fix: strip image parts for non-vision models with provider profiles + getattr-safe _custom_providers
Original commit75e5d0f6bby hueilau targeted _build_api_kwargs in pre-refactor run_agent.py. The body now lives in agent/chat_completion_helpers.build_api_kwargs — re-applied there. Also: switch the custom_providers forward (from21078ebce) to use getattr() — tests build a bare AIAgent via __new__ and would otherwise hit AttributeError on _custom_providers. Co-authored-by: hueilau <33933019+hueilau@users.noreply.github.com>
This commit is contained in:
@@ -377,6 +377,11 @@ def build_api_kwargs(agent, api_messages: list) -> dict:
|
|||||||
if _ephemeral_out is not None:
|
if _ephemeral_out is not None:
|
||||||
agent._ephemeral_max_output_tokens = None
|
agent._ephemeral_max_output_tokens = None
|
||||||
|
|
||||||
|
# Strip image parts for non-vision models that have provider profiles
|
||||||
|
# (e.g. DeepSeek, Kimi). The legacy path below already does this, but
|
||||||
|
# registered providers with profiles were bypassing the strip.
|
||||||
|
api_messages = agent._prepare_messages_for_non_vision_model(api_messages)
|
||||||
|
|
||||||
return _ct.build_kwargs(
|
return _ct.build_kwargs(
|
||||||
model=agent.model,
|
model=agent.model,
|
||||||
messages=api_messages,
|
messages=api_messages,
|
||||||
@@ -850,7 +855,7 @@ def try_activate_fallback(agent, reason: "FailoverReason | None" = None) -> bool
|
|||||||
agent.model, base_url=agent.base_url,
|
agent.model, base_url=agent.base_url,
|
||||||
api_key=agent.api_key, provider=agent.provider,
|
api_key=agent.api_key, provider=agent.provider,
|
||||||
config_context_length=getattr(agent, "_config_context_length", None),
|
config_context_length=getattr(agent, "_config_context_length", None),
|
||||||
custom_providers=agent._custom_providers,
|
custom_providers=getattr(agent, "_custom_providers", None),
|
||||||
)
|
)
|
||||||
agent.context_compressor.update_model(
|
agent.context_compressor.update_model(
|
||||||
model=agent.model,
|
model=agent.model,
|
||||||
|
|||||||
Reference in New Issue
Block a user