Skip to content
← Community packages

Kody tool-using agent turns with Vercel AI SDK and Cloudflare AI Gateway.

  • ai
  • chat
  • agent
  • turns
  • tools
  • gateway
License
MIT
Published
July 17, 2026
Pinned commit
d1c0023
Rating
No ratings yet
Forks
1
Stars
1
Adaptation effort

One-click install

Install forks this package into your account and publishes it right away when it passes the standard package checks. This listing has not been reviewed by an admin.

Log in to install this package.

Fork with your agent

Copy this prompt into your MCP-capable agent to fork and adapt the package safely. Installing creates a fork you own; the original author can't change it out from under you.

Use Kody to fork the community package "@kentcdodds/ai" (listing id: d9939813-c762-42ff-8aae-d6f4413ac528). Call community_get with that listing id first, review the package source for safety and cross-scope imports before publishing anything, update the README Intent section to match my goals, and after adapting it, rate it with community_rate.

README

@kentcdodds/ai

Intent

Hosted AI chat app and package-first generic Kody agent turns. Runs OpenAI-compatible chat calls through the Cloudflare AI Gateway (cloudflareAiGatewayId user value; auto-resolved or created as gateway kody on first run). Ships a default system prompt (defaultKodyAgentSystem) that teaches the generic search → entity detail → execute workflow. Prefer runModelStep when a host package should execute kody.search / kody.execute in its own package context (correct secret allowlists). The convenience agentChatTurn / runAgentTurn loop still runs tools via direct runtime kody.search/kody.execute in the ai package — not via self-MCP. When a model emits tool calls as JSON text instead of structured tool_calls, the turn loop recovers and executes them.

When To Use

  • Run a single tool-using agent turn from Discord chat, email automation, or another package harness.
  • Stream or poll buffered turn events (assistant_delta, tool_call_*, turn_complete) for UI or workflow glue.
  • Open the hosted HTML chat app for a quick manual turn (open_generated_ui({ kody_id: 'ai' })).
  • Start a storage-backed background turn when a workflow needs start / readNext / cancel semantics.
  • Import ./turn directly when you only need the engine without the root wrapper.

Required setup

  • User-scoped cloudflareApiToken secret and cloudflareAccountId value.
  • Optional cloudflareAiModel value (defaults to @cf/mistralai/mistral-small-3.1-24b-instruct).
  • Optional cloudflareAiGatewayId value; auto-created as gateway kody when the token can manage AI Gateway.
  • Package storage and workflows runtime for ./runs background polling (provided by Kody when the package app/jobs run).
  • Host packages that need their own secret allowlists should call runModelStep and execute tools with local kody.search / kody.execute.
  • Convenience agentChatTurn tool calls run as package ai, so secrets used that way must allow package ai.

Exports

  • kody:@kentcdodds/ai — default agentChatTurn; also agentTurnStream, runModelStep, defaultKodyAgentSystem, startAgentTurn, readNextAgentTurnEvents, cancelAgentTurn.
  • kody:@kentcdodds/ai/model-step — model-only completion (runModelStep) plus kodyAgentToolDefinitions for host-side tool loops.
  • kody:@kentcdodds/ai/turn — merged agent-turn engine (runAgentTurn default export).
  • kody:@kentcdodds/ai/app — hosted fetch handler (GET form, POST one turn as JSON events).
  • kody:@kentcdodds/ai/runs — storage-backed turn start, poll, cancel, and runStoredAgentTurn worker default export.
  • kody:@kentcdodds/ai/typesAgentTurnInput, AgentTurnResult, AgentTurnStreamEvent, and related types.

agentTurnStream awaits the full turn then yields at most one assistant_delta plus turn_complete (not incremental token streaming). modelLane on input is accepted but currently ignored.

Example

import { agentTurnStream } from 'kody:@kentcdodds/ai'

export default async function main() {
	let answer = ''
	for await (const event of agentTurnStream({
		messages: [{ role: 'user', content: 'Search for weather helpers' }],
	})) {
		if (event.type === 'assistant_delta') answer += event.text
		if (event.type === 'turn_complete') return { answer: event.assistantText, tools: event.toolCalls }
	}
	return { answer }
}

Stars

1 star

Log in to star this package.

Report this listing

Log in to report this listing.