cloudflare / cloudflare/agents
Support TanStack AI in AIChatAgent / @cloudflare/ai-chat
- Dominant language
- TypeScript
- Stars
- 5.6k
- Forks
- 711
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 53
Description
## Summary
`@cloudflare/ai-chat` (`AIChatAgent` + `useAgentChat`) currently only works with the Vercel AI SDK (`ai` v6 + `@ai-sdk/react`). It would be great to have first-class TanStack AI support as an alternative.
## Context
Cloudflare already ships `@cloudflare/tanstack-ai` for Workers AI and AI Gateway model adapters, and the `docs/index.md` in this repo has a TODO placeholder for TanStack integration:
```
- TODO: [TanStack Integration](./tanstack.md) - Using TanStack AI with agents
```
However, `AIChatAgent` is tightly coupled to the Vercel AI SDK — it uses `convertToModelMessages`, `createUIMessageStream`, `UIMessage` types, and the `useAgentChat` hook depends on `@ai-sdk/react`. There's no way to use TanStack AI's `chat()`, `useChat`, or AG-UI streaming protocol with `AIChatAgent` today.
## What this would enable
- Using `@tanstack/ai-anthropic` (or any TanStack AI adapter) with `AIChatAgent` for the LLM layer
- Using `useChat` from `@tanstack/ai-react` instead of `useAgentChat` from `@ai-sdk/react`
- AG-UI protocol streaming over the existing DO WebSocket transport
- Tool approval flow via TanStack AI's `CUSTOM` event pattern
- Removing the hard dependency on `ai` / `@ai-sdk/react` for projects that prefer TanStack AI
## Current workaround
Extend `Agent` directly instead of `AIChatAgent` and reimplement message persistence, WebSocket streaming, and tool approval manually. This works but loses all the convenience that `AIChatAgent` provides (incremental persistence, `maxPersistedMessages`, row size guards, resumable streams, etc.).
Contributor guide
Assessment
This issue has not been assessed yet.