Files
ZQR1101 24e26b1b67 feat(subagent): speak ACP as a client so compliant agents plug in
Adds AcpBackend to the subagent registry: DeepTutor spawns an ACP-speaking
agent and drives initialize -> session/new|session/load -> session/prompt over
newline-delimited JSON-RPC, mapping session/update notifications onto the
existing text / reasoning / tool events. A new ACP-speaking agent then needs a
config line, not a connector.

Frames are pumped in bounded chunks rather than StreamReader.readline(), which
gives up on any line past 64 KiB and would truncate a whole tool result -- the
same limit process.py already works around for the native JSONL backends.
Elicitations are answered with `decline`, because approving a remote agent's
request for input is not this code's call to make.

Rebuilt on current dev; supersedes #1272.
2026-11-09 11:12:57 +08:00

90 lines
3.1 KiB
Python

"""Backend registry — the single place that knows which subagents exist.
Add a new subagent by writing a :class:`SubagentBackend` and listing it here;
the capability, API and UI all discover it through these helpers. Local-CLI
backends (Claude Code, Codex, Grok CLI, Antigravity CLI, Kimi CLI, opencode,
MiMo Code, Hermes Agent, OpenClaw, DeepSeek Harness, a configured ACP host),
configured remote backends, and the in-process partner backend live in the
same registry. ``local_cli`` and ``detectable`` control which backends
participate in connection discovery.
"""
from __future__ import annotations
import asyncio
from deeptutor.services.subagent.acp import AcpBackend
from deeptutor.services.subagent.antigravity import AntigravityBackend
from deeptutor.services.subagent.base import SubagentBackend
from deeptutor.services.subagent.claude_code import ClaudeCodeBackend
from deeptutor.services.subagent.codex import CodexBackend
from deeptutor.services.subagent.deepseek_harness import DeepSeekHarnessBackend
from deeptutor.services.subagent.grok import GrokBackend
from deeptutor.services.subagent.hermes import HermesBackend
from deeptutor.services.subagent.hermes_remote import HermesRemoteBackend
from deeptutor.services.subagent.kimi import KimiBackend
from deeptutor.services.subagent.openclaw import OpenClawBackend
from deeptutor.services.subagent.opencode_family import MimoBackend, OpencodeBackend
from deeptutor.services.subagent.types import DetectResult
_BACKENDS: dict[str, SubagentBackend] = {
backend.kind: backend
for backend in (
ClaudeCodeBackend(),
CodexBackend(),
GrokBackend(),
AntigravityBackend(),
KimiBackend(),
OpencodeBackend(),
MimoBackend(),
HermesBackend(),
HermesRemoteBackend(),
OpenClawBackend(),
DeepSeekHarnessBackend(),
AcpBackend(),
)
}
def list_backend_kinds() -> list[str]:
"""Return every connectable local, remote, and Partner backend kind."""
return list(_BACKENDS.keys())
def get_backend(kind: str) -> SubagentBackend | None:
return _BACKENDS.get(str(kind or "").strip())
def _detectable_backends() -> list[SubagentBackend]:
return [
backend
for backend in _BACKENDS.values()
if getattr(backend, "local_cli", True) or getattr(backend, "detectable", False)
]
async def detect_all() -> list[DetectResult]:
"""Probe local CLIs and configured remote backends."""
backends = _detectable_backends()
results = await asyncio.gather(
*(backend.detect() for backend in backends),
return_exceptions=True,
)
detections: list[DetectResult] = []
for backend, result in zip(backends, results, strict=True):
if isinstance(result, DetectResult):
detections.append(result)
else:
detections.append(
DetectResult(
kind=backend.kind,
display_name=backend.display_name,
available=False,
detail=str(result),
)
)
return detections
__all__ = ["list_backend_kinds", "get_backend", "detect_all"]