From 0310170869aa2581e03123da686fe83aafa91d12 Mon Sep 17 00:00:00 2001 From: Raeli Savitt Date: Wed, 25 Feb 2026 22:37:36 -0500 Subject: [PATCH] Fix subagent auth: propagate parent API key to child agents When using Nous Portal (or any non-OpenRouter provider), child agents spawned by delegate_task failed with "No pricing available" or "Unknown model" errors because they had no valid API key. The delegate tool passed base_url but not api_key to child AIAgent instances. Without an explicit key, children fell back to the empty OPENROUTER_API_KEY env var, causing auth failures. Extract the parent's API key from _client_kwargs and pass it through. Co-Authored-By: Claude Opus 4.6 --- tools/delegate_tool.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/delegate_tool.py b/tools/delegate_tool.py index 111beb33a..4ce109f57 100644 --- a/tools/delegate_tool.py +++ b/tools/delegate_tool.py @@ -99,8 +99,14 @@ def _run_single_child( child_prompt = _build_child_system_prompt(goal, context) try: + # Extract parent's API key so subagents inherit auth (e.g. Nous Portal) + parent_api_key = None + if hasattr(parent_agent, '_client_kwargs'): + parent_api_key = parent_agent._client_kwargs.get("api_key") + child = AIAgent( base_url=parent_agent.base_url, + api_key=parent_api_key, model=model or parent_agent.model, max_iterations=max_iterations, enabled_toolsets=child_toolsets,