mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-07 02:51:50 +00:00
fix(delegate): correct _spawn_child → _build_child_agent in comments
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
42d72b5922
commit
0b5fd40a01
2 changed files with 27 additions and 17 deletions
|
|
@ -821,7 +821,9 @@ class TestDelegationCredentialResolution(unittest.TestCase):
|
||||||
self.assertEqual(creds["api_key"], "local-key")
|
self.assertEqual(creds["api_key"], "local-key")
|
||||||
self.assertEqual(creds["api_mode"], "chat_completions")
|
self.assertEqual(creds["api_mode"], "chat_completions")
|
||||||
|
|
||||||
def test_direct_endpoint_falls_back_to_openai_api_key_env(self):
|
def test_direct_endpoint_returns_none_api_key_when_not_configured(self):
|
||||||
|
# When base_url is set without api_key, api_key should be None so
|
||||||
|
# _build_child_agent inherits the parent's key (effective_api_key = override or parent).
|
||||||
parent = _make_mock_parent(depth=0)
|
parent = _make_mock_parent(depth=0)
|
||||||
cfg = {
|
cfg = {
|
||||||
"model": "qwen2.5-coder",
|
"model": "qwen2.5-coder",
|
||||||
|
|
@ -829,10 +831,11 @@ class TestDelegationCredentialResolution(unittest.TestCase):
|
||||||
}
|
}
|
||||||
with patch.dict(os.environ, {"OPENAI_API_KEY": "env-openai-key"}, clear=False):
|
with patch.dict(os.environ, {"OPENAI_API_KEY": "env-openai-key"}, clear=False):
|
||||||
creds = _resolve_delegation_credentials(cfg, parent)
|
creds = _resolve_delegation_credentials(cfg, parent)
|
||||||
self.assertEqual(creds["api_key"], "env-openai-key")
|
self.assertIsNone(creds["api_key"])
|
||||||
self.assertEqual(creds["provider"], "custom")
|
self.assertEqual(creds["provider"], "custom")
|
||||||
|
|
||||||
def test_direct_endpoint_does_not_fall_back_to_openrouter_api_key_env(self):
|
def test_direct_endpoint_no_raise_when_only_provider_env_key_present(self):
|
||||||
|
# Even if OPENAI_API_KEY is absent, no ValueError — _build_child_agent uses parent key.
|
||||||
parent = _make_mock_parent(depth=0)
|
parent = _make_mock_parent(depth=0)
|
||||||
cfg = {
|
cfg = {
|
||||||
"model": "qwen2.5-coder",
|
"model": "qwen2.5-coder",
|
||||||
|
|
@ -846,9 +849,9 @@ class TestDelegationCredentialResolution(unittest.TestCase):
|
||||||
},
|
},
|
||||||
clear=False,
|
clear=False,
|
||||||
):
|
):
|
||||||
with self.assertRaises(ValueError) as ctx:
|
creds = _resolve_delegation_credentials(cfg, parent)
|
||||||
_resolve_delegation_credentials(cfg, parent)
|
self.assertIsNone(creds["api_key"])
|
||||||
self.assertIn("OPENAI_API_KEY", str(ctx.exception))
|
self.assertEqual(creds["provider"], "custom")
|
||||||
|
|
||||||
@patch("hermes_cli.runtime_provider.resolve_runtime_provider")
|
@patch("hermes_cli.runtime_provider.resolve_runtime_provider")
|
||||||
def test_nous_provider_resolves_nous_credentials(self, mock_resolve):
|
def test_nous_provider_resolves_nous_credentials(self, mock_resolve):
|
||||||
|
|
|
||||||
|
|
@ -2237,11 +2237,17 @@ def _resolve_delegation_credentials(cfg: dict, parent_agent) -> dict:
|
||||||
"""Resolve credentials for subagent delegation.
|
"""Resolve credentials for subagent delegation.
|
||||||
|
|
||||||
If ``delegation.base_url`` is configured, subagents use that direct
|
If ``delegation.base_url`` is configured, subagents use that direct
|
||||||
OpenAI-compatible endpoint. Otherwise, if ``delegation.provider`` is
|
OpenAI-compatible endpoint. ``delegation.api_key`` overrides the key; when
|
||||||
configured, the full credential bundle (base_url, api_key, api_mode,
|
omitted, ``api_key`` is returned as ``None`` so ``_build_child_agent``
|
||||||
provider) is resolved via the runtime provider system — the same path used
|
inherits the parent agent's key (``effective_api_key = override_api_key or
|
||||||
by CLI/gateway startup. This lets subagents run on a completely different
|
parent_api_key``). This lets providers that store their key outside
|
||||||
provider:model pair.
|
``OPENAI_API_KEY`` (e.g. ``MINIMAX_API_KEY``, ``DASHSCOPE_API_KEY``) work
|
||||||
|
without a duplicate config entry.
|
||||||
|
|
||||||
|
Otherwise, if ``delegation.provider`` is configured, the full credential
|
||||||
|
bundle (base_url, api_key, api_mode, provider) is resolved via the runtime
|
||||||
|
provider system — the same path used by CLI/gateway startup. This lets
|
||||||
|
subagents run on a completely different provider:model pair.
|
||||||
|
|
||||||
If neither base_url nor provider is configured, returns None values so the
|
If neither base_url nor provider is configured, returns None values so the
|
||||||
child inherits everything from the parent agent.
|
child inherits everything from the parent agent.
|
||||||
|
|
@ -2254,12 +2260,13 @@ def _resolve_delegation_credentials(cfg: dict, parent_agent) -> dict:
|
||||||
configured_api_key = str(cfg.get("api_key") or "").strip() or None
|
configured_api_key = str(cfg.get("api_key") or "").strip() or None
|
||||||
|
|
||||||
if configured_base_url:
|
if configured_base_url:
|
||||||
api_key = configured_api_key or os.getenv("OPENAI_API_KEY", "").strip()
|
# When delegation.api_key is not set, return None so _build_child_agent
|
||||||
if not api_key:
|
# falls back to the parent agent's API key via the credential inheritance
|
||||||
raise ValueError(
|
# path (effective_api_key = override_api_key or parent_api_key). This
|
||||||
"Delegation base_url is configured but no API key was found. "
|
# lets providers that store their key in a non-OPENAI_API_KEY env var
|
||||||
"Set delegation.api_key or OPENAI_API_KEY."
|
# (e.g. MINIMAX_API_KEY, DASHSCOPE_API_KEY) work without requiring
|
||||||
)
|
# callers to duplicate the key under delegation.api_key.
|
||||||
|
api_key = configured_api_key # None → inherited from parent in _build_child_agent
|
||||||
|
|
||||||
base_lower = configured_base_url.lower()
|
base_lower = configured_base_url.lower()
|
||||||
provider = "custom"
|
provider = "custom"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue