fix: strip image parts for non-vision models with provider profiles + getattr-safe _custom_providers

Original commit 75e5d0f6b by 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 (from 21078ebce) 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:
teknium1 2026-05-16 23:43:37 -07:00
parent 36ad8336f9
commit 563b4d9e51
No known key found for this signature in database

View file

@ -377,6 +377,11 @@ def build_api_kwargs(agent, api_messages: list) -> dict:
if _ephemeral_out is not 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(
model=agent.model,
messages=api_messages,
@ -850,7 +855,7 @@ def try_activate_fallback(agent, reason: "FailoverReason | None" = None) -> bool
agent.model, base_url=agent.base_url,
api_key=agent.api_key, provider=agent.provider,
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(
model=agent.model,