Skip to content
Open
1 change: 1 addition & 0 deletions HUB.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ JSON request keys match the corresponding MCP tool arguments.
|---|---|---|
| GET | `/v1/health` | readiness |
| GET | `/v1/agents` | list_agents |
| GET | `/v1/agents/{agent}/models?cwd=/abs/project&refresh=false` | list_models (admin API only; not on the remote gateway) |
| PUT | `/v1/preferences` | set_preferences: mode, instructions |
| POST | `/v1/tasks` | dispatch_task: agent, message, cwd; optional session_id, model, effort, title, user_requested, request_id |
| GET | `/v1/tasks/{id}` | check_task |
Expand Down
3 changes: 2 additions & 1 deletion HUB.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ message / Cursor follow-up run 发送结果;交付 turn 不增加深度、不
`agent-bridge approvals list`,再 `approve 审批ID` 或 `deny 审批ID`。
审批随 token 过期,重启丢弃。管理端(远程网关不开放)REST:GET `/v1/approvals`、
POST `/v1/approvals/{id}/approve` 或 `/deny`、GET `/v1/remote`、
PUT `/v1/remote/public-url`(JSON public_url 字段)。
PUT `/v1/remote/public-url`(JSON public_url 字段)、
GET `/v1/agents/{agent}/models?cwd=绝对项目路径&refresh=false`(list_models,仅本机管理端)。

`agent-bridge ui` 一次性登录码有效60秒,传给浏览器时可能短暂出现在进程参数中;
`--no-open` 改为输出敏感链接,请勿保存/分享。链接不包含管理 bearer。
Expand Down
4 changes: 3 additions & 1 deletion ORCHESTRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Call `list_agents` first and re-read `coordinator` before every dispatch.

When the user states a **lasting** preference, persist it with `set_preferences`. Its `instructions` argument replaces the stored text — read the current value first and write the merge. One-off wishes are not preferences.

Workers are reached **only** through Agent Bridge MCP tools (`list_agents`, `dispatch_task`, `wait_task`, `check_task`, `get_result`, `get_transcript`, `cancel_task`, `list_sessions`, `end_session`). If those tools are missing, stop and say so. Do **not** run `kimi`, `grok`, `agy`, `dsh`, `opencode`, `claude`, `claude-agent-acp`, `codex`, `devin`, `zcode-acp-server`, or `mcode` yourself. `git` / `pytest` after a turn is review, not a substitute for dispatch.
Workers are reached **only** through Agent Bridge MCP tools (`list_agents`, `list_models`, `dispatch_task`, `wait_task`, `check_task`, `get_result`, `get_transcript`, `cancel_task`, `list_sessions`, `end_session`). If those tools are missing, stop and say so. Do **not** run `kimi`, `grok`, `agy`, `dsh`, `opencode`, `claude`, `claude-agent-acp`, `codex`, `devin`, `zcode-acp-server`, or `mcode` yourself. `git` / `pytest` after a turn is review, not a substitute for dispatch.

## Step 1 — dispatch, or do it yourself?

Expand Down Expand Up @@ -49,6 +49,8 @@ In `auto`/`eager`, tell the user after the fact. In `manual`, their explicit req

## How to dispatch

When `dispatch_enabled=true`, use supported workers' `list_models(agent,cwd)` before choosing a model. See SETUP.md for usage details.

