From 336fd952d68f6bba52f7d10be195ad9c2a3f80e3 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 20:17:33 -0700 Subject: [PATCH] refactor(agent/agent_init): fold custom-provider model-match + key-filter ladders --- agent/agent_init.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/agent/agent_init.py b/agent/agent_init.py index 6cd74349f3..fd7e7de0f0 100644 --- a/agent/agent_init.py +++ b/agent/agent_init.py @@ -260,30 +260,20 @@ def _custom_provider_model_matches(agent_model: str, entry: Dict[str, Any]) -> b # matching ANY catalog entry counts, else a provider whose `model` differs from the # session model drops its extra_body (e.g. OpenAI service_tier) → wrong billing tier. models = entry.get("models") - catalog: List[str] = [] - if isinstance(models, dict): - catalog = [str(k).strip().lower() for k in models] - elif isinstance(models, (list, tuple)): - catalog = [str(m).strip().lower() for m in models] + catalog = [str(m).strip().lower() for m in models] if isinstance(models, (dict, list, tuple)) else [] if catalog and agent_model_norm in catalog: return True provider_model = str(entry.get("model", "") or "").strip().lower() - if not provider_model and not catalog: - return True - return provider_model == agent_model_norm + return (not provider_model and not catalog) or provider_model == agent_model_norm def _custom_provider_extra_body_for_agent( *, provider: str, model: str, base_url: str, custom_providers: List[Dict[str, Any]] ) -> Optional[Dict[str, Any]]: provider_norm = (provider or "").strip().lower() - if provider_norm == "custom": - provider_key_filter = "" - elif provider_norm.startswith("custom:"): - provider_key_filter = provider_norm.split(":", 1)[1].strip() - else: + if provider_norm != "custom" and not provider_norm.startswith("custom:"): return None - + provider_key_filter = provider_norm.partition(":")[2].strip() target_url = _normalized_custom_base_url(base_url) if not target_url: return None