diff --git a/run_agent.py b/run_agent.py index 130e4abd63..5b51bc433b 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.