Skip to content

The agent that grows with you

fix(providers): allow external-process plugins to opt into streaming

Robert Borkowski81a55437f3f3
diff --git a/agent/turn_api_call.py b/agent/turn_api_call.py
index ef08530846f..196e9dbf724 100644
--- a/agent/turn_api_call.py
+++ b/agent/turn_api_call.py
@@ -44,16 +44,21 @@ class ApiCallVerdict:
def _should_stream(agent: Any) -> bool:
- """Streaming is preferred even without consumers (stale-stream / read-timeout health
- checks); disabled on provider signal, ACP providers (``acp://`` scheme or an
- external-process provider profile), MoA without a display consumer, or Mock clients in
- tests (SimpleNamespace, not stream iterators)."""
+ """Prefer streaming for liveness even without display consumers. Process providers
+ must opt in; ACP transports and explicit session/provider disables stay non-streaming."""
if getattr(agent, "_disable_streaming", False):
return False
_base = str(agent.base_url or "").lower()
+ if _base.startswith(("acp://", "acp+tcp://")):
+ return False
+ from providers import get_provider_profile
from hermes_cli.runtime_provider_backends import _is_external_process_provider
- if _base.startswith(("acp://", "acp+tcp://")) or _is_external_process_provider(agent.provider):
+ profile = get_provider_profile(agent.provider)
+ streaming = getattr(profile, "supports_streaming", None)
+ if streaming is False:
+ return False
+ if _is_external_process_provider(agent.provider) and streaming is not True:
return False
if not agent._has_stream_consumers():
if agent.provider == "moa":
diff --git a/providers/base.py b/providers/base.py
index 9183cf3074e..5995a833a39 100644
--- a/providers/base.py
+++ b/providers/base.py
@@ -63,6 +63,9 @@ class ProviderProfile:
base_url: str = ""
models_url: str = "" # explicit models endpoint; falls back to {base_url}/models
auth_type: str = "api_key" # api_key|oauth_device_code|oauth_external|copilot|aws_sdk
+ # None preserves transport defaults (external-process clients default to non-streaming).
+ # True opts a streaming-capable process client in; False disables streaming for this provider.
+ supports_streaming: bool | None = field(default=None, kw_only=True)
supports_health_check: bool = True # False → doctor skips /models probe for this provider
# False → fetch_models returns None without a network call (catalog comes from an SDK/subprocess).
supports_model_listing: bool = True
diff --git a/tests/agent/test_external_process_streaming.py b/tests/agent/test_external_process_streaming.py
new file mode 100644
index 00000000000..64e2ad4687c
--- /dev/null
+++ b/tests/agent/test_external_process_streaming.py
@@ -0,0 +1,138 @@
+"""Streaming is a provider capability, not an authentication mechanism."""
+import threading
+from types import SimpleNamespace
+
+import pytest
+
+from agent.turn_api_call import _should_stream
+from providers.base import ProviderProfile
+
+
+def test_streaming_capability_preserves_positional_plugin_construction():
+ from dataclasses import dataclass, fields
+ from typing import Any
+
+ @dataclass
+ class PluginProfile(ProviderProfile):
+ plugin_option: str = "default"
+
+ # All pre-existing base and subclass fields retain their positional slots.
+ legacy_fields = [f for f in fields(PluginProfile) if f.name != "supports_streaming"]
+ values: list[Any] = [object() for _ in legacy_fields]
+ profile = PluginProfile(*values, supports_streaming=True)
+ for field, value in zip(legacy_fields, values):
+ assert getattr(profile, field.name) is value
+ assert profile.supports_streaming is True
+
+
[email protected]("auth,capability,url,disabled,consumers,expected", [
+ ("external_process", True, "process://fixture", False, True, True),
+ ("external_process", True, "process://fixture", False, False, True),
+ ("external_process", None, "process://fixture", False, True, False),
+ ("external_process", None, "https://proxy.invalid/v1", False, True, False),
+ ("external_process", False, "process://fixture", False, True, False),
+ ("external_process", True, "process://fixture", True, True, False),
+ ("external_process", True, "acp://fixture", False, True, False),
+ ("external_process", True, "acp+tcp://127.0.0.1:9000", False, True, False),
+ ("api_key", None, "https://provider.invalid/v1", False, True, True),
+ ("api_key", False, "https://provider.invalid/v1", False, True, False),
+])
+def test_external_process_can_opt_into_streaming(monkeypatch, auth, capability, url, disabled, consumers, expected):
+ profile = ProviderProfile(name="streaming-process", auth_type=auth, supports_streaming=capability)
+ monkeypatch.setattr("providers.get_provider_profile", lambda name: profile)
+ agent = SimpleNamespace(
+ provider=profile.name, base_url=url,
+ _disable_streaming=disabled, _has_stream_consumers=lambda: consumers,
+ )
+ assert _should_stream(agent) is expected
+
+
+def test_discovered_process_provider_delivers_progress_before_completion(tmp_path, monkeypatch):
+ """A buffered call deadlocks this handshake; the real streaming consumer releases it.
+
+ Load a process profile through the user-plugin registry in an isolated home,
+ then cross the normal dispatch and streaming accumulator with a fixture client.
+ Only native I/O is replaced, not routing, callbacks, accumulation or cleanup.
+ """
+ from hermes_constants import get_hermes_home
+ from providers import get_provider_profile
+ from run_agent import AIAgent
+ from agent.turn_api_call import perform_api_call
+
+ plugin = get_hermes_home() / "plugins" / "streaming-fixture"
+ plugin.mkdir(parents=True)
+ (plugin / "plugin.yaml").write_text(
+ "name: streaming-fixture\nkind: model-provider\nversion: 0.1.0\ndescription: test fixture\n")
+ (plugin / "__init__.py").write_text(
+ "from providers import register_provider\n"
+ "from providers.base import ProviderProfile\n"
+ "register_provider(ProviderProfile(name='streaming-fixture', "
+ "auth_type='external_process', base_url='process://fixture', supports_streaming=True))\n")
+ profile = get_provider_profile("streaming-fixture")
+ assert profile is not None
+ progress_seen = threading.Event()
+ closed = []
+ requests = []
+ carrier = [{"type": "streaming-fixture.native_assistant", "value": "fixture-signature"}]
+
+ def chunk(delta=None, finish=None, usage=None):
+ return SimpleNamespace(
+ model="fixture-model", usage=usage,
+ choices=[] if delta is None else [SimpleNamespace(
+ index=0, delta=SimpleNamespace(**delta), finish_reason=finish)],
+ )
+
+ def chunks():
+ yield chunk({"reasoning_content": "fixture reasoning"})
+ assert progress_seen.wait(5), "Host buffered progress until completion"
+ yield chunk({"tool_calls": [SimpleNamespace(
+ index=0, id="fixture-call", type="function",
+ function=SimpleNamespace(name="read_file", arguments='{"path":"fixture.txt"}'))],
+ "reasoning_details": carrier}, finish="tool_calls")
+ yield chunk(usage=SimpleNamespace(prompt_tokens=7, completion_tokens=3, total_tokens=10))
+
+ class FixtureClient:
+ HERMES_SKIP_TRANSPORT_WRAP = True
+ HERMES_SKIP_ASYNC_WRAP = True
+
+ def __init__(self):
+ self.chat = SimpleNamespace(completions=self)
+
+ def create(self, **kwargs):
+ requests.append(kwargs)
+ if kwargs.get("stream"):
+ return chunks()
+ # Mirror a process client buffering its native events until completion.
+ list(chunks())
+ raise AssertionError("Buffered path must not be selected")
+
+ def close(self):
+ closed.append(True)
+
+ monkeypatch.setattr(profile, "create_client", lambda **kwargs: FixtureClient())
+ agent = AIAgent(
+ provider=profile.name, model="fixture-model", api_key="fixture", base_url=profile.base_url,
+ enabled_toolsets=[], quiet_mode=True, skip_context_files=True, skip_memory=True,
+ save_trajectories=False,
+ )
+ agent.reasoning_callback = lambda text: progress_seen.set()
+ kwargs = {"model": agent.model, "messages": [{"role": "user", "content": "fixture"}]}
+ try:
+ verdict = perform_api_call(
+ agent, api_kwargs=kwargs, _original_api_kwargs=kwargs, _llm_middleware_trace=[],
+ _moa_prepared_request=None, _retry=SimpleNamespace(), thinking_spinner=None,
+ retry_count=0, api_call_count=0, api_request_id="fixture-request",
+ effective_task_id=None, turn_id="fixture-turn", interrupted=False,
+ )
+ assert verdict.action == "fallthrough"
+ response = verdict.response
+ assert requests[0]["stream"] is True
+ assert progress_seen.is_set()
+ assert response.choices[0].message.tool_calls[0].function.arguments == '{"path":"fixture.txt"}'
+ assert response.choices[0].message.reasoning_content == "fixture reasoning"
+ assert response.choices[0].message.reasoning_details == carrier
+ assert response.usage.completion_tokens == 3
+ assert response.choices[0].finish_reason == "tool_calls"
+ finally:
+ agent.close()
+ assert closed
diff --git a/website/docs/developer-guide/model-provider-plugin.md b/website/docs/developer-guide/model-provider-plugin.md
index df1fbda3fd6..9442cc979bc 100644
--- a/website/docs/developer-guide/model-provider-plugin.md
+++ b/website/docs/developer-guide/model-provider-plugin.md
@@ -103,6 +103,7 @@ Full definition in `providers/base.py`. The most useful ones:
| `env_vars` | `tuple[str, ...]` | API-key env vars in priority order; a final `*_BASE_URL` entry is used as the user base-URL override |
| `base_url` | str | Default inference endpoint |
| `models_url` | str | Explicit catalog URL (falls back to `{base_url}/models`) |
+| `supports_streaming` | `bool \| None` | `None` (default) preserves transport defaults; `True` opts streaming-capable `external_process` clients into host streaming; `False` disables provider streaming. ACP URLs and session-level streaming disables still take precedence. Only opt in when the client implements the selected API mode's streaming contract, including cancellation and cleanup. |
| `auth_type` | str | `api_key` \| `oauth_device_code` \| `oauth_external` \| `copilot` \| `aws_sdk` \| `external_process` |
| `auth_handler` | `Callable \| None` | Provider-owned `hermes auth add/status/logout/refresh <name>` — see [Provider-owned auth](#provider-owned-auth-auth_handler-refresh_credential) |
| `refresh_credential` | `Callable \| None` | Provider-owned rotation of a pooled OAuth row — same section |