Skip to main content
Reference vendor/cloudflare 1 min read

streaming-chat

Streaming Chat with AIChatAgent

Use AIChatAgent for persisted conversations with streaming and tools; use callable streaming RPC for non-chat output. Before adapting an existing app, check its installed agents, @cloudflare/ai-chat, and AI SDK versions against the current docs.

Read the relevant documentation before implementing:

TaskDocumentation
Build a chat agentChat agent example — setup, provider, server, and UI
Implement or customize chatChat agents — message format, tools, custom streams, persistence, concurrency, cancellation, and recovery
Connect a clientClient guidance — React, vanilla JS, HTTP, and authentication
Stream non-chat resultsCallable methods — server and client streaming RPC
Trigger background turnsServer-driven messages
Add approvalsHuman-in-the-loop

Forward the request abort signal to the model call so cancellation stops generation. When customizing streams, verify persistence and completion behavior for the installed version. Treat client reconnection and Durable Object eviction as separate recovery cases.