ai-chat: forward or document body behavior during tool continuation path
Context
In #886, we added forwarding of custom body fields to onChatMessage via options.body. However, this only applies to the initial CF_AGENT_USE_CHAT_REQUEST path. The tool continuation path (CF_AGENT_TOOL_RESULT) does not forward body, so options.body will be undefined during auto-continue after client tool results.
Problem
Users who rely on body data (e.g., model selection, temperature) for every onChatMessage invocation will find it missing on tool continuation calls. They would need to manually store it on the first call (e.g., in Durable Object state) and retrieve it on subsequent calls.
Possible approaches
- Persist and re-forward
body— Store the custom body fields from the initial request and automatically pass them through on tool continuations sooptions.bodyis always available. - Document the current behavior — Make it clear in docs/JSDoc that
options.bodyis only populated on the initial chat request and isundefinedduring tool continuations, with guidance on how users can persist it themselves.
References
- PR: #886
- Review nit: https://github.com/cloudflare/agents/pull/886#issuecomment-2897483105
/bonk implement this carefully with tests included
Created PR #895
github run
fixed in main