The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent_init): reuse anthropic_adapter._TOOL_STREAMING_BETA
kshitijk4poorafeaabf629d6
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex 06bd3f1a073..e62cf5179b0 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -877,20 +877,19 @@ def _routed_client_kwargs(agent, fallback_model, _provider_timeout) -> Dict[str,)-_FINE_GRAINED_BETA = "fine-grained-tool-streaming-2025-05-14"--def _apply_openai_header_policy(agent, client_kwargs: Dict[str, Any]) -> None:"""Mutate ``client_kwargs`` (== ``agent._client_kwargs``) with header/TLS policy, in order:OpenRouter Claude beta header → model.default_headers → custom-provider TLS/extra_headers."""# Fine-grained tool streaming for Claude on OpenRouter: without the beta header# Anthropic buffers the whole tool call and OpenRouter's proxy times out.+ from agent.anthropic_adapter import _TOOL_STREAMING_BETA+_effective_base = str(client_kwargs.get("base_url", "")).lower()if base_url_host_matches(_effective_base, "openrouter.ai") and "claude" in (agent.model or "").lower():headers = client_kwargs.get("default_headers") or {}existing_beta = headers.get("x-anthropic-beta", "")- if _FINE_GRAINED_BETA not in existing_beta:- headers["x-anthropic-beta"] = ",".join(filter(None, (existing_beta, _FINE_GRAINED_BETA)))+ if _TOOL_STREAMING_BETA not in existing_beta:+ headers["x-anthropic-beta"] = ",".join(filter(None, (existing_beta, _TOOL_STREAMING_BETA)))client_kwargs["default_headers"] = headers# model.default_headers override provider/SDK defaults (WAFs rejecting SDK headers).agent._apply_user_default_headers()