Send each function response as its own tool message - #288
Conversation
A message holding several function responses is what a parallel tool call produces, but prepareMessagesParam() only special-cased a message with exactly one function-response part. Anything more fell through to the generic branch, where getMessagePartContentData() threw "The API only allows a single function response, as the only content of the message." The chat completions API expects one message of role 'tool' per tool call, so a message can no longer map to a single API entry. Expand a message whose parts are all function responses into one entry per response, and reject a message that mixes function responses with other content up front, where the constraint can be stated clearly. The single-message shape itself is correct and unchanged: it is what PromptBuilder::withFunctionResponse() builds when called more than once, and what the Anthropic and Google providers already expect, both of which map function responses through their normal per-part conversion. Fixes WordPress#286. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @stefanolissa. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #288 +/- ##
============================================
- Coverage 86.54% 86.52% -0.03%
- Complexity 1381 1383 +2
============================================
Files 69 69
Lines 4438 4446 +8
============================================
+ Hits 3841 3847 +6
- Misses 597 599 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A message holding several function responses is what a parallel tool call produces, but
prepareMessagesParam()only special-cased a message with exactly one function-response part. Anything more fell through to the generic branch, wheregetMessagePartContentData()threw "The API only allows a single function response, as the only content of the message."The chat completions API expects one message of role 'tool' per tool call, so a message can no longer map to a single API entry. Expand a message whose parts are all function responses into one entry per response, and reject a message that mixes function responses with other content up front, where the constraint can be stated clearly.
The single-message shape itself is correct and unchanged: it is what
PromptBuilder::withFunctionResponse()builds when called more than once, and what the Anthropic and Google providers already expect, both of which map function responses through their normal per-part conversion.Fixes #286.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Tracing the folded-in values through git history to confirm they were never snake_case, verifying the emitted values at runtime, and drafting these comment corrections. The final wording was reviewed and edited by me.
🤖 Generated with Claude Code