From 560c6ae1433f42b0919cc7f9caf7e1b5d5b66c6d Mon Sep 17 00:00:00 2001 From: Lume Date: Sun, 5 Apr 2026 07:32:04 +0100 Subject: [PATCH] feat: add _should_sanitize_tool_calls() method Adds a centralized method to determine when tool_calls need sanitization for strict APIs. Returns True for all APIs except codex_responses mode. This prevents 400 errors from providers like Fireworks that reject unknown fields (call_id, response_item_id) in tool_calls. --- run_agent.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/run_agent.py b/run_agent.py index 130e4abd6..5b51bc433 100644 --- a/run_agent.py +++ b/run_agent.py @@ -5345,6 +5345,19 @@ class AIAgent: ] return api_msg + def _should_sanitize_tool_calls(self) -> bool: + """Determine if tool_calls need sanitization for strict APIs. + + Codex Responses API uses fields like call_id and response_item_id + that are not part of the standard Chat Completions schema. These + fields must be stripped when calling any other API to avoid + validation errors (400 Bad Request). + + Returns: + bool: True if sanitization is needed (non-Codex API), False otherwise. + """ + return self.api_mode != "codex_responses" + def flush_memories(self, messages: list = None, min_turns: int = None): """Give the model one turn to persist memories before context is lost.