1. `list_agents`. Read `coordinator.mode` / `instructions` / `dispatch_enabled` and `env.proxy` / `env.warnings`. A null proxy on a direct network is normal; if a worker fails with connect errors on a proxied machine, fix `[env.proxy]` instead of retrying.
2. `dispatch_task` with `cwd` = **this conversation's project folder** (absolute). Never the Agent Bridge install path (unless the user is editing Bridge). Never a temp dir. The `message` must be self-contained: background, absolute paths, acceptance criteria, things not to do. Leave `model`/`effort` unset unless you have a reason.
- Antigravity: `agy models` slugs; default `gemini-3.7-flash`.
Expand Down
4 changes: 4 additions & 0 deletions ORCHESTRATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ ACP 失败保留字符串 `error`,并可附带 `failure`。`failure.prompt_may
需要重试去重时,在首次调用 `dispatch_task` 前生成 UUID `request_id`,首次调用就传入。重试须使用同一 ID 和原始参数;首次省略了 `session_id`,重试也保持省略。只在重试时补 ID 无法对首次调用去重。相同参数复用原任务(`reused=true`),不同参数直接拒绝。去重只在同一 Bridge 实例内、原任务仍保留时有效,仍须通过正常派发校验。重启 Bridge、切换实例或清理原任务后不再保留绑定;Worker 的外部副作用不保证 exactly-once。

对另一个 Bridge 实例拥有的任务,`check_task` / `get_result` 从 `state.json` 作答——带 `from_state: true`、`silent_for_sec: null`;`wait_task` / `cancel_task` 仍须由拥有它的实例调用。

## 按需查询模型目录

当 `dispatch_enabled=true` 时,选择模型前调用支持此功能的 worker 的 `list_models(agent,cwd)`;字段、缓存、effort 映射和会话行为见 SETUP.md。
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Close coordinators that are holding Bridge, then `agent-bridge upgrade`, then re
| Tool | Role |
| --- | --- |
| `list_agents` | Probe workers, report remaining quota, proxy/env + coordinator policy |
| `list_models` | Discover advertised models for one worker/project, with cached results |
| `set_preferences` | Persist coordinator mode / routing preferences |
| `dispatch_task` | Start or resume a turn in the project `cwd` |
| `invoke_agent` | Call a worker until done, with MCP progress (optional timeout) |
Expand All @@ -148,6 +149,13 @@ Close coordinators that are holding Bridge, then `agent-bridge upgrade`, then re
| `list_sessions` | Known sessions |
| `end_session` | Shut down a worker process |

Call `list_models(agent="kimi", cwd="/absolute/project")` to discover a worker's
advertised models before choosing one. Supported workers are Kimi, DSH,
Claude Code, Antigravity, and Codex; check `list_agents.model_discovery` for support.
Results are cached per worker/project for one hour by default. Use
`refresh=true` for an immediate update. See [Model discovery](SETUP.md#model-discovery)
for result fields, configuration, and session behavior.

`get_result` returns up to 60,000 characters per call. Continue with
`next_cursor` while `has_more` is true. Detailed work events remain available
through `get_transcript` and `~/.agent-bridge/transcripts/`; sparse task
Expand Down
53 changes: 53 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,59 @@ uv run --no-sync python scripts/setup_lab.py

If a worker is missing, `list_agents` reports `available: false` and the coordinator should pick another worker or do the work itself.

### Model discovery

`list_agents` includes a `model_discovery` capability block. Query a supported
worker on demand, using this conversation's absolute project directory:

```text
list_models(agent="kimi", cwd="/absolute/project")
list_models(agent="antigravity", cwd="/absolute/project", refresh=true)
```

Supported workers and catalog sources:

| Worker | Source |
| --- | --- |
| Kimi, DSH, Claude Code | ACP `initialize` / `session/new` |
| Antigravity | `agy models` |
| Codex | app-server `model/list`, using app-server configuration and the worker's `config_overrides` |

Discovery uses a separate worker process, closed after the lookup. ACP discovery
denies permission requests and may leave an empty session in worker history.
`list_models` is available when `coordinator.dispatch_enabled=true`. With a
running hub, MCP clients forward it to the hub's loopback admin API
(`GET /v1/agents/{agent}/models`), so every coordinator shares one cache; the
remote gateway does not expose it.

Result fields:

| Field | Meaning |
| --- | --- |
| `models` | Advertised choices with `id`, `name`, `is_default`, and `supported_efforts` |
| `default_model` | Default model ID reported by the query session; `null` when unknown |
| `supported_efforts` | Worker-native effort levels for a model; `null` means unknown, `[]` means explicitly no levels |
| `source` | Worker interface used for discovery |
| `agent`, `cwd` | Worker name and resolved project directory |
| `fetched_at`, `cached` | Fetch timestamp and whether this response came from cache |
| `availability="advertised"`, `invocation_verified=false` | Results describe the worker's catalog; successful model invocation is a separate check |
| `effort_vocabulary="worker_native"` | Effort names use the worker's vocabulary |
| `warnings` | Discovery diagnostics |

For dispatch, pass `off|low|medium|high|max` to `dispatch_task.effort`;
the adapter maps that value to the worker's effort settings.

```toml
[models]
cache_sec = 3600 # one hour; 0 disables reuse
timeout_sec = 30 # complete lookup deadline, including worker initialization
```

The cache is per worker and project, in memory for this Bridge instance.
Expired entries are refreshed on the next query. Use `refresh=true` after
changing accounts, worker configuration, or model access. A failed refresh
returns an error and preserves the last successful cache entry.

The coordinator can pin a worker model and thinking intensity on `dispatch_task`:

```text
Expand Down
5 changes: 5 additions & 0 deletions agents.toml
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,8 @@ command = ["codex"]
# session_meta = { yolo = true }
revivable = true
idle_unload_sec = 0

# On-demand worker model catalogs.
[models]
cache_sec = 3600
timeout_sec = 30
80 changes: 80 additions & 0 deletions scripts/smoke_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""Smoke-test list_models through an isolated MCP server.

uv run python scripts/smoke_models.py --cwd /absolute/project

