The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor: reuse _provider_model_key for the image-rejection model key
kshitijk4poor26f9cb03c406
diff --git a/agent/message_sanitization.py b/agent/message_sanitization.pyindex 5511a6dc696..a93e87c8083 100644--- a/agent/message_sanitization.py+++ b/agent/message_sanitization.py@@ -14,6 +14,8 @@ import refrom functools import partialfrom typing import Any, Callable+from agent.vision_message_prep import _provider_model_key+logger = logging.getLogger(__name__)# Lone surrogates are invalid UTF-8 and crash json.dumps in the OpenAI SDK; also used for@@ -411,12 +413,6 @@ _IMAGE_CORRUPT_PHRASES = (_IMAGE_REJECTION_PHRASES = _IMAGE_REJECTION_PHRASES + _IMAGE_CORRUPT_PHRASES-def image_model_key(agent: Any) -> tuple:- """``(provider, model)`` the agent is currently talking to — the key image rejections are- tracked by, so each model in a fallback chain is judged on its own."""- return (getattr(agent, "provider", None), getattr(agent, "model", None))--def strip_images_for_rejecting_model(agent: Any, api_messages: Any) -> bool:"""Send-path image strip for a model that rejected image content (see turn_recovery).@@ -427,7 +423,7 @@ def strip_images_for_rejecting_model(agent: Any, api_messages: Any) -> bool:that accepts images gets them again."""rejected = getattr(agent, "_image_rejecting_models", None)- if not isinstance(rejected, set) or image_model_key(agent) not in rejected:+ if not isinstance(rejected, set) or _provider_model_key(agent) not in rejected:return Falsereturn isinstance(api_messages, list) and _strip_images_from_messages(api_messages)@@ -451,7 +447,7 @@ __all__ = ["_escape_invalid_chars_in_json_strings", "_repair_tool_call_arguments","_strip_non_ascii", "_sanitize_messages_non_ascii", "_sanitize_tools_non_ascii","_strip_images_from_messages", "_sanitize_structure_non_ascii", "sanitize_outbound_kwargs",- "strip_images_for_rejecting_model", "image_model_key",+ "strip_images_for_rejecting_model",# call_id policy owners"deterministic_call_id", "coalesce_tool_call_id", "tool_call_id_variants","tool_result_id_variants", "uniquify_tool_call_ids",diff --git a/agent/turn_recovery.py b/agent/turn_recovery.pyindex 5220ffe5c20..dc574ec1dd3 100644--- a/agent/turn_recovery.py+++ b/agent/turn_recovery.py@@ -24,10 +24,11 @@ from agent.error_classifier import FailoverReason, classify_api_errorfrom agent.message_sanitization import (_looks_like_corrupt_image_rejection, _looks_like_image_content_rejection, _sanitize_messages_non_ascii,_sanitize_messages_surrogates, _sanitize_structure_non_ascii, _sanitize_structure_surrogates,- _strip_images_from_messages, _strip_non_ascii, image_model_key,+ _strip_images_from_messages, _strip_non_ascii,close_interrupted_tool_sequence,)from agent.thinking_timeout_guidance import build_thinking_timeout_guidance, is_thinking_timeout+from agent.vision_message_prep import _provider_model_keyfrom agent.turn_failure_copy import (CONTENT_POLICY_NEXT_STEPS, content_policy_copy, exhausted_copy, limit_reset_copy, nonretryable_copy,provider_label_for, site_copy, stamp_failure,@@ -246,7 +247,7 @@ def recover_before_classification(_status_ok = _err_status is None or (400 <= int(_err_status) < 500)# Guarded PER MODEL, not by a turn-global flag: in a fallback chain the next model can reject# images too, and a turn-wide flag would skip its recovery and fail the turn.- _model_key = image_model_key(agent)+ _model_key = _provider_model_key(agent)_rejected = getattr(agent, "_image_rejecting_models", None)if not isinstance(_rejected, set):_rejected = agent._image_rejecting_models = set()