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
21
run_agent.py
21
run_agent.py
|
|
@ -2737,6 +2737,27 @@ class AIAgent:
|
||||||
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
sanitized_messages = api_messages
|
||||||
|
needs_sanitization = False
|
||||||
|
for msg in api_messages:
|
||||||
|
if not isinstance(msg, dict):
|
||||||
|
continue
|
||||||
|
if "codex_reasoning_items" in msg:
|
||||||
|
needs_sanitization = True
|
||||||
|
break
|
||||||
|
|
||||||
|
tool_calls = msg.get("tool_calls")
|
||||||
|
if isinstance(tool_calls, list):
|
||||||
|
for tool_call in tool_calls:
|
||||||
|
if not isinstance(tool_call, dict):
|
||||||
|
continue
|
||||||
|
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)
|
sanitized_messages = copy.deepcopy(api_messages)
|
||||||
for msg in sanitized_messages:
|
for msg in sanitized_messages:
|
||||||
if not isinstance(msg, dict):
|
if not isinstance(msg, dict):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue