CORAL Agent Runtimes完全指南:如何接入Claude Code、Codex、Cursor、Kiro、OpenCode并配置Bindings
CORAL Agent Runtimes完全指南:如何接入Claude Code、Codex、Cursor、Kiro、OpenCode并配置Bindings
CORAL 是一个开源的自主研究(autoresearch)框架,它把 Claude Code、Codex、OpenCode、Cursor Agent、Kiro 等编码 Agent 封装为可插拔的 Agent Runtimes,让多个 Agent 在隔离工作区中并行进化、共享知识并自动评分。本文带你快速完成各 Runtime 的接入,并学会用 Bindings 把本地环境配置与任务定义分离,一次配置、多任务复用。
什么是 Agent Runtime?
每个 Agent 在 CORAL 中都是一个独立子进程:它读取指令文件、修改代码、运行 coral eval 评分、把经验写入共享笔记,然后循环迭代。不同的 Runtime 只是"驱动子进程的方式"不同——CORAL 的初始化与后台管理器(watch、heartbeat、知识整合)对所有 Runtime 保持一致:
CORAL 内置 6 个 Runtime,均在 coral/agent/registry.py 中注册,每个实现位于 coral/agent/builtin/ 目录:
| Runtime | agents.runtime 取值 |
默认模型 | 对应 CLI | 指令文件 |
|---|---|---|---|---|
| Claude Code(默认) | claude_code |
sonnet |
claude |
CLAUDE.md |
| Codex | codex |
gpt-5.4 |
codex |
AGENTS.md |
| OpenCode | opencode |
openai/gpt-5 |
opencode |
AGENTS.md |
| Cursor Agent | cursor(别名 cursor_agent) |
auto |
cursor-agent |
AGENTS.md |
| Kiro | kiro |
auto |
kiro-cli |
KIRO.md |
| Pi | pi |
zai/glm-5.1 |
pi |
— |
在 task.yaml 中切换 Runtime 只需一行:
agents:
runtime: codex
model: gpt-5.4
更多背景可参考官方文档 docs/content/docs/guides/agent-runtimes.mdx 与 docs/content/docs/concepts/agents.mdx。
接入 Claude Code:零配置默认 Runtime
Claude Code 是默认 Runtime,源码见 coral/agent/builtin/claude_code.py。前置条件只有一个:本机安装了 claude CLI 并配置好 Anthropic API key。
agents:
runtime: claude_code # 可省略,默认即它
model: opus # 或用 sonnet / 完整模型ID
几个实用细节:
- 会话日志以 stream-json 格式写入各 Agent 工作区的
.claude/logs/,重启时通过--resume <session_id>无缝续接; - 启动参数支持
--max-turns限制轮数,也支持runtime_options.add_dirs给会话追加可访问目录; - 仓库自带的 coral/template/presets/local-claude.yaml 是一个 4 Agent 的本地 Claude Code 预设,在
task.yaml中写preset: local-claude即可继承。
接入 Codex:OpenAI 的编码 Agent
Codex Runtime(coral/agent/builtin/codex.py)以 codex exec --json 非交互方式运行,并自动以 codex exec resume <session_id> 恢复会话。
agents:
runtime: codex
model: gpt-5.4
runtime_options:
model_reasoning_effort: high # 也支持 fast_mode、personality、web_search
runtime_options 会被翻译成 codex -c key=value 参数;若启用了 LiteLLM 网关(gateway),CORAL 会自动设置 OPENAI_BASE_URL / OPENAI_API_KEY 把请求路由过去。
接入 OpenCode:配置走 seed 目录
OpenCode(coral/agent/builtin/opencode.py)通过 opencode run --format json 启动,权限与模型提供商都来自一个 opencode.json——把它放进任务的 seed/ 目录,CORAL 会自动复制到每个 Agent 的工作区。参考现成示例 examples/circle_packing/seed/opencode.json:
{
"permission": { "bash": "allow", "edit": "allow", "write": "allow", "question": "deny" },
"provider": {
"claude": {
"npm": "@ai-sdk/anthropic",
"options": { "baseURL": "http://localhost:4000/v1", "apiKey": "xxx" }
}
}
}
要点:
- 除
question、webfetch、websearch设为"deny"外,权限全部"allow",保证 Agent 无人值守; - 使用 gateway 时,
baseURL指向http://localhost:<端口>/v1,apiKey填占位值即可; agents.model必须与opencode.json中定义的模型一致,例如claude/claude-opus-4-6。
完整任务配置可对照 examples/circle_packing/task.yaml(它通过 preset: docker-opencode 一键继承 opencode + Docker 会话配置)。
接入 Cursor Agent:一次登录长期有效
安装 Cursor Agent CLI 后执行一次 cursor-agent login 完成认证,然后:
agents:
runtime: cursor # 别名 cursor_agent 也可以
model: auto
CORAL 以 cursor-agent --print --output-format stream-json --force --workspace <worktree> 启动每个 Agent,完整任务简报写入工作区根目录的 AGENTS.md,并额外放置 .cursor/rules/coral.mdc 常生效规则(如"用 coral eval 评分、不要碰 .coral/private/")。可选 runtime_options:
agents:
runtime: cursor
runtime_options:
command: /usr/local/bin/cursor-agent # 覆盖二进制路径
mode: plan # --mode plan|ask
stream_partial_output: true
注意:Cursor 使用自己的账号登录态,不经过 CORAL 的 LiteLLM 网关。
接入 Kiro:最简单的 CLI 集成
安装 kiro-cli 并完成 Kiro 的认证设置后,task.yaml 只需:
agents:
runtime: kiro
model: auto
CORAL 以 kiro-cli chat <prompt> --no-interactive -a 启动(-a 信任所有工具),指令读取工作区的 KIRO.md。由于 Kiro 暂不暴露可恢复的 session id,重启的 Agent 会重新开始——但它们仍可通过共享的 .kiro/ 目录看到之前的所有尝试与笔记,不会丢失知识。Kiro 与 Cursor 一样走自己的认证,不经网关。
配置 Bindings:一次配置,全任务复用
直接把 runtime / model 写进每个 task.yaml 有个问题:换个机器,CLI 路径、默认模型都得重改。**Bindings(Agent 绑定)**就是为解决它而生的"机器级预设":一个短名打包 runtime、CLI 命令、默认模型、runtime_options 和可选角色文件,任务只按名字引用,保持可移植。
1. 一键检测并创建。 不带子命令运行 coral setup,它会扫描 PATH 中所有受支持的 CLI(claude、codex、cursor-agent、opencode、kiro-cli、pi)并进入交互式选择向导:
coral setup
# ✓ claude_code claude /opt/homebrew/bin/claude
# codex codex not found
# ✓ cursor_agent cursor-agent ~/.local/bin/cursor-agent
2. 显式创建(适合脚本/CI)。
coral setup agent --name claude-opus --runtime claude_code --model opus
coral setup agent --name codex-high --runtime codex --option model_reasoning_effort=high
3. 存放位置与查看。 Bindings 保存在 ~/.config/coral/agents.yaml(遵循 $XDG_CONFIG_HOME),示例:
default: claude-opus
agents:
claude-opus:
runtime: claude_code
command: claude
model: opus
role_file: ~/.config/coral/roles/generalist.md
codex-high:
runtime: codex
model: gpt-5.4
runtime_options:
model_reasoning_effort: high
日常管理命令(实现见 coral/cli/agents.py):
coral agents list # 列出所有 binding(标记默认项)
coral agents show claude-opus # 查看单个 binding 展开后的字段
coral agents doctor # 校验所有 binding(含一次真实 hello-ping 探活)
coral agents remove claude-opus # 按名称删除
doctor 的 live ping 会真正调用一次 CLI,能提前暴露登录过期、模型名拼写错误等问题;CI 中可加 --no-live 跳过。
4. 在任务中引用。 单个 Runtime:
agents:
binding: claude-opus
count: 4
混合团队——不同角色绑不同 Runtime:
agents:
assignments:
- binding: researcher
count: 1
- binding: implementer
count: 3
优先级规则:task.yaml 中显式写的字段 > binding 字段 > Runtime 默认值。例如 binding: claude-opus 加 model: sonnet,就是用 opus 绑定的 runtime 配置但换成 sonnet 模型。多 Runtime 团队共享知识的效果,可以看下方多 Agent 共识笔记的实例(各 Agent 的分数与"已确认死路"一目了然):
常见问题速查
| 症状 | 处理 |
|---|---|
Unknown runtime 'xxx' |
用 coral agents list 查看可用名;别名见 registry 中 _ALIASES(如 claude → claude_code) |
| Agent 频繁重启 | 跑 coral agents doctor <名字>,live ping 失败多半是登录态过期,按提示重新登录对应 CLI |
| OpenCode 模型不生效 | 检查 seed/opencode.json 的 provider.models 与 agents.model 是否一致 |
| Cursor/Kiro 认证报错 | 二者使用自身登录态,与 CORAL 配置和 gateway 无关,重新 cursor-agent login 或 Kiro setup 即可 |
小结
- 切换 Runtime 只需在
task.yaml中改agents.runtime(+model),6 个内置实现开箱即用; - 需要精细控制时用
runtime_options(Codex 推理强度、Cursor 模式、OpenCode 权限等); - 跨机器、跨任务复用环境时,用
coral setup agent建 Bindings,coral agents doctor定期体检; - 想深入协议细节,可阅读 coral/agent/runtime.py 中的
AgentRuntime协议定义,以及 coral/agent/builtin/ 下各 Runtime 的完整实现。
装好任何一个 Runtime,跑通一个 Binding,你的多 Agent 自主研究实验就可以出发了。


