Skip to content

Commit 17ef6bd

Browse files
floodsungFlood Sung
andauthored
docs: document /goal loops and Agent Teams (#276)
* feat(installer): allow custom install directory via --dir / -Dir flag install.sh and install.ps1 previously hardcoded the install path to $HOME/metabot. Add a CLI flag (and matching PowerShell parameter) plus an interactive prompt so users can install MetaBot anywhere. - Priority: --dir / -Dir > METABOT_HOME env var > prompt > default. - Tilde expansion + absolute-path validation; refuses to clobber $HOME / system roots. - Persists METABOT_HOME to ~/.bashrc / ~/.zshrc (Linux/macOS) or user-level env (Windows) when non-default, so the mm/mb/metabot CLIs can locate the install in new shells. * fix(codex): show model metadata in cards * fix(codex): mirror skills and avoid bwrap sandbox * fix(codex): tolerate agents deployment failures * fix(codex): install bundled skills when user cache is empty * docs: explain Codex skill migration * docs: document /goal loops and Agent Teams - README_EN.md / README.md: add Core Components rows for Persistent Sessions & Goal Loops and Agent Teams, new Example Prompts sections, and /goal row in the Chat Commands table. - docs/features/goal-loops.{md,zh.md}: new feature page covering Claude-native Stop hook + fast-model evaluator and MetaBot's persistent-executor role. - docs/features/agent-teams.{md,zh.md}: new feature page describing the runtime team experience; honest about current Team-panel limitations (SDK hooks not firing yet, activity surfaces in the agent activity card). - docs/usage/chat-commands.{md,zh.md}: add /goal row with link to the new feature page. - mkdocs.yml: add both pages to the en and zh nav blocks under Features, adjacent to MetaSkill. --------- Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
1 parent 2acf106 commit 17ef6bd

9 files changed

Lines changed: 257 additions & 0 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ MetaBot 支持 4 种方式与你的 Agent 团队交互:
175175
| 组件 | 一句话说明 |
176176
|------|-----------|
177177
| **三引擎内核** | 每个 Bot 独立选 Claude Code / Kimi Code / Codex CLI — 完整工具链(Read/Write/Edit/Bash/Glob/Grep/WebSearch/MCP),自主模式运行 |
178+
| **常驻会话与目标循环** | 每个会话一个常驻 Claude 进程 — `/goal` 让 Agent 在多轮之间持续自驱直到目标达成;团队成员和后台任务跨轮存活 |
179+
| **Agent 团队(运行时)** | 主导 Agent 并行派遣专家队友,互相路由任务、汇总结果 —— 全部在一个飞书会话中完成 |
178180
| **CC 原生调度** | 直接用 Claude Code 内置的 `CronCreate` / `/loop` —— 即开即用,会话内最简单 |
179181
| **MetaMemory** | 内嵌 SQLite 知识库,全文搜索,Web UI,变更自动同步到飞书知识库 |
180182
| **IM Bridge** | 飞书、Telegram、微信(含手机端)对话任意 Agent,流式卡片 + 工具调用追踪 |
@@ -241,6 +243,21 @@ MetaBot 支持 4 种方式与你的 Agent 团队交互:
241243
> `cp src/skills/metaschedule/SKILL.md ~/.claude/skills/metaschedule/`),
242244
> 就能用 `mb schedule cron` / HTTP API 提交到 MetaBot 服务端调度器。
243245
246+
### Agent 团队 — 运行时协作
247+
248+
```
249+
你来当主导工程师。并行派出一个前端专家和一个后端专家:
250+
前端负责 React UI 改造,后端加上新的 /api/reports 接口,
251+
你负责 review 两边的 PR,全部通过后再合并。
252+
```
253+
254+
### 目标循环
255+
256+
```
257+
/goal PR #123 的 CI 全绿、部署成功。
258+
每 10 分钟检查一次,搞定后告诉我。
259+
```
260+
244261
### MetaSkill — Agent 工厂(可选)
245262

246263
`/metaskill` 默认不装。先启用:`cp -r src/skills/metaskill ~/.claude/skills/`,然后:
@@ -406,6 +423,7 @@ MetaBot 以 `bypassPermissions` 模式运行 Claude Code — 无交互式确认
406423
| `/reset` | 清除会话 |
407424
| `/stop` | 中止当前任务 |
408425
| `/status` | 查看会话状态(含当前模型) |
426+
| `/goal <条件>` | 设置目标,Agent 跨多轮持续推进直到达成。`/goal clear` 停止 |
409427
| `/model` | 查看当前模型;`/model list` 查看可用模型;`/model <name>` 切换;`/model reset` 恢复默认 |
410428
| `/memory list` | 浏览知识库目录 |
411429
| `/memory search 关键词` | 搜索知识库 |

