-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: preserve tool blocks for native protocol in conversation history #9319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Problem: When resuming tasks with native protocol, tool_use and tool_result blocks were being converted to text format (e.g., 'Called read_file with...'), which confused the model and prevented proper OpenAI tool calling format. Root Cause: The tool-to-text conversion logic added in v2.0 for XML protocol was running for all protocols, including native protocol where it shouldn't apply. Solution: Gate the conversion logic to only run for XML protocol. Native protocol now preserves tool_use/tool_result blocks, which are properly converted to OpenAI format (tool_calls/tool role) by convertToOpenAiMessages. Testing: Added 8 new tests verifying both protocols work correctly. All 58 existing tests pass, confirming XML protocol behavior is unchanged.
Review completed. No issues found. The implementation correctly gates tool block conversion to only run for XML protocol, preserving tool_use and tool_result blocks for native protocol as intended. The fix is well-tested with comprehensive test coverage for both protocols. Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
Problem
When resuming tasks with native protocol, tool_use and tool_result blocks were being converted to text format:
This confused the model, making it think that's how to call tools instead of using the proper OpenAI tool calling format.
Root Cause
The tool-to-text conversion logic added in v2.0 (commit 1d912bd) for XML protocol was running for all protocols. It should only run for XML protocol where tools are text-based, not for native protocol where tools use structured API calls.
Solution
Gate the conversion logic to only run for XML protocol (lines 1433-1465 in Task.ts). Native protocol now preserves tool_use/tool_result blocks, which convertToOpenAiMessages properly transforms to:
{ "role": "assistant", "tool_calls": [{"id": "call_123", "type": "function", ...}] }, { "role": "tool", "tool_call_id": "call_123", "content": "..." }This matches the OpenAI API format documented in tool_calling.md.
Testing
Backward Compatibility
Protocol is determined at resume time based on current settings. Old tasks with tool blocks are handled correctly:
Important
Fixes tool block conversion logic to preserve tool blocks for native protocol, ensuring correct transformation and backward compatibility.
Task.tsto only apply to XML protocol, preserving tool blocks for native protocol.convertToOpenAiMessagescorrectly transforms tool blocks for native protocol.task-tool-history.spec.tswith 8 new tests for both XML and native protocols.task-xml-protocol-regression.spec.ts.This description was created by
for c2a952c. You can customize this summary. It will automatically update as commits are pushed.