@kentcdodds/ai
Kody tool-using agent turns with Vercel AI SDK and Cloudflare AI Gateway.
README.md
49 lines · 2.4 KB · Markdown@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 in this package's storage via ./settings;
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.
What it does
- Run a single tool-using agent turn (chat, Discord, email, or other harnesses)
- Stream or poll buffered turn events for UI / workflow glue
- Hosted HTML chat app for a quick manual turn
- Storage-backed background turns with start / readNext / cancel
- Model-only step (
runModelStep) so hosts can run tools in their own context - Persist Cloudflare account / gateway / model ids in package storage without republishing
Prerequisites / setup
- Save user secret
cloudflareApiToken(do not paste the token value in chat) with access to Cloudflare AI / AI Gateway as needed. - Set
cloudflareAccountId(and optionallycloudflareAiGatewayId,cloudflareAiModel) via this package's./settingsexport — stored in package storage, no republish. - Optional: leave gateway id unset; first run auto-creates gateway
kodywhen the token can manage AI Gateway. Model defaults to@cf/mistralai/mistral-small-3.1-24b-instructwhen unset. - Host packages that need their own secret allowlists should prefer
runModelStepand execute tools with localkody.search/kody.execute. ConvenienceagentChatTurntool calls run as packageai, so secrets used that way must allow packageai. - Agents: see
AGENTS.mdfor import paths and smoke checks.
Done when
cloudflareApiTokenis saved and package secret access is approved- Account (and optional gateway/model) ids are set or auto-resolved via
./settings - A read-only or low-cost turn / settings read succeeds from
execute - Hosted app at
/packages/airesponds when you need the HTML chat UI