fix: preserve chat kwargs identity when no sanitization is needed
This commit is contained in:
parent
08208323f2
commit
a628c607f0
1 changed files with 29 additions and 8 deletions
37
run_agent.py
37
run_agent.py
|
|
@ -2737,20 +2737,41 @@ class AIAgent:
|
||||||
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
sanitized_messages = copy.deepcopy(api_messages)
|
sanitized_messages = api_messages
|
||||||
for msg in sanitized_messages:
|
needs_sanitization = False
|
||||||
|
for msg in api_messages:
|
||||||
if not isinstance(msg, dict):
|
if not isinstance(msg, dict):
|
||||||
continue
|
continue
|
||||||
|
if "codex_reasoning_items" in msg:
|
||||||
# Codex-only replay state must not leak into strict chat-completions APIs.
|
needs_sanitization = True
|
||||||
msg.pop("codex_reasoning_items", None)
|
break
|
||||||
|
|
||||||
tool_calls = msg.get("tool_calls")
|
tool_calls = msg.get("tool_calls")
|
||||||
if isinstance(tool_calls, list):
|
if isinstance(tool_calls, list):
|
||||||
for tool_call in tool_calls:
|
for tool_call in tool_calls:
|
||||||
if isinstance(tool_call, dict):
|
if not isinstance(tool_call, dict):
|
||||||
tool_call.pop("call_id", None)
|
continue
|
||||||
tool_call.pop("response_item_id", None)
|
if "call_id" in tool_call or "response_item_id" in tool_call:
|
||||||
|
needs_sanitization = True
|
||||||
|
break
|
||||||
|
if needs_sanitization:
|
||||||
|
break
|
||||||
|
|
||||||
|
if needs_sanitization:
|
||||||
|
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 = {}
|
provider_preferences = {}
|
||||||
if self.providers_allowed:
|
if self.providers_allowed:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue