Skip to content

AgentProc把任意 Agent CLI 接入任意消息平台

一个极简的进程级协议。不用 HTTP、不用 socket——只用 stdin 和 stdout。

5 分钟上手

① 安装 CLI

bash
npm install -g agentproc
bash
pipx install agentproc
bash
pip install agentproc

macOS 用户:找不到 pip/pipx

Homebrew 的 Python 默认不暴露 pip。可以跑 python3 -m ensurepip && python3 -m pip install --user pipx,或者直接用上面的 npm——反正 agentproc CLI 本来就是 npm 包,Node 是必需的。

验证可用:

bash
agentproc --version
# agentproc 0.14.0 (protocol 0.4)

② 浏览 hub

bash
agentproc hub list
#   claude-code   official    Connect the claude CLI (Anthropic) as an AgentProc agent
#   codex         official    Connect the codex CLI (OpenAI) as an AgentProc agent
#   gemini-cli    official    Connect the gemini CLI (Google) as an AgentProc agent
#   cursor        official    Connect the Cursor Agent CLI as an AgentProc agent
#   codebuddy     official    Connect the codebuddy CLI (Tencent) as an AgentProc agent
#   grok-build    community   Connect the grok CLI (xAI Grok Build) as an AgentProc agent
#   qwen-code     community   Connect the qwen CLI (Alibaba) as an AgentProc agent
#   kimi-code     community   Connect the kimi CLI (Moonshot AI) as an AgentProc agent
#   deepseek      community   Connect the deepseek TUI as an AgentProc agent
#   aider         community   Connect the aider CLI as an AgentProc agent
#   opencode      community   Connect the opencode CLI as an AgentProc agent
#   agy           community   Connect the agy CLI as an AgentProc agent
#   pi            community   Connect the pi CLI (earendil-works) as an AgentProc agent
#   recursive     community   Connect the recursive CLI (self-improving Rust agent) as an AgentProc agent
#   echo-agent    official    Minimal hello-world agent

Profile Hub 收录了主流 AI CLI 的开箱即用 profile。不用 clone、不用复制、不用改 YAML——CLI 首次使用时从 GitHub 拉取,缓存在 ~/.agentproc/cache/hub/<name>/(24 小时 TTL)。

遇到 GitHub 限流?

匿名拉取每个 IP 每小时 ~60 次。设置 token 可以提到 5,000 次/小时:

bash
export GITHUB_TOKEN=$(gh auth token)   # 或任意 personal access token

如果你想完全绕开网络,可以用本地仓库:agentproc --profile ./hub/<name>/profile.yaml --prompt "hi"

③ 一行命令跑起来

先跑冒烟测试(不需要 API key):

bash
agentproc hub run echo-agent -p "hello"
# → You said: hello

然后跑真实的。claude-code 支持流式输出和多轮会话续接:

bash
cd ~/projects/my-app          # agent 在哪个目录跑,就 cd 到哪里
agentproc hub run claude-code \
  -p "what is this codebase?" \
  --env ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY"

不需要改任何 profile YAML

agentproc hub run 自动把你当前所在目录作为 agent 的 cwd,并通过 占位符找到打包的 bridge 脚本。只要 cd 到你想让 agent 操作的项目目录,跑就行。

stderr 上会实时看到 NDJSON 事件,stdout 是最终回复:

{"type":"partial","text":"This codebase is...","session_id":"13c2f6ec-1f97-42c4-be9e-9475129e243c"}
{"type":"result","text":"","session_id":"13c2f6ec-1f97-42c4-be9e-9475129e243c"}
agentproc:session:13c2f6ec-1f97-42c4-be9e-9475129e243c

捕获 session id,继续对话:

bash
agentproc hub run claude-code \
  -p "tell me about the auth module" \
  --env ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  --session 13c2f6ec-1f97-42c4-be9e-9475129e243c

短回复可能看不到

有些 agent 在回答较短时一次性吐完全部内容——你只会看到单条 {"type":"result","text":"..."}(可选带 session_id),没有 {"type":"partial"} 行。这是正常的;流式只分片长回复。

④ 接到你的消息平台

AgentProc agent 不直接和微信或 Slack 通信——那是 bridge 的工作。bridge 是一个小程序,职责是:

  1. 从消息平台收到消息(通过 webhook、轮询等)
  2. 启动你的 agent 进程,往它的 stdin 写入一个 {"type":"turn",...} 对象
  3. 读取 agent stdout 上的 NDJSON 事件(按 AgentProc 协议)
  4. 把回复转发给用户

下面是一个 ~30 行的 Node.js bridge 示例,把 agentproc 接到任何平台:

js
// bridge.js — 一个极简的 AgentProc bridge
const { run } = require('agentproc');
const fs = require('fs');

async function handleMessage(message, sessionId) {
  const profile = JSON.parse(fs.readFileSync('./profile.json'));
  const result = await run(profile, {
    message,
    sessionId,
    onPartial: (chunk) => console.log(`[streaming] ${chunk}`),
  });
  console.log(`Reply: ${result.reply}`);
  console.log(`Session: ${result.sessionId}`);  // 下一轮把这个传回来
}

// 替换成你平台的 SDK:
// yourMessagingPlatform.onMessage(handleMessage);
handleMessage(process.argv[2] || 'hello', '');

存为 bridge.js,指向一个 profile,再接到你消息平台的 webhook。runner.js 源码就是协议的代码化形式——读它就是读规范。

接下来去哪

Released under the MIT License.