agents icon indicating copy to clipboard operation
agents copied to clipboard

ai-chat: forward or document body behavior during tool continuation path

Open ask-bonk opened this issue 9 months ago • 3 comments

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

  1. Persist and re-forward body — Store the custom body fields from the initial request and automatically pass them through on tool continuations so options.body is always available.
  2. Document the current behavior — Make it clear in docs/JSDoc that options.body is only populated on the initial chat request and is undefined during 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

ask-bonk avatar Feb 11 '26 10:02 ask-bonk

/bonk implement this carefully with tests included

whoiskatrin avatar Feb 12 '26 09:02 whoiskatrin

Created PR #895

github run

ask-bonk avatar Feb 12 '26 09:02 ask-bonk

fixed in main

threepointone avatar Feb 14 '26 16:02 threepointone