The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(plugins): optional per-launch provider on SubagentLaunchRequest
Evaad37bfb17fb7
diff --git a/agent/subagent_lifecycle.py b/agent/subagent_lifecycle.pyindex ddc720f21c0..ff724f2daeb 100644--- a/agent/subagent_lifecycle.py+++ b/agent/subagent_lifecycle.py@@ -51,6 +51,7 @@ class SubagentLaunchRequest:context: Optional[str] = Nonerole: str = "leaf"model: Optional[str] = None+ provider: Optional[str] = Noneallowed_toolsets: Optional[tuple[str, ...]] = Noneblocked_tools: tuple[str, ...] = ()working_directory: Optional[str] = None@@ -222,6 +223,8 @@ _REQUEST_REJECTIONS: tuple[tuple[Callable[[Any], bool], str], ...] = ((lambda r: r.context is not None and (not isinstance(r.context, str) or len(r.context) > _MAX_CONTEXT_CHARS),"context must be a string of at most 32000 characters."),(lambda r: r.role not in {"leaf", "orchestrator"}, "role must be 'leaf' or 'orchestrator'."),+ (lambda r: r.provider is not None and (not isinstance(r.provider, str) or not r.provider.strip() or len(r.provider) > 64),+ "provider must be a non-empty string of at most 64 characters."),(lambda r: r.timeout_seconds is not None, "Per-launch timeout is not supported; configure delegation timeout explicitly."),(lambda r: r.working_directory is not None,"working_directory is not supported because Hermes delegates use isolated task environments."),@@ -290,8 +293,8 @@ class SubagentLifecycleService:_build_child_preserving_parent_tools, _credential_overrides, _load_config, _resolve_delegation_credentials,DEFAULT_MAX_ITERATIONS,)- # Children follow the delegation config exactly as delegate_task children do.- routing_cfg = _load_config()+ # Routing precedence: request.provider > delegation config > parent.+ routing_cfg = {"provider": request.provider, "model": request.model or ""} if request.provider is not None else _load_config()try:creds = _resolve_delegation_credentials(routing_cfg, parent)except ValueError as exc:diff --git a/tests/agent/test_subagent_lifecycle.py b/tests/agent/test_subagent_lifecycle.pyindex 2b45bdb2244..ba638ff8853 100644--- a/tests/agent/test_subagent_lifecycle.py+++ b/tests/agent/test_subagent_lifecycle.py@@ -323,15 +323,49 @@ def test_routing_delegation_provider_bundle(routing_lifecycle):resolve.assert_called_once_with(requested="openrouter", target_model="delegated-model")-def test_routing_unknown_provider_refuses_before_registration(routing_lifecycle):[email protected]("wire", [False, True])+def test_routing_request_provider_wins_without_mixing_bundles(routing_lifecycle, wire):+ from hermes_cli.plugin_host_wire import decode, encode++ service, build, config, resolve = routing_lifecycle+ config.return_value = {+ "provider": "nous", "model": "delegated-model",+ "base_url": "https://delegation.example/v1", "api_key": "delegation-fixture-key",+ "api_mode": "anthropic_messages", "command": "delegation-command",+ "request_overrides": {"temperature": 0.9},+ }+ request = SubagentLaunchRequest(goal="route", provider="openrouter", model="m")+ request = decode(encode(request)) if wire else request+ if wire:+ assert request["provider"] == "openrouter"+ handle = service.launch(request)+ assert service.wait(handle, timeout_seconds=2).state is SubagentState.SUCCEEDED+ kwargs = build.call_args.kwargs+ assert kwargs["model"] == "m"+ assert kwargs["override_provider"] == "openrouter"+ assert kwargs["override_base_url"] == "https://route.example/v1"+ assert kwargs["override_api_key"] == "fixture-key"+ assert kwargs["override_api_mode"] == "chat_completions"+ assert kwargs["override_request_overrides"] == {"temperature": 0.2}+ assert kwargs["override_acp_command"] is None+ assert kwargs["override_acp_args"] == []+ assert kwargs["routing_cfg"] == {"provider": "openrouter", "model": "m"}+ resolve.assert_called_once_with(requested="openrouter", target_model="m")++[email protected]("per_launch", [False, True])+def test_routing_unknown_provider_refuses_before_registration(routing_lifecycle, per_launch):from agent.subagent_lifecycle import _REGISTRYservice, build, config, resolve = routing_lifecycleresolve.side_effect = ValueError("Unknown provider fixture-missing")- config.return_value = {"provider": "fixture-missing"}+ config.return_value = {} if per_launch else {"provider": "fixture-missing"}+ request = {"goal": "route", "correlation_id": "refused-route"}+ if per_launch:+ request["provider"] = "fixture-missing"records, correlations = dict(_REGISTRY.records), dict(_REGISTRY.correlations)with pytest.raises(SubagentLifecycleError, match="Unknown provider fixture-missing"):- service.launch({"goal": "route", "correlation_id": "refused-route"})+ service.launch(request)assert _REGISTRY.records == recordsassert _REGISTRY.correlations == correlationsbuild.assert_not_called()@@ -357,3 +391,13 @@ def test_routing_request_model_beats_delegation_model(routing_lifecycle):assert service.wait(handle, timeout_seconds=2).state is SubagentState.SUCCEEDEDassert build.call_args.kwargs["model"] == "request-model"assert build.call_args.kwargs["override_base_url"] == "https://direct.example/v1"++[email protected]("provider", ["", " ", 123, "p" * 65])+def test_routing_provider_validation(routing_lifecycle, provider):+ service, build, _config, resolve = routing_lifecycle+ with pytest.raises(SubagentLifecycleError) as exc:+ service.launch({"goal": "route", "provider": provider})+ assert str(exc.value) == "provider must be a non-empty string of at most 64 characters."+ build.assert_not_called()+ resolve.assert_not_called()diff --git a/website/docs/developer-guide/subagent-lifecycle-api.md b/website/docs/developer-guide/subagent-lifecycle-api.mdindex 406753305b8..ca4981241bc 100644--- a/website/docs/developer-guide/subagent-lifecycle-api.md+++ b/website/docs/developer-guide/subagent-lifecycle-api.md@@ -12,7 +12,7 @@ CLI, gateway, non-interactive, and kanban-worker sessions. Launching outside anactive agent turn fails closed with `No active Hermes parent session`.The facade also works when a plugin runs under `plugins.isolation: host`.-Requests accept `goal`, `context`, `role`, `model`, `allowed_toolsets`,+Requests accept `goal`, `context`, `role`, `model`, `provider`, `allowed_toolsets`,`blocked_tools`, `working_directory`, `parent_session_id`, `correlation_id`,`metadata`, and `timeout_seconds`, subject to the restrictions below.@@ -20,8 +20,12 @@ Requests accept `goal`, `context`, `role`, `model`, `allowed_toolsets`,Children follow the `delegation` config (provider, model, base_url,request_overrides, and ACP command) exactly as `delegate_task` children do.-The request's `model` overrides the configured model. A configured provider-that cannot be resolved raises `SubagentLifecycleError` before launch.+The request's `model` overrides the configured model. Its optional `provider`+names a configured provider for this launch, with precedence request >+delegation config > parent; the selected provider supplies its own credential+bundle. An unresolvable provider raises `SubagentLifecycleError` before launch.+Core does not expose `provider` to the model: the plugin chooses it, for example+from operator config.```pythonfrom agent.subagent_lifecycle import SubagentLaunchRequest