Skip to content

The agent that grows with you

test/docs: trim seam tests to invariants, document create_client and external-process fields

Teknium0cbc6e37ac9f
diff --git a/tests/agent/test_provider_client_seam.py b/tests/agent/test_provider_client_seam.py
index 752093448c6..2514977b0ca 100644
--- a/tests/agent/test_provider_client_seam.py
+++ b/tests/agent/test_provider_client_seam.py
@@ -1,32 +1,28 @@
"""A provider profile can supply its own client — the registration seam.
-Most providers speak OpenAI-over-HTTP and want the client the core builds. A
-provider whose wire protocol is something else (the ACP subprocess shims) must
-be able to supply its own — and must be able to do so from *outside* this tree,
-otherwise every such integration has to edit ``create_openai_client`` by hand.
-
-These tests pin the hook, the two resolution paths into it (provider name and
-``base_url``), its failure isolation, and the capability flags that let such a
-client opt out of the transport/async wrappers without this code importing it.
+A provider whose wire protocol is not OpenAI-over-HTTP (the ACP subprocess
+shims) supplies its client via ``ProviderProfile.create_client()``, from inside
+or outside the tree. These tests pin the hook through the real entry point
+(``create_openai_client``), its failure isolation, and the capability flags
+that let such a client opt out of the auxiliary transport/async wrappers.
"""
from __future__ import annotations
-import os
-import sys
from types import SimpleNamespace
import pytest
-_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-if _REPO_ROOT not in sys.path:
- sys.path.insert(0, _REPO_ROOT)
-
-import providers as _providers # noqa: E402
-from providers.base import ProviderProfile # noqa: E402
+import providers as _providers
+from providers.base import ProviderProfile
class _FakeClient:
+ HERMES_SKIP_TRANSPORT_WRAP = True
+ HERMES_SKIP_ASYNC_WRAP = True
+ api_key = "k"
+ base_url = "acp://seam-test"
+
def __init__(self, **kwargs):
self.kwargs = kwargs
@@ -45,18 +41,8 @@ class _ExplodingProfile(ProviderProfile):
def registered():
"""Register profiles for one test and restore the registry afterwards."""
_providers._discover_providers()
- snapshot = (
- dict(_providers._REGISTRY),
- dict(_providers._ALIASES),
- _providers._PROVIDER_LIST_CACHE,
- )
-
- def _register(profile):
- _providers.register_provider(profile)
- return profile
-
- yield _register
-
+ snapshot = (dict(_providers._REGISTRY), dict(_providers._ALIASES), _providers._PROVIDER_LIST_CACHE)
+ yield _providers.register_provider
_providers._REGISTRY.clear()
_providers._REGISTRY.update(snapshot[0])
_providers._ALIASES.clear()
@@ -65,7 +51,6 @@ def registered():
def _agent(provider: str = ""):
- """The minimal agent surface create_openai_client touches."""
return SimpleNamespace(
provider=provider,
_client_log_context=lambda: "",
@@ -73,183 +58,47 @@ def _agent(provider: str = ""):
)
-# ── the hook itself ──────────────────────────────────────────────────────────
-
-
-def test_the_default_profile_supplies_no_client():
- """Every ordinary provider inherits this and keeps the standard client."""
- assert ProviderProfile(name="plain").create_client(api_key="k") is None
-
-
-def test_a_profile_can_supply_its_own_client(registered):
- from agent.agent_runtime_helpers import _provider_supplied_client
+def _build(provider, base_url):
+ from agent.agent_runtime_helpers import create_openai_client
- registered(_SeamProfile(name="seam-test", base_url="acp://seam-test"))
- client = _provider_supplied_client(_agent("seam-test"), {"api_key": "k"})
- assert isinstance(client, _FakeClient)
- assert client.kwargs == {"api_key": "k"}
+ return create_openai_client(_agent(provider), {"api_key": "k", "base_url": base_url}, reason="t", shared=False)
-def test_an_alias_reaches_the_same_profile(registered):
- from agent.agent_runtime_helpers import _provider_supplied_client
+def test_an_out_of_tree_profile_supplies_the_client_through_create_openai_client(registered):
+ from openai import OpenAI
registered(_SeamProfile(name="seam-test", aliases=("seam",), base_url="acp://seam-test"))
- assert isinstance(_provider_supplied_client(_agent("seam"), {}), _FakeClient)
+ # By name, by alias, and by base_url prefix when no provider name is set.
+ assert isinstance(_build("seam-test", "acp://seam-test"), _FakeClient)
+ assert isinstance(_build("seam", "acp://seam-test"), _FakeClient)
+ assert isinstance(_build("", "acp://seam-test/x"), _FakeClient)
+ # No hook → the standard client, untouched by the seam.
+ assert isinstance(_build("openai-api", "https://api.example/v1"), OpenAI)
-def test_the_base_url_resolves_the_profile_when_the_name_does_not(registered):
- """A runtime configured only by URL still reaches its provider's client."""
- from agent.agent_runtime_helpers import _provider_supplied_client
-
- registered(_SeamProfile(name="seam-test", base_url="acp://seam-test"))
- client = _provider_supplied_client(_agent(""), {"base_url": "acp://seam-test"})
- assert isinstance(client, _FakeClient)
- # Prefix, not equality — the branch this replaced keyed on startswith().
- assert isinstance(
- _provider_supplied_client(_agent(""), {"base_url": "acp://seam-test/x"}),
- _FakeClient,
- )
- # A different scheme must not be captured.
- assert _provider_supplied_client(_agent(""), {"base_url": "https://api.example/v1"}) is None
-
-
-def test_an_unregistered_provider_gets_no_client(registered):
- from agent.agent_runtime_helpers import _provider_supplied_client
-
- assert _provider_supplied_client(_agent("nothing-registered-here"), {}) is None
-
-
-def test_a_broken_plugin_cannot_take_the_turn_down(registered):
- """A third-party profile that raises falls through to the standard path."""
+def test_a_broken_plugin_falls_through_instead_of_taking_the_turn_down(registered):
from agent.agent_runtime_helpers import _provider_supplied_client
registered(_ExplodingProfile(name="seam-boom", base_url="acp://seam-boom"))
assert _provider_supplied_client(_agent("seam-boom"), {"api_key": "k"}) is None
-# ── the in-tree consumer ─────────────────────────────────────────────────────
-
-
-def test_copilot_acp_still_gets_its_acp_client():
- """copilot-acp lost its hardcoded branch in create_openai_client; it must
- still be constructed, now via its profile."""
+def test_copilot_acp_still_gets_its_acp_client_via_its_profile():
from agent.copilot_acp_client import CopilotACPClient
- from providers import get_provider_profile
-
- profile = get_provider_profile("copilot-acp")
- assert profile is not None
- client = profile.create_client(api_key="copilot-acp", base_url="acp://copilot")
- assert isinstance(client, CopilotACPClient)
-
-
-def test_copilot_acp_reaches_the_seam_by_name_and_by_url():
- from agent.agent_runtime_helpers import _provider_supplied_client
- from agent.copilot_acp_client import CopilotACPClient
-
- by_name = _provider_supplied_client(
- _agent("copilot-acp"), {"api_key": "copilot-acp", "base_url": "acp://copilot"}
- )
- assert isinstance(by_name, CopilotACPClient)
- by_url = _provider_supplied_client(
- _agent(""), {"api_key": "copilot-acp", "base_url": "acp://copilot"}
- )
- assert isinstance(by_url, CopilotACPClient)
+ assert isinstance(_build("copilot-acp", "acp://copilot"), CopilotACPClient)
+ assert isinstance(_build("", "acp://copilot"), CopilotACPClient)
-# ── the wiring, not just the helper ──────────────────────────────────────────
-
-def test_create_openai_client_actually_consults_the_profile(registered):
- """Exercise the real construction entry point, not the helper it calls.
-
- The helper being correct is worth nothing if ``create_openai_client`` stops
- calling it — that is the regression this file exists to prevent.
- """
- from agent.agent_runtime_helpers import create_openai_client
-
- registered(_SeamProfile(name="seam-test", base_url="acp://seam-test"))
- client = create_openai_client(
- _agent("seam-test"),
- {"api_key": "k", "base_url": "acp://seam-test"},
- reason="test",
- shared=False,
- )
- assert isinstance(client, _FakeClient)
-
-
-def test_create_openai_client_still_builds_the_standard_client(registered):
- """A provider with no profile hook is untouched by the seam."""
- from openai import OpenAI
-
- from agent.agent_runtime_helpers import create_openai_client
-
- client = create_openai_client(
- _agent("openai-api"),
- {"api_key": "k", "base_url": "https://api.example/v1"},
- reason="test",
- shared=False,
- )
- assert isinstance(client, OpenAI)
-
-
-def test_create_openai_client_builds_the_copilot_acp_client():
- """The in-tree consumer, through the same entry point its hardcoded branch
- used to serve."""
- from agent.agent_runtime_helpers import create_openai_client
- from agent.copilot_acp_client import CopilotACPClient
-
- client = create_openai_client(
- _agent("copilot-acp"),
- {"api_key": "copilot-acp", "base_url": "acp://copilot"},
- reason="test",
- shared=False,
- )
- assert isinstance(client, CopilotACPClient)
-
-
-# ── capability flags replacing the isinstance checks ─────────────────────────
-
-
-def test_clients_declaring_skip_flags_are_not_wrapped():
- from agent.auxiliary_client import _client_declares
-
- class _Final:
- HERMES_SKIP_TRANSPORT_WRAP = True
- HERMES_SKIP_ASYNC_WRAP = True
-
- class _Plain:
- pass
-
- final = _Final()
- assert _client_declares(final, "HERMES_SKIP_TRANSPORT_WRAP")
- assert _client_declares(final, "HERMES_SKIP_ASYNC_WRAP")
- # Absent attribute → False, so every ordinary client keeps its behaviour.
- assert not _client_declares(_Plain(), "HERMES_SKIP_TRANSPORT_WRAP")
- assert not _client_declares(None, "HERMES_SKIP_TRANSPORT_WRAP")
-
-
-def test_the_in_tree_clients_declare_what_their_isinstance_checks_used_to_say():
- """copilot-acp skipped both wrappers; the Gemini native client skipped only
- the transport one (its async path is a real conversion)."""
+def test_skip_flags_replace_the_isinstance_checks_for_in_and_out_of_tree_clients():
+ from agent.auxiliary_client import _maybe_wrap_anthropic, _to_async_client
from agent.copilot_acp_client import CopilotACPClient
from agent.gemini_native_adapter import GeminiNativeClient
- assert CopilotACPClient.HERMES_SKIP_TRANSPORT_WRAP is True
- assert CopilotACPClient.HERMES_SKIP_ASYNC_WRAP is True
- assert GeminiNativeClient.HERMES_SKIP_TRANSPORT_WRAP is True
- assert getattr(GeminiNativeClient, "HERMES_SKIP_ASYNC_WRAP", False) is False
-
-
-def test_an_out_of_tree_client_is_covered_by_the_same_flags():
- """The point of the flags: auxiliary_client never imports this class."""
- from agent.auxiliary_client import _maybe_wrap_anthropic, _to_async_client
-
- class _ThirdPartyClient:
- HERMES_SKIP_TRANSPORT_WRAP = True
- HERMES_SKIP_ASYNC_WRAP = True
- api_key = "k"
- base_url = "acp://third-party"
+ assert CopilotACPClient.HERMES_SKIP_TRANSPORT_WRAP and CopilotACPClient.HERMES_SKIP_ASYNC_WRAP
+ assert GeminiNativeClient.HERMES_SKIP_TRANSPORT_WRAP
+ assert not getattr(GeminiNativeClient, "HERMES_SKIP_ASYNC_WRAP", False)
- client = _ThirdPartyClient()
- assert _maybe_wrap_anthropic(client, "m", "k", "acp://third-party") is client
+ client = _FakeClient() # never imported by auxiliary_client
+ assert _maybe_wrap_anthropic(client, "m", "k", "acp://seam-test") is client
assert _to_async_client(client, "m")[0] is client
diff --git a/tests/hermes_cli/test_external_process_provider_seam.py b/tests/hermes_cli/test_external_process_provider_seam.py
index e0e6f73369b..47f3f476682 100644
--- a/tests/hermes_cli/test_external_process_provider_seam.py
+++ b/tests/hermes_cli/test_external_process_provider_seam.py
@@ -1,60 +1,36 @@
-"""An external-process provider can ship from outside this tree.
-
-An ACP agent CLI is not an HTTP endpoint: it is a subprocess Hermes drives over
-stdio. Everything about launching it used to be spelled out for one vendor —
-the known-provider gate, the binary, the argv, the env var names. A provider
-registered from ``~/.hermes/plugins/model-providers/`` or a pip entry point
-therefore could not be reached at all: ``hermes -m <it>`` died with "Unknown
-provider" long before any client was built.
-
-This registers a provider the way a standalone package does — before importing
-any ``hermes_cli`` module, exactly as plugin discovery does — and walks the real
-resolution path end to end. ``copilot-acp`` is asserted alongside it at every
-step, so the generalisation cannot quietly change the in-tree provider.
+"""An external-process (ACP) provider can ship from outside this tree.
+
+The known-provider gate, the binary, the argv and the env var names used to be
+spelled out for one vendor, so a profile registered from a plugin died with
+"Unknown provider" before any client was built. This registers a provider the
+way a standalone package does — before importing ``hermes_cli`` — and walks the
+real resolution path, asserting ``copilot-acp`` is unchanged alongside it.
"""
from __future__ import annotations
import os
import stat
-import sys
import pytest
-_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-if _REPO_ROOT not in sys.path:
- sys.path.insert(0, _REPO_ROOT)
-
-from providers import register_provider # noqa: E402
-from providers.base import ProviderProfile # noqa: E402
-
-
-class _AcmeClient:
- HERMES_SKIP_TRANSPORT_WRAP = True
- HERMES_SKIP_ASYNC_WRAP = True
-
- def __init__(self, **kwargs):
- self.kwargs = kwargs
- self.api_key = kwargs.get("api_key")
- self.base_url = kwargs.get("base_url")
+from providers import register_provider
+from providers.base import ProviderProfile
class _AcmeACPProfile(ProviderProfile):
def create_client(self, **kwargs):
- return _AcmeClient(**kwargs)
+ return ("acme-client", kwargs)
def fetch_models(self, **kwargs):
return None
-# Registered at import time — the same moment a plugin's ``__init__.py`` or a
-# pip entry point runs, i.e. before hermes_cli.auth builds PROVIDER_REGISTRY.
register_provider(
_AcmeACPProfile(
name="acme-acp",
aliases=("acme",),
display_name="Acme ACP",
- api_mode="chat_completions",
base_url="acp://acme",
auth_type="external_process",
process_command="acme-cli",
@@ -67,152 +43,44 @@ register_provider(
@pytest.fixture
def fake_cli(tmp_path, monkeypatch):
- """Put stub `acme-cli` and `copilot` binaries on PATH."""
bindir = tmp_path / "bin"
bindir.mkdir()
- for name in ("acme-cli", "copilot"):
+ for name in ("acme-cli", "copilot", "custom-acme"):
exe = bindir / name
exe.write_text("#!/bin/sh\nexit 0\n")
- exe.chmod(exe.stat().st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
+ exe.chmod(exe.stat().st_mode | stat.S_IEXEC)
monkeypatch.setenv("PATH", f"{bindir}{os.pathsep}{os.environ.get('PATH', '')}")
return bindir
-# ── the known-provider gate ──────────────────────────────────────────────────
-
-
-def test_the_provider_is_absorbed_into_the_cli_registry():
- """Without this the resolver raises "Unknown provider" before anything else."""
- from hermes_cli.auth import PROVIDER_REGISTRY
+def test_an_out_of_tree_external_process_provider_resolves_end_to_end(fake_cli, monkeypatch):
+ from hermes_cli.auth import PROVIDER_REGISTRY, resolve_external_process_provider_credentials, resolve_provider
+ from hermes_cli.runtime_provider import resolve_runtime_provider
- assert "acme-acp" in PROVIDER_REGISTRY
- assert PROVIDER_REGISTRY["acme-acp"].auth_type == "external_process"
- assert PROVIDER_REGISTRY["acme-acp"].inference_base_url == "acp://acme"
- assert PROVIDER_REGISTRY["acme-acp"].name == "Acme ACP"
- # Aliases resolve to the same config.
assert PROVIDER_REGISTRY["acme"] is PROVIDER_REGISTRY["acme-acp"]
- # The in-tree one is declared explicitly and must not be shadowed.
- assert PROVIDER_REGISTRY["copilot-acp"].auth_type == "external_process"
-
-
-def test_resolve_provider_accepts_the_name_and_its_alias():
- from hermes_cli.auth import resolve_provider
-
- assert resolve_provider("acme-acp") == "acme-acp"
+ assert PROVIDER_REGISTRY["acme-acp"].auth_type == "external_process"
assert resolve_provider("acme") == "acme-acp"
-
-# ── launching the CLI ────────────────────────────────────────────────────────
-
-
-def test_credentials_come_from_the_profile(fake_cli):
- from hermes_cli.auth import resolve_external_process_provider_credentials
-
creds = resolve_external_process_provider_credentials("acme-acp")
- assert creds["command"] == str(fake_cli / "acme-cli")
- assert creds["args"] == ["--acp"]
- assert creds["base_url"] == "acp://acme"
- # Placeholder credential keyed on the provider, not a borrowed literal.
- assert creds["api_key"] == "acme-acp"
+ assert (creds["command"], creds["args"], creds["api_key"]) == (str(fake_cli / "acme-cli"), ["--acp"], "acme-acp")
+ monkeypatch.setenv("ACME_CLI_PATH", str(fake_cli / "custom-acme"))
+ monkeypatch.setenv("ACME_ACP_ARGS", "--acp=true --verbose")
+ creds = resolve_external_process_provider_credentials("acme-acp")
+ assert (creds["command"], creds["args"]) == (str(fake_cli / "custom-acme"), ["--acp=true", "--verbose"])
-def test_copilot_launch_details_are_unchanged(fake_cli):
- """These moved from hardcoded resolver code into copilot-acp's profile."""
- from hermes_cli.auth import resolve_external_process_provider_credentials
-
- creds = resolve_external_process_provider_credentials("copilot-acp")
- assert creds["command"] == str(fake_cli / "copilot")
- assert creds["args"] == ["--acp", "--stdio"]
- assert creds["api_key"] == "copilot-acp"
- assert creds["base_url"] == "acp://copilot"
-
-
- "provider,env_var,binary",
- [
- ("acme-acp", "ACME_CLI_PATH", "acme-cli"),
- ("copilot-acp", "HERMES_COPILOT_ACP_COMMAND", "copilot"),
- ("copilot-acp", "COPILOT_CLI_PATH", "copilot"),
- ],
-)
-def test_the_binary_can_be_overridden_by_env(fake_cli, monkeypatch, provider, env_var, binary):
- from hermes_cli.auth import resolve_external_process_provider_credentials
-
- custom = fake_cli / f"custom-{binary}"
- custom.write_text("#!/bin/sh\nexit 0\n")
- custom.chmod(custom.stat().st_mode | stat.S_IEXEC)
- monkeypatch.setenv(env_var, str(custom))
- creds = resolve_external_process_provider_credentials(provider)
- assert creds["command"] == str(custom)
+ runtime = resolve_runtime_provider(requested="acme", target_model="acme")
+ assert (runtime["provider"], runtime["base_url"], runtime["source"]) == ("acme-acp", "acp://acme", "process")
- "provider,env_var",
- [("acme-acp", "ACME_ACP_ARGS"), ("copilot-acp", "HERMES_COPILOT_ACP_ARGS")],
-)
-def test_the_args_can_be_overridden_by_env(fake_cli, monkeypatch, provider, env_var):
+def test_copilot_acp_launch_details_are_unchanged(fake_cli, monkeypatch):
from hermes_cli.auth import resolve_external_process_provider_credentials
-
- monkeypatch.setenv(env_var, "--acp=true --verbose")
- assert resolve_external_process_provider_credentials(provider)["args"] == [
- "--acp=true",
- "--verbose",
- ]
-
-
-def test_a_missing_binary_names_the_provider_and_its_env_override(monkeypatch, tmp_path):
- from hermes_cli.auth import AuthError, resolve_external_process_provider_credentials
-
- monkeypatch.setenv("PATH", str(tmp_path))
- with pytest.raises(AuthError) as excinfo:
- resolve_external_process_provider_credentials("acme-acp")
- message = str(excinfo.value)
- assert "acme-acp" in message
- assert "ACME_CLI_PATH" in message
-
-
-def test_a_non_external_process_provider_is_still_rejected():
- from hermes_cli.auth import AuthError, resolve_external_process_provider_credentials
-
- with pytest.raises(AuthError):
- resolve_external_process_provider_credentials("openai-api")
-
-
-# ── runtime resolution ───────────────────────────────────────────────────────
-
-
- "requested,expected_base_url",
- [
- ("acme-acp", "acp://acme"),
- ("acme", "acp://acme"),
- ("copilot-acp", "acp://copilot"),
- ],
-)
-def test_runtime_resolution_reaches_the_external_process_branch(
- fake_cli, requested, expected_base_url
-):
- """Previously keyed on the literal "copilot-acp", so anything else fell
- through to the OpenRouter default instead of its own runtime."""
from hermes_cli.runtime_provider import resolve_runtime_provider
- runtime = resolve_runtime_provider(requested=requested, target_model=requested)
- assert runtime["base_url"] == expected_base_url
- assert runtime["api_mode"] == "chat_completions"
- assert runtime["source"] == "process"
- assert runtime["command"]
-
-
-def test_the_client_is_built_from_the_profile(fake_cli):
- from types import SimpleNamespace
-
- from agent.agent_runtime_helpers import _provider_supplied_client
- from hermes_cli.runtime_provider import resolve_runtime_provider
+ creds = resolve_external_process_provider_credentials("copilot-acp")
+ assert creds["command"] == str(fake_cli / "copilot")
+ assert (creds["args"], creds["api_key"], creds["base_url"]) == (["--acp", "--stdio"], "copilot-acp", "acp://copilot")
- runtime = resolve_runtime_provider(requested="acme-acp", target_model="acme-acp")
- agent = SimpleNamespace(provider=runtime["provider"], _client_log_context=lambda: "")
- client = _provider_supplied_client(
- agent, {"api_key": runtime["api_key"], "base_url": runtime["base_url"]}
- )
- assert isinstance(client, _AcmeClient)
- assert client.base_url == "acp://acme"
+ monkeypatch.setenv("COPILOT_CLI_PATH", str(fake_cli / "custom-acme"))
+ assert resolve_external_process_provider_credentials("copilot-acp")["command"] == str(fake_cli / "custom-acme")
+ assert resolve_runtime_provider(requested="copilot-acp", target_model="x")["base_url"] == "acp://copilot"
diff --git a/tests/providers/test_installed_plugin_discovery.py b/tests/providers/test_installed_plugin_discovery.py
index 252009b61b3..985aaf8b539 100644
--- a/tests/providers/test_installed_plugin_discovery.py
+++ b/tests/providers/test_installed_plugin_discovery.py
@@ -1,15 +1,10 @@
"""A provider installed by ``hermes plugins install`` must actually be found.
-``hermes plugins install owner/repo`` (and the plugin index behind
-``hermes plugins search``) clones into ``$HERMES_HOME/plugins/<name>/`` — flat,
-one directory per plugin. Provider discovery only ever scanned
-``$HERMES_HOME/plugins/model-providers/<name>/``, and ``PluginManager`` skips
-``kind: model-provider`` on purpose ("routed to their own discovery system").
-
-Nothing joined those two halves, so the documented install path half-worked: the
-CLI reported success and the provider silently did not exist. These tests pin
-the join, and pin that provider discovery still keeps its hands off every other
-plugin living in that same directory.
+The installer clones into ``$HERMES_HOME/plugins/<name>/`` (flat), provider
+discovery only scanned ``plugins/model-providers/<name>/``, and PluginManager
+skips ``kind: model-provider`` on purpose — so the documented install path
+reported success and registered nothing. These tests pin the join, and that
+discovery keeps its hands off every other plugin in that directory.
"""
from __future__ import annotations
@@ -20,25 +15,18 @@ from pathlib import Path
import pytest
-REPO_ROOT = Path(__file__).resolve().parents[2]
-
_PROFILE_SOURCE = textwrap.dedent(
"""
from providers import register_provider
from providers.base import ProviderProfile
- register_provider(ProviderProfile(
- name="{name}",
- aliases=("{name}-alias",),
- base_url="acp://{name}",
- auth_type="external_process",
- ))
+ register_provider(ProviderProfile(name="{name}", aliases=("{name}-alias",),
+ base_url="acp://{name}", auth_type="external_process"))
"""
)
def _clear_provider_caches():
- """Force providers/__init__.py to re-discover on the next lookup."""
import providers as _pkg
_pkg._REGISTRY.clear()
@@ -46,23 +34,16 @@ def _clear_provider_caches():
_pkg._PROVIDER_LIST_CACHE = None
_pkg._discovered = False
for mod in list(sys.modules):
- if mod.startswith("plugins.model_providers") or mod.startswith(
- "_hermes_user_provider"
- ):
+ if mod.startswith(("plugins.model_providers", "_hermes_user_provider")):
del sys.modules[mod]
-def _write_plugin(directory: Path, *, name: str, kind: str, body: str | None = None):
+def _write_plugin(directory: Path, *, name: str, manifest: str | None):
directory.mkdir(parents=True, exist_ok=True)
- (directory / "plugin.yaml").write_text(
- f"name: {name}\nkind: {kind}\nversion: 1.0.0\ndescription: test fixture\n",
- encoding="utf-8",
- )
- (directory / "__init__.py").write_text(
- body if body is not None else _PROFILE_SOURCE.format(name=name),
- encoding="utf-8",
- )
- return directory
+ if manifest is not None:
+ (directory / "plugin.yaml").write_text(manifest, encoding="utf-8")
+ # Registers a provider on import, so an unwanted import is *visible*.
+ (directory / "__init__.py").write_text(_PROFILE_SOURCE.format(name=name), encoding="utf-8")
@pytest.fixture
@@ -73,126 +54,25 @@ def hermes_home(tmp_path, monkeypatch):
_clear_provider_caches()
-def test_a_plugin_installed_flat_is_discovered(hermes_home):
- """The layout `hermes plugins install` actually produces."""
- _write_plugin(
- hermes_home / "plugins" / "installed-acp", name="installed-acp", kind="model-provider"
- )
- from providers import get_provider_profile
-
- profile = get_provider_profile("installed-acp")
- assert profile is not None
- assert profile.base_url == "acp://installed-acp"
- assert profile.auth_type == "external_process"
-
-
-def test_its_aliases_resolve_too(hermes_home):
- _write_plugin(
- hermes_home / "plugins" / "installed-acp", name="installed-acp", kind="model-provider"
- )
+def test_flat_installed_model_provider_plugins_are_discovered_alongside_nested_ones(hermes_home):
+ _write_plugin(hermes_home / "plugins" / "installed-acp", name="installed-acp",
+ manifest='name: installed-acp\nkind: "model-provider"\n')
+ _write_plugin(hermes_home / "plugins" / "model-providers" / "nested-acp", name="nested-acp",
+ manifest="name: nested-acp\nkind: model-provider\n")
from providers import get_provider_profile
+ assert get_provider_profile("installed-acp").base_url == "acp://installed-acp"
assert get_provider_profile("installed-acp-alias") is not None
-
-
-def test_the_model_providers_layout_still_works(hermes_home):
- """The pre-existing nested location must not regress."""
- _write_plugin(
- hermes_home / "plugins" / "model-providers" / "nested-acp",
- name="nested-acp",
- kind="model-provider",
- )
- from providers import get_provider_profile
-
- assert get_provider_profile("nested-acp") is not None
-
-
-def test_both_layouts_coexist(hermes_home):
- _write_plugin(
- hermes_home / "plugins" / "installed-acp", name="installed-acp", kind="model-provider"
- )
- _write_plugin(
- hermes_home / "plugins" / "model-providers" / "nested-acp",
- name="nested-acp",
- kind="model-provider",
- )
- from providers import get_provider_profile
-
- assert get_provider_profile("installed-acp") is not None
assert get_provider_profile("nested-acp") is not None
-# ── discovery must not overreach ─────────────────────────────────────────────
-
-
[email protected]("kind", ["standalone", "backend", "platform", "exclusive"])
-def test_other_plugin_kinds_are_left_to_the_plugin_manager(hermes_home, kind):
- """Those belong to PluginManager, which owns their lifecycle and consent
- flow. Importing them here would run third-party code behind its back.
-
- The fixture registers a provider on import, so an unwanted import is
- *visible* — a plugin that merely raised would be swallowed by
- ``_import_plugin_dir``'s except and prove nothing.
- """
- _write_plugin(
- hermes_home / "plugins" / f"other-{kind}",
- name=f"other-{kind}",
- kind=kind,
- body=_PROFILE_SOURCE.format(name=f"other-{kind}"),
- )
- from providers import get_provider_profile, list_providers
-
- assert get_provider_profile(f"other-{kind}") is None
- assert not [p for p in list_providers() if p.name.startswith("other-")]
-
-
-def test_a_plugin_with_no_manifest_is_ignored(hermes_home):
- directory = hermes_home / "plugins" / "manifestless"
- directory.mkdir(parents=True)
- # Registers on import, so an unwanted import shows up as a provider.
- (directory / "__init__.py").write_text(
- _PROFILE_SOURCE.format(name="manifestless"), encoding="utf-8"
- )
- from providers import get_provider_profile
-
- assert get_provider_profile("manifestless") is None
-
-
-def test_an_unreadable_manifest_does_not_break_discovery(hermes_home):
- """A malformed third-party manifest must not blank the whole registry."""
- directory = hermes_home / "plugins" / "broken-manifest"
- directory.mkdir(parents=True)
- (directory / "plugin.yaml").write_text("kind: [this is: not valid\n", encoding="utf-8")
- (directory / "__init__.py").write_text("", encoding="utf-8")
+def test_other_plugins_in_the_flat_directory_are_left_to_the_plugin_manager(hermes_home):
+ _write_plugin(hermes_home / "plugins" / "other-standalone", name="other-standalone",
+ manifest="name: other-standalone\nkind: standalone\n")
+ _write_plugin(hermes_home / "plugins" / "manifestless", name="manifestless", manifest=None)
+ _write_plugin(hermes_home / "plugins" / "broken-manifest", name="broken-manifest",
+ manifest="kind: [this is: not valid\n")
from providers import get_provider_profile, list_providers
- assert len(list_providers()) > 20 # the bundled set is still there
- assert get_provider_profile("copilot-acp") is not None
-
-
-def test_quoted_kind_values_are_accepted(hermes_home):
- """The fallback line scan runs when PyYAML is unavailable; a quoted scalar
- is valid YAML and must parse the same either way."""
- directory = hermes_home / "plugins" / "quoted-acp"
- directory.mkdir(parents=True)
- (directory / "plugin.yaml").write_text(
- 'name: quoted-acp\nkind: "model-provider"\nversion: 1.0.0\n', encoding="utf-8"
- )
- (directory / "__init__.py").write_text(
- _PROFILE_SOURCE.format(name="quoted-acp"), encoding="utf-8"
- )
- from providers import get_provider_profile
-
- assert get_provider_profile("quoted-acp") is not None
-
-
-def test_discovery_survives_a_missing_hermes_home(tmp_path, monkeypatch):
- """No $HERMES_HOME/plugins/ at all — the bundled set must still load."""
- monkeypatch.setenv("HERMES_HOME", str(tmp_path / "does-not-exist"))
- _clear_provider_caches()
- try:
- from providers import get_provider_profile
-
- assert get_provider_profile("copilot-acp") is not None
- finally:
- _clear_provider_caches()
+ assert not [p for p in list_providers() if p.name in ("other-standalone", "manifestless", "broken-manifest")]
+ assert get_provider_profile("copilot-acp") is not None # bundled set still intact
diff --git a/website/docs/developer-guide/model-provider-plugin.md b/website/docs/developer-guide/model-provider-plugin.md
index 5127107fa31..df11914f3fe 100644
--- a/website/docs/developer-guide/model-provider-plugin.md
+++ b/website/docs/developer-guide/model-provider-plugin.md
@@ -18,7 +18,8 @@ Model provider plugins are the third kind of **provider plugin**. The others are
1. **Bundled plugins** — `<repo>/plugins/model-providers/<name>/` — ship with Hermes
2. **User plugins** — `$HERMES_HOME/plugins/model-providers/<name>/` — drop in any directory; no restart required for subsequent sessions
-3. **Legacy single-file** — `<repo>/providers/<name>.py` — back-compat for out-of-tree editable installs
+3. **Installed plugins** — `$HERMES_HOME/plugins/<name>/` (where `hermes plugins install owner/repo` clones) — imported only when `plugin.yaml` declares `kind: model-provider`; every other kind there belongs to the general PluginManager
+4. **Legacy single-file** — `<repo>/providers/<name>.py` — back-compat for out-of-tree editable installs
**User plugins override bundled plugins of the same name** because `register_provider()` is last-writer-wins. Drop a `$HERMES_HOME/plugins/model-providers/gmi/` directory to replace the built-in GMI profile without touching the repo.
@@ -141,8 +142,31 @@ class AcmeProfile(ProviderProfile):
Bearer auth. Override for: custom auth (Anthropic), no REST endpoint
(Bedrock → None), or public/unauthenticated catalogs (OpenRouter)."""
return super().fetch_models(api_key=api_key, base_url=base_url, timeout=timeout)
+
+ def create_client(self, **client_kwargs):
+ """Supply your own client object instead of the shared openai.OpenAI.
+ Default returns None (= use the standard client). Override when the
+ wire protocol is not OpenAI-over-HTTP — e.g. an ACP subprocess shim.
+ client_kwargs is what the core would have passed to openai.OpenAI
+ (api_key, base_url, command, args, timeouts, headers…); accept **kwargs
+ and pick what you need. A raise is logged and falls back to the
+ standard client."""
+ return None
```
+## External-process (ACP) providers
+
+An agent CLI driven over stdio is not an HTTP endpoint. Set `auth_type="external_process"`, describe how to launch the binary, and supply the client with `create_client`. No core edits are needed — `hermes -m <name>`, `/model`, credential resolution, runtime resolution and the auxiliary client (compression, vision) all key on `auth_type`, not on the provider name. `plugins/model-providers/copilot-acp/` is the in-tree example.
+
+| Field | Purpose |
+|---|---|
+| `process_command` | Default binary, e.g. `"copilot"` |
+| `process_args` | Default argv tail, e.g. `("--acp", "--stdio")` |
+| `process_command_env_vars` | Env vars that override the binary, checked in order |
+| `process_args_env_var` | Env var that overrides argv (shlex-split) |
+
+The client your `create_client` returns receives `command` and `args` in `client_kwargs`. If it is already complete and async-safe, declare `HERMES_SKIP_TRANSPORT_WRAP = True` / `HERMES_SKIP_ASYNC_WRAP = True` as class attributes so the auxiliary client does not re-dispatch it through an HTTP wire adapter.
+
## Hook reference examples
Look at these bundled plugins for idioms:
@@ -198,7 +222,7 @@ Set `profile.api_mode` to match the default your provider ships — it acts as a
| `oauth_external` | User signs in elsewhere, tokens land in `auth.json` | Anthropic OAuth, MiniMax OAuth, Qwen Portal, Nous Portal |
| `copilot` | GitHub Copilot token refresh cycle | `copilot` plugin only |
| `aws_sdk` | AWS SDK credential chain (IAM role, profile, env) | `bedrock` plugin only |
-| `external_process` | Auth handled by a subprocess the agent spawns | `copilot-acp` plugin only |
+| `external_process` | Auth handled by a subprocess the agent spawns (see [External-process providers](#external-process-acp-providers)) | `copilot-acp` plugin, out-of-tree ACP plugins |
`auth_type` gates which codepaths treat your provider as a "simple api-key provider" — if it's not `api_key`, the PluginManager still records the manifest but Hermes' CLI-level automation (doctor checks, `--provider` flag, setup wizard delegation) may skip over it.