@kentcdodds/ ai
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/cancelsemantics. - Import
./turndirectly when you only need the engine without the root wrapper.
Required setup
- User-scoped
cloudflareApiTokensecret andcloudflareAccountIdvalue. - Optional
cloudflareAiModelvalue (defaults to@cf/mistralai/mistral-small-3.1-24b-instruct). - Optional
cloudflareAiGatewayIdvalue; auto-created as gatewaykodywhen the token can manage AI Gateway. - Package storage and workflows runtime for
./runsbackground polling (provided by Kody when the package app/jobs run). - Host packages that need their own secret allowlists should call
runModelStepand execute tools with localkody.search/kody.execute. - Convenience
agentChatTurntool calls run as packageai, so secrets used that way must allow packageai.
Exports
kody:@kentcdodds/ai— defaultagentChatTurn; alsoagentTurnStream,runModelStep,defaultKodyAgentSystem,startAgentTurn,readNextAgentTurnEvents,cancelAgentTurn.kody:@kentcdodds/ai/model-step— model-only completion (runModelStep) pluskodyAgentToolDefinitionsfor host-side tool loops.kody:@kentcdodds/ai/turn— merged agent-turn engine (runAgentTurndefault 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, andrunStoredAgentTurnworker default export.kody:@kentcdodds/ai/types—AgentTurnInput,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.