Uses a temporary Bridge home under ignored lab/, preserving worker login homes.
ACP may leave empty discovery sessions in the worker's own history.
"""

from __future__ import annotations

import argparse
import asyncio
import json
import os
import shutil
import sys
import tempfile
from pathlib import Path
from typing import Any

from mcp.client.session import ClientSession
from mcp.client.stdio import StdioServerParameters, stdio_client

from agent_bridge.paths import bridge_home


def payload(result: Any) -> dict:
structured = result.structured_content
if isinstance(structured, dict):
return structured
for content in result.content:
if getattr(content, "type", None) == "text":
return json.loads(content.text)
raise RuntimeError("MCP result contained no JSON payload")


async def run(cwd: Path, agents: list[str], config_home: Path, output: Path | None) -> int:
lab = Path(__file__).resolve().parents[1] / "lab"
lab.mkdir(exist_ok=True)
results = {}
with tempfile.TemporaryDirectory(prefix="model-discovery-", dir=lab) as scratch:
overlay = config_home / "agents.toml"
if overlay.is_file():
shutil.copyfile(overlay, Path(scratch) / "agents.toml")
params = StdioServerParameters(
command=sys.executable,
args=["-c", "from agent_bridge.server import mcp; mcp.run(transport='stdio')"],
cwd=str(cwd),
env={**os.environ, "AGENT_BRIDGE_HOME": scratch, "AGENT_BRIDGE_PARENT_CONTEXT": ""},
)
async with stdio_client(params) as streams, ClientSession(*streams, read_timeout_seconds=120) as session:
await session.initialize()
listing = await session.list_tools()
assert "list_models" in {tool.name for tool in listing.tools}
for agent in agents:
args = {"agent": agent, "cwd": str(cwd)}
discovered = payload(await session.call_tool("list_models", args))
if discovered.get("ok"):
cached = payload(await session.call_tool("list_models", args))
assert cached.get("cached") is True
assert cached["models"] == discovered["models"]
results[agent] = discovered
print(json.dumps({"agent": agent, "ok": discovered.get("ok"),
"models": len(discovered.get("models", [])),
"error": discovered.get("error")}, ensure_ascii=False), flush=True)
sessions = payload(await session.call_tool("list_sessions", {}))
assert sessions["sessions"] == [], "Discovery registered a Bridge work session"
if output:
output.write_text(json.dumps(results, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
return 0 if all(result.get("ok") for result in results.values()) else 1


if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--cwd", type=Path, required=True)
parser.add_argument("--agents", nargs="+", default=["kimi", "dsh", "claude", "antigravity", "codex"])
parser.add_argument("--config-home", type=Path, default=bridge_home())
parser.add_argument("--output", type=Path)
args = parser.parse_args()
raise SystemExit(asyncio.run(run(args.cwd.resolve(), args.agents, args.config_home, args.output)))
6 changes: 5 additions & 1 deletion skills/agent-bridge/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Honor routing preferences and absolute cwd; never dispatch into your own session
Peer depth is limited by `[hub] max_depth` (default 3). Do not expose bearer tokens.
See HUB.md / HUB.zh-CN.md. 先运行 Hub,即可通过共享 API 调用同伴。

You are the coordinator: users talk only to you, and you call the workers. Workers are reached **only** through the Agent Bridge MCP tools (`list_agents`, `set_preferences`, `invoke_agent`, `dispatch_task`, `wait_task`, `check_task`, `get_result`, `get_transcript`, `cancel_task`, `list_sessions`, `end_session`). If those tools are missing from this session, stop and say so — never run `grok`, `kimi`, `agy`, `dsh`, `opencode`, `claude`, `claude-agent-acp`, `codex`, `devin`, `zcode-acp-server`, or `mcode` CLIs directly, and never drive their GUIs. The same product can be a coordinator and a worker; those are different processes.
You are the coordinator: users talk only to you, and you call the workers. Workers are reached **only** through the Agent Bridge MCP tools (`list_agents`, `list_models`, `set_preferences`, `invoke_agent`, `dispatch_task`, `wait_task`, `check_task`, `get_result`, `get_transcript`, `cancel_task`, `list_sessions`, `end_session`). If those tools are missing from this session, stop and say so — never run `grok`, `kimi`, `agy`, `dsh`, `opencode`, `claude`, `claude-agent-acp`, `codex`, `devin`, `zcode-acp-server`, or `mcode` CLIs directly, and never drive their GUIs. The same product can be a coordinator and a worker; those are different processes.

## Before anything: read the policy

Expand Down Expand Up @@ -48,6 +48,10 @@ Call `list_agents` first. Its result carries:

Claude `status`: shared `5h`/`weekly` only. Before dispatch, even if `ok`, check the target model's `weekly:opus`/`weekly:sonnet`: 0% is exhausted; missing/null unknown. Report reset time or a user-permitted alternative. Model-only data leaves shared status unknown.

## Model discovery

When `coordinator.dispatch_enabled=true` and `list_agents.model_discovery.supported=true`, use `list_models(agent=..., cwd=...)` to obtain worker-advertised model IDs before explicitly selecting a model. Supply this conversation's absolute project directory; use `refresh=true` after changing accounts or worker configuration. `supported_efforts` reports worker-native levels; pass `off|low|medium|high|max` to `dispatch_task.effort` for adapter mapping. See SETUP.md for result fields, caching, and session behavior.

## Step 1 — dispatch, or do it yourself?

A cost question, not a category question; "it is implementation work" is never by itself a reason to dispatch.
Expand Down
Loading
Loading