The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor: detach aliased tools with _clone_message_for_send, not deepcopy
kshitijk4poorc27219adc8cb
diff --git a/agent/message_sanitization.py b/agent/message_sanitization.pyindex de525451988..cd9af163fbf 100644--- a/agent/message_sanitization.py+++ b/agent/message_sanitization.py@@ -7,7 +7,6 @@ characters that would crash ``json.dumps`` in the OpenAI SDK or be rejected upstfrom __future__ import annotations-import copyimport hashlibimport jsonimport logging@@ -135,8 +134,13 @@ def sanitize_outbound_kwargs(agent: Any, api_kwargs: dict) -> None:if agent._force_ascii_payload:# ``tools`` is built from ``agent.tools`` per attempt and usually aliases it; detach# before the in-place strip so the retry never rewrites the canonical tool schemas.+ # A structural clone suffices: ``_sanitize_structure`` only rebinds str leaves+ # inside dict/list containers.if api_kwargs.get("tools") is not None and api_kwargs["tools"] is getattr(agent, "tools", None):- api_kwargs["tools"] = copy.deepcopy(api_kwargs["tools"])+ # Lazy: conversation_loop imports this module (cycle).+ from agent.conversation_loop import _clone_message_for_send++ api_kwargs["tools"] = _clone_message_for_send(api_kwargs["tools"])_sanitize_structure_non_ascii(api_kwargs)