fix: sanitize chat payloads and provider precedence

This commit is contained in:
Adavya Sharma 2026-03-13 23:59:12 -07:00 committed by teknium1
parent a20d373945
commit 358dab52ce
8 changed files with 91 additions and 10 deletions

View file

@ -2737,6 +2737,21 @@ class AIAgent:
return kwargs
sanitized_messages = copy.deepcopy(api_messages)
for msg in sanitized_messages:
if not isinstance(msg, dict):
continue
# Codex-only replay state must not leak into strict chat-completions APIs.
msg.pop("codex_reasoning_items", None)
tool_calls = msg.get("tool_calls")
if isinstance(tool_calls, list):
for tool_call in tool_calls:
if isinstance(tool_call, dict):
tool_call.pop("call_id", None)
tool_call.pop("response_item_id", None)
provider_preferences = {}
if self.providers_allowed:
provider_preferences["only"] = self.providers_allowed
@ -2753,7 +2768,7 @@ class AIAgent:
api_kwargs = {
"model": self.model,
"messages": api_messages,
"messages": sanitized_messages,
"tools": self.tools if self.tools else None,
"timeout": float(os.getenv("HERMES_API_TIMEOUT", 900.0)),
}