README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ Full-featured browser-based chat interface. Access at `https://your-server/web/`
171171
| Component | Description |
172172
|-----------|-------------|
173173
| **Triple Engine Kernel** | Each bot independently chooses Claude Code / Kimi Code / Codex CLI — full tool stack (Read/Write/Edit/Bash/Glob/Grep/WebSearch/MCP) in autonomous mode |
174+
| **Persistent Sessions & Goal Loops** | One Claude process per chat — `/goal` keeps the agent auto-driving across turns until a condition is met; teammates and background tasks survive between turns |
175+
| **Agent Teams** | A lead agent spawns specialist teammates in parallel, routes tasks between them, and aggregates results — all in one Feishu chat |
174176
| **CC-Native Scheduling** | Use Claude Code's built-in `CronCreate` and `/loop` directly — zero MetaBot setup, runs in-session |
175177
| **MetaMemory** | Embedded SQLite knowledge store with full-text search, Web UI, auto-syncs to Feishu Wiki |
176178
| **IM Bridge** | Chat with any agent from Feishu, Telegram, or WeChat (including mobile). Streaming cards + tool call tracking |
@@ -240,6 +242,21 @@ summarize the top 5 stories, and save the summary to MetaMemory.
240242
> then use `mb schedule cron` / the HTTP API to submit jobs to MetaBot's
241243
> persistent scheduler.
242244
245+
### Agent Teams — Runtime
246+
247+
```
248+
Act as a lead engineer. Spawn a frontend specialist and a backend specialist
249+
in parallel: the frontend handles the React UI changes, the backend adds the
250+
new /api/reports endpoint, and you review both PRs before merging.
251+
```
252+
253+
### Goal Loops
254+
255+
```
256+
/goal The CI for PR #123 is green and the deploy completes successfully.
257+
Check every 10 minutes and report back when done.
258+
```
259+
243260
### MetaSkill — Agent Factory (opt-in)
244261

245262
`/metaskill` is not installed by default. Enable it first:
@@ -409,6 +426,7 @@ MetaBot runs Claude Code in `bypassPermissions` mode — no interactive approval
409426
| `/reset` | Clear session |
410427
| `/stop` | Abort current task |
411428
| `/status` | Session info (includes current model) |
429+
| `/goal <condition>` | Set a goal the agent keeps pursuing across turns. `/goal clear` to stop |
412430
| `/model` | Show current engine/model; `/model list` — available engines/models; `/model claude`, `/model kimi`, or `/model codex` — switch engine; `/model <name>` — set model; `/model reset` — restore default |
413431
| `/memory list` | Browse knowledge tree |
414432
| `/memory search <query>` | Search knowledge base |

docs/features/agent-teams.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Agent Teams
2+
3+
A lead agent spawns specialist teammates in parallel, routes tasks between them, and aggregates results — all inside a single Feishu chat.
4+
5+
## What It Does
6+
7+
Agent Teams is the **runtime** team experience inside a single chat session:
8+
9+
- A **lead agent** receives your request and decides what specialists are needed.
10+
- The lead spawns **teammates** (frontend, backend, reviewer, …) via the `Agent` tool. Teammates run as separate sub-agents under the same chat process.
11+
- Teammates can be addressed across turns: the lead routes tasks via `SendMessage`, asks teammates to report back, and aggregates the results.
12+
- Everything happens in one Feishu chat — you talk to the lead, the lead talks to the team.
13+
14+
This is the runtime counterpart to [MetaSkill](metaskill.md): MetaSkill *generates* an agent team configuration (CLAUDE.md / AGENTS.md + skills), while Agent Teams *runs* it.
15+
16+
## Usage
17+
18+
Prompt the lead agent to spawn teammates. You don't need a special command — just describe the team and the work:
19+
20+
```
21+
Act as a lead engineer. Spawn a frontend specialist and a backend specialist
22+
in parallel: the frontend handles the React UI changes, the backend adds the
23+
new /api/reports endpoint, and you review both PRs before merging.
24+
```
25+
26+
```
27+
Spawn a researcher and a writer teammate. The researcher gathers everything
28+
we have on competitor X's pricing strategy from MetaMemory and the web.
29+
The writer turns it into a one-pager. Hand off when done.
30+
```
31+
32+
If your bot already has a generated team (via `/metaskill`), the orchestrator agent in that team is your lead — just describe the goal.
33+
34+
## How It Works
35+
36+
- **Persistent process per chat.** Teammates spawned in turn 1 are still addressable in turn N hours later, because each chat has one long-lived Claude process (see [How it works in CLAUDE.md](https://github.com/xvirobotics/metabot/blob/main/CLAUDE.md#persistent-claude-process-per-chat-stage-4--opt-in)). Without this, every turn would spawn a fresh subprocess and tear down all teammates.
37+
- **Agent tool spawns teammates.** The lead uses Claude's native `Agent` tool with a `team_name=` parameter to start a teammate. Teammates inherit the same working directory and tools.
38+
- **Cross-agent messaging.** Teammates and the lead use `SendMessage` to exchange messages. Replies are queued and delivered when the recipient is ready.
39+
- **Background activity surfacing.** Teammate progress between user turns shows up as a coalesced "Agent activity" card in Feishu (30-second debounce, so you don't get spammed during fast back-and-forth).
40+
41+
## Current Limitations
42+
43+
- **Team panel UX is coming soon.** A dedicated `🧑‍🤝‍🧑 Team` panel showing each teammate with a working/idle status icon and a shared task list is implemented in the card renderer, but the upstream SDK hooks that populate it (`TaskCreated` / `TaskCompleted` / `TeammateIdle`) do not fire reliably yet. Today, teammate activity surfaces in the existing **agent activity card** during the run.
44+
- **Claude engine only.** Teammate spawning relies on Claude's native `Agent` tool. Kimi and Codex bots don't support Agent Teams yet.
45+
- **One lead per chat.** The chat session has one process, so one lead agent. Use separate Feishu chats (or [peers](peers.md)) to run multiple independent teams.
46+
- **Budget is shared.** All teammates run inside the same chat's token budget. Heavy parallel work counts against `maxBudgetUsd`.
47+
48+
## See Also
49+
50+
- [MetaSkill](metaskill.md) — generate a team configuration before running it
51+
- [Goal Loops](goal-loops.md) — give the team a multi-turn objective
52+
- [Peers](peers.md) — run teams on separate MetaBot instances and route between them

docs/features/agent-teams.zh.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Agent 团队
2+
3+
主导 Agent 并行派遣专家队友,互相路由任务、汇总结果 —— 全部在一个飞书会话中完成。
4+
5+
## 功能
6+
7+
Agent 团队是单个会话内的**运行时**团队体验:
8+
9+
- **主导 Agent**接到你的需求,决定需要哪些专家。
10+
- 主导 Agent 通过 `Agent` 工具派遣**队友**(前端、后端、Reviewer 等)。队友以子 Agent 形式运行在同一个会话进程下。
11+
- 队友跨多轮可寻址:主导 Agent 用 `SendMessage` 路由任务、请队友汇报,并汇总结果。
12+
- 所有交互都在一个飞书会话中 —— 你和主导 Agent 对话,主导 Agent 协调团队。
13+
14+
这是 [MetaSkill](metaskill.md) 的运行时对应:MetaSkill *生成* Agent 团队的配置(CLAUDE.md / AGENTS.md + skills),Agent 团队负责*运行*它。
15+
16+
## 用法
17+
18+
让主导 Agent 派出队友即可,不需要特殊命令 —— 把团队和工作描述出来:
19+
20+
```
21+
你来当主导工程师。并行派出一个前端专家和一个后端专家:
22+
前端负责 React UI 改造,后端加上新的 /api/reports 接口,
23+
你负责 review 两边的 PR,全部通过后再合并。
24+
```
25+
26+
```
27+
派出一个研究员和一个写手队友。研究员从 MetaMemory 和网络
28+
收集竞品 X 的定价策略;写手整理成一页纸。完成后交付。
29+
```
30+
31+
如果你的 Bot 已经通过 `/metaskill` 生成了团队,里面的 orchestrator 就是主导 Agent —— 直接描述目标即可。
32+
33+
## 工作原理
34+
35+
- **每个会话一个常驻进程。**第 1 轮派出的队友,几小时后第 N 轮仍可寻址。原因是每个会话有一个长生命周期的 Claude 进程(见 [CLAUDE.md 中的说明](https://github.com/xvirobotics/metabot/blob/main/CLAUDE.md#persistent-claude-process-per-chat-stage-4--opt-in))。如果没有这个机制,每轮都重新启动子进程,所有队友会被销毁。
36+
- **Agent 工具派遣队友。**主导 Agent 用 Claude 原生的 `Agent` 工具加 `team_name=` 参数派出队友。队友继承同样的工作目录和工具集。
37+
- **跨 Agent 消息。**队友和主导 Agent 通过 `SendMessage` 交换消息。回复会排队,接收方就绪后投递。
38+
- **后台活动展示。**用户轮之间的队友进度,会在飞书以合并后的"Agent activity"卡片呈现(30 秒去抖,避免快速交互时刷屏)。
39+
40+
## 当前限制
41+
42+
- **专属团队面板即将上线。**专门的 `🧑‍🤝‍🧑 Team` 面板(队友列表带忙/闲图标 + 共享任务列表)渲染逻辑已经写好,但上游 SDK 的 hooks(`TaskCreated` / `TaskCompleted` / `TeammateIdle`)目前还不稳定触发。当前队友活动展示在运行期的**Agent activity 卡片**中。
43+
- **仅 Claude 引擎。**队友派遣依赖 Claude 原生 `Agent` 工具,Kimi 和 Codex Bot 暂不支持 Agent 团队。
44+
- **每个会话一个主导 Agent。**单会话单进程,只能有一个主导 Agent。需要并行运行多个独立团队时,用不同的飞书会话(或 [peers](peers.md))。
45+
- **预算共享。**所有队友共享同一个会话的 token 预算,重并行任务会快速计入 `maxBudgetUsd`
46+
47+
## 相关
48+
49+
- [MetaSkill](metaskill.md) — 先用它生成团队配置,再运行
50+
- [目标循环](goal-loops.md) — 给团队一个跨多轮的目标
51+
- [Peers 联邦](peers.md) — 把团队跑在不同 MetaBot 实例上,跨实例路由

docs/features/goal-loops.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Goal Loops
2+
3+
Set a goal condition; MetaBot keeps Claude working across turns until the goal is met.
4+
5+
## What It Does
6+
7+
`/goal` lets you hand Claude an objective rather than a single instruction. The agent keeps pursuing the goal across **multiple turns** — checking, retrying, waiting on external state — and reports back when the condition is satisfied (or when you tell it to stop).
8+
9+
The Feishu card shows a persistent `🎯 Goal: <condition>` badge across turns, so you always know what the agent is chasing.
10+
11+
## Usage
12+
13+
Send `/goal` followed by the condition you want satisfied:
14+
15+
```
16+
/goal The CI for PR #123 is green and the deploy completes successfully.
17+
Check every 10 minutes and report back when done.
18+
```
19+
20+
```
21+
/goal All open Linear tickets in the INGEST project are either resolved
22+
or assigned to a human. Recheck every 30 minutes.
23+
```
24+
25+
Other forms:
26+
27+
| Command | Effect |
28+
|---------|--------|
29+
| `/goal <condition>` | Set or replace the active goal |
30+
| `/goal` | Query the current goal (no mutation) |
31+
| `/goal clear` (or `stop` / `off` / `reset` / `none` / `cancel`) | Clear the active goal |
32+
33+
## How It Works
34+
35+
`/goal` is a **Claude Code native command** — the loop machinery lives inside Claude Code itself:
36+
37+
1. Claude registers a session-scoped **Stop hook** when the goal is set.
38+
2. When a turn finishes, the Stop hook runs a fast-model evaluator against the goal condition.
39+
3. If the goal is **not yet met**, the evaluator queues another turn automatically. If it **is** met, the loop ends and Claude reports the result.
40+
41+
MetaBot's contribution is the runtime that makes this work over Feishu:
42+
43+
- The **persistent Claude process per chat** (one long-lived SDK session per `chatId`) is what keeps the Stop hook alive between user turns. Without it, every turn spawned a fresh subprocess and killed any in-flight hooks. This runs by default — no configuration needed.
44+
- The Feishu card mirrors the goal condition into a persistent badge so the user can see what's being pursued.
45+
46+
## Limits
47+
48+
- Auto-driven turns count toward the bot's token budget (`maxBudgetUsd`) and turn limit (`maxTurns`) just like manual turns.
49+
- One active goal per chat session. Setting a new goal replaces the previous one.
50+
- Use `/stop` to abort the current turn; use `/goal clear` to stop the loop entirely.
51+
- Goals are scoped to a single chat (`chatId`); they don't persist after `/reset`.
52+
53+
## See Also
54+
55+
- [Agent Teams](agent-teams.md) — combine a goal with parallel teammates
56+
- [Chat Commands](../usage/chat-commands.md) — full command reference

docs/features/goal-loops.zh.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# 目标循环(Goal Loops)
2+
3+
设一个目标,MetaBot 让 Claude 跨多轮持续推进,直到目标达成。
4+
5+
## 功能
6+
7+
`/goal` 让你把"目标"交给 Claude,而不是单条指令。Agent 会**跨多轮**自动驱动:检查、重试、等待外部状态,达成条件时回来汇报(或者你主动叫停)。
8+
9+
飞书卡片会在多轮之间持续显示 `🎯 Goal: <condition>` 徽标,你随时知道 Agent 在追什么。
10+
11+
## 用法
12+
13+
`/goal` 加目标条件:
14+
15+
```
16+
/goal PR #123 的 CI 全绿、部署成功。
17+
每 10 分钟检查一次,搞定后告诉我。
18+
```
19+
20+
```
21+
/goal Linear INGEST 项目下所有 open ticket 都已解决或分派给人。
22+
每 30 分钟复查一次。
23+
```
24+
25+
其他形式:
26+
27+
| 命令 | 效果 |
28+
|------|------|
29+
| `/goal <条件>` | 设置或替换当前目标 |
30+
| `/goal` | 查询当前目标(不修改) |
31+
| `/goal clear`(或 `stop` / `off` / `reset` / `none` / `cancel`| 清除当前目标 |
32+
33+
## 工作原理
34+
35+
`/goal`**Claude Code 原生命令**,循环机制本身跑在 Claude Code 内部:
36+
37+
1. 设置目标时,Claude 注册一个会话级 **Stop hook**
38+
2. 每轮结束时,Stop hook 调用快速模型评估目标是否达成。
39+
3. **未达成**则自动排队下一轮;**已达成**则结束循环并汇报结果。
40+
41+
MetaBot 的贡献是让这套机制能跨飞书消息工作:
42+
43+
- **每个会话一个常驻 Claude 进程**(一个长生命周期的 SDK 会话 per `chatId`),这是 Stop hook 跨用户轮存活的前提。没有它的话,每轮都重新启动子进程,hook 会被杀掉。该机制默认开启,无需配置。
44+
- 飞书卡片把目标条件镜像成持久徽标,让用户看到 Agent 在追什么。
45+
46+
## 限制
47+
48+
- 自动驱动的轮次和手动轮次一样,计入 Bot 的 token 预算(`maxBudgetUsd`)和轮次上限(`maxTurns`)。
49+
- 每个会话只能有一个活跃目标。再次设置会替换原目标。
50+
- `/stop` 中止当前轮次;`/goal clear` 完全停止循环。
51+
- 目标作用域是单个会话(`chatId`),`/reset` 后不保留。
52+
53+
## 相关
54+
55+
- [Agent 团队](agent-teams.md) — 把目标和并行队友组合使用
56+
- [聊天命令](../usage/chat-commands.md) — 完整命令参考

docs/usage/chat-commands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Commands you can send to MetaBot in Feishu or Telegram.
99
| `/reset` | Clear session — starts a fresh conversation |
1010
| `/stop` | Abort the currently running task |
1111
| `/status` | Show session info (session ID, working directory) |
12+
| `/goal <condition>` | Set a goal the agent keeps pursuing across turns. `/goal clear` to stop. See [Goal Loops](../features/goal-loops.md) |
1213
| `/memory list` | Browse MetaMemory knowledge tree |
1314
| `/memory search <query>` | Search MetaMemory knowledge base |
1415
| `/sync` | Trigger MetaMemory → Feishu Wiki sync |

docs/usage/chat-commands.zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
| `/reset` | 清除会话 — 开始全新对话 |
1010
| `/stop` | 中止当前任务 |
1111
| `/status` | 查看会话信息(会话 ID、工作目录) |
12+
| `/goal <条件>` | 设置目标,Agent 跨多轮持续推进直到达成。`/goal clear` 停止。参见 [目标循环](../features/goal-loops.md) |
1213
| `/memory list` | 浏览 MetaMemory 知识库目录 |
1314
| `/memory search 关键词` | 搜索 MetaMemory 知识库 |
1415
| `/sync` | 触发 MetaMemory → 飞书知识库同步 |

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ plugins:
7373
- 安全: concepts/security.md
7474
- 功能:
7575
- MetaSkill: features/metaskill.md
76+
- 目标循环: features/goal-loops.md
77+
- Agent 团队: features/agent-teams.md
7678
- MetaMemory: features/metamemory.md
7779
- Web UI: features/web-ui.md
7880
- Peers 联邦: features/peers.md
@@ -125,6 +127,8 @@ nav:
125127
- Security: concepts/security.md
126128
- Features:
127129
- MetaSkill: features/metaskill.md
130+
- Goal Loops: features/goal-loops.md
131+
- Agent Teams: features/agent-teams.md
128132
- MetaMemory: features/metamemory.md
129133
- Web UI: features/web-ui.md
130134
- Peers Federation: features/peers.md

0 commit comments

Comments
 (0)