fix: layer llm route inheritance
This commit is contained in:
parent
507af6f6e2
commit
cd145f14d0
|
|
@ -137,7 +137,7 @@ def test_role_specific_llm_config_overrides_actual_graph_wiring(monkeypatch):
|
||||||
assert "News Analyst" not in recorded_llms
|
assert "News Analyst" not in recorded_llms
|
||||||
|
|
||||||
|
|
||||||
def test_role_specific_route_inherits_default_provider_and_base_url(monkeypatch):
|
def test_role_specific_route_inherits_default_provider_base_url_and_model(monkeypatch):
|
||||||
recorded_llms = {}
|
recorded_llms = {}
|
||||||
|
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
|
|
@ -161,10 +161,11 @@ def test_role_specific_route_inherits_default_provider_and_base_url(monkeypatch)
|
||||||
"default": {
|
"default": {
|
||||||
"provider": "anthropic",
|
"provider": "anthropic",
|
||||||
"base_url": "https://anthropic.example/v1",
|
"base_url": "https://anthropic.example/v1",
|
||||||
|
"model": "claude-sonnet-4-6",
|
||||||
},
|
},
|
||||||
"roles": {
|
"roles": {
|
||||||
"portfolio_manager": {
|
"portfolio_manager": {
|
||||||
"model": "claude-opus-4-6",
|
"base_url": "https://anthropic-pm.example/v1",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -173,9 +174,10 @@ def test_role_specific_route_inherits_default_provider_and_base_url(monkeypatch)
|
||||||
|
|
||||||
assert recorded_llms["Market Analyst"]["provider"] == "anthropic"
|
assert recorded_llms["Market Analyst"]["provider"] == "anthropic"
|
||||||
assert recorded_llms["Market Analyst"]["base_url"] == "https://anthropic.example/v1"
|
assert recorded_llms["Market Analyst"]["base_url"] == "https://anthropic.example/v1"
|
||||||
|
assert recorded_llms["Market Analyst"]["model"] == "claude-sonnet-4-6"
|
||||||
assert recorded_llms["Portfolio Manager"]["provider"] == "anthropic"
|
assert recorded_llms["Portfolio Manager"]["provider"] == "anthropic"
|
||||||
assert recorded_llms["Portfolio Manager"]["base_url"] == "https://anthropic.example/v1"
|
assert recorded_llms["Portfolio Manager"]["base_url"] == "https://anthropic-pm.example/v1"
|
||||||
assert recorded_llms["Portfolio Manager"]["model"] == "claude-opus-4-6"
|
assert recorded_llms["Portfolio Manager"]["model"] == "claude-sonnet-4-6"
|
||||||
|
|
||||||
|
|
||||||
def test_unused_role_routes_do_not_instantiate_clients(monkeypatch):
|
def test_unused_role_routes_do_not_instantiate_clients(monkeypatch):
|
||||||
|
|
|
||||||
|
|
@ -226,20 +226,18 @@ class TradingAgentsGraph:
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
routing = self.config.get("llm_routing") or {}
|
routing = self.config.get("llm_routing") or {}
|
||||||
role_routes = routing.get("roles") or {}
|
role_routes = routing.get("roles") or {}
|
||||||
|
model_key = "deep_think_llm" if thinker_depth == "deep" else "quick_think_llm"
|
||||||
|
legacy_route = {
|
||||||
|
"provider": self._normalize_provider(self.config["llm_provider"]),
|
||||||
|
"model": self.config[model_key],
|
||||||
|
"base_url": self.config.get("backend_url"),
|
||||||
|
}
|
||||||
default_route = routing.get("default") or {}
|
default_route = routing.get("default") or {}
|
||||||
role_route = role_routes.get(role) or {}
|
role_route = role_routes.get(role) or {}
|
||||||
route = self._deep_merge_dicts(default_route, role_route)
|
route = self._deep_merge_dicts(legacy_route, default_route)
|
||||||
|
route = self._deep_merge_dicts(route, role_route)
|
||||||
model_key = "deep_think_llm" if thinker_depth == "deep" else "quick_think_llm"
|
route["provider"] = self._normalize_provider(route.get("provider"))
|
||||||
provider = self._normalize_provider(
|
return route
|
||||||
route.get("provider", self.config["llm_provider"])
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"provider": provider,
|
|
||||||
"model": route.get("model", self.config[model_key]),
|
|
||||||
"base_url": route.get("base_url", self.config.get("backend_url")),
|
|
||||||
}
|
|
||||||
|
|
||||||
def _get_provider_kwargs(self, provider: Optional[str] = None) -> Dict[str, Any]:
|
def _get_provider_kwargs(self, provider: Optional[str] = None) -> Dict[str, Any]:
|
||||||
"""Get provider-specific kwargs for LLM client creation."""
|
"""Get provider-specific kwargs for LLM client creation."""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue