fix: strip call_id/response_item_id from tool_calls for Mistral compatibility#1058
Merged
fix: strip call_id/response_item_id from tool_calls for Mistral compatibility#1058
Conversation
…tibility Mistral's API strictly validates the Chat Completions schema and rejects unknown fields (call_id, response_item_id) with 422. These fields are added by _build_assistant_message() for Codex Responses API support. This fix: - Only strips when targeting Mistral (api.mistral.ai in base_url) - Creates new tool_call dicts instead of mutating originals (shallow copy safety — msg.copy() shares the tool_calls list) - Preserves call_id/response_item_id in the internal message history so _chat_messages_to_responses_input() can still read them if the session falls back to a Codex provider mid-conversation Applied in all 3 API message building locations: - Main conversation loop (run_conversation) - _handle_max_iterations() - flush_memories() Inspired by PR #864 (unmodeled-tyler) which identified the issue but applied the fix unconditionally and mutated originals via shallow copy. Co-authored-by: unmodeled-tyler <unmodeled.tyler@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mistral's API strictly validates the Chat Completions schema and rejects unknown fields (
call_id,response_item_id) with 422 "Extra inputs are not permitted". These fields are added by_build_assistant_message()for Codex Responses API support but are not part of the Chat Completions spec.Approach
Unlike PR #864 which stripped these fields unconditionally (and mutated originals via shallow copy), this fix:
api.mistral.aiinself.base_urltc.pop()— avoids mutating the shared objects frommsg.copy()(shallow copy)_chat_messages_to_responses_input()can still readcall_id/response_item_idif the session falls back to a Codex provider mid-conversationChanges
_sanitize_tool_calls_for_strict_api()static method that builds new tool_call dicts without the Codex-specific fieldsrun_conversation)_handle_max_iterations()flush_memories()Why not merge PR #864
PR #864 had several issues:
run_agent.py(+1526/-758 lines of noise)call_id/response_item_idunconditionally for ALL providers, not just Mistraltc.pop()on shallow-copied dicts, permanently destroying the fields from internal message historyThis PR cherry-picks the valid fix idea with proper scoping.
Related
finish_reasonstrippingCo-authored-by: unmodeled-tyler unmodeled.tyler@proton.me