harness-agents
它能做什么
这项技能描述如何通过自身的运行时层,把 Claude Code、Codex 或 Cursor 等完整的智能体运行框架(harness)添加到 Agent-Native 中。内容涵盖启动运行、保存会话状态和展示后台工作。适合希望在应用中使用这些智能体的开发者。
适用场景
- ✓当你希望在 Agent-Native 应用中让 Claude Code 或 Codex 执行任务的时候。
- ✓当外部智能体程序需要在多轮对话之间保存其会话状态的时候。
- ✓当你希望在应用中显示后台智能体运行的时候。
技能链接
https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/harness-agents/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能让 Codex 在我的应用中执行一个编码任务,并保留它的会话,以便之后继续吗?”
每周 5 个新技能,1 分钟读完。
工作原理
开发者注册 harness 适配器,并通过运行管理器启动一次运行。会话状态保存在应用的数据库中,而 harness 保持它自己的循环。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Harness Agents
Rule
Full agent harnesses are not AgentEngine providers. Use the AgentHarness
substrate in @agent-native/core/agent/harness.
Why
AgentEngine is for one model round trip beneath runAgentLoop. Harnesses like
Claude Code, Codex, Pi, Cursor, and Mastra own their own loop, workspace,
native tools, session state, compaction, approval model, and sandbox behavior.
Putting a harness under AgentEngine.stream() double-runs the loop and loses
session lifecycle semantics.
How
- Register or resolve a harness adapter.
import {
registerBuiltinAgentHarnesses,
resolveAgentHarness,
} from "@agent-native/core/agent/harness";
registerBuiltinAgentHarnesses();
const harness = resolveAgentHarness("ai-sdk-harness:codex");
- Start a turn through the run-manager bridge.
import { startAgentHarnessRun } from "@agent-native/core/agent/harness";
startAgentHarnessRun({
runId,
threadId,
adapter: harness,
input: { prompt },
createSession: {
sessionId,
resumeState,
instructions,
sandbox,
permissionMode: "allow-reads",
},
ownerEmail,
orgId,
});
- Persist native session state in SQL.
Use saveAgentHarnessSession, updateAgentHarnessSession, and
getLatestAgentHarnessSessionForThread. The resumeState is opaque; Agent
Native stores it but does not inspect it.
- Surface runs through background agents.
Harness runs are projected into the shared BackgroundAgentRun shape with
createAgentHarnessBackgroundAgentController() and are available through the
existing run routes as goalId=agent-harness.
ACP Agents
Agent-Native can act as an ACP (Agent Client Protocol) client and drive a local coding agent — Gemini CLI, Claude Code, or any ACP-compliant agent — through this same substrate. This is scoped to local coding: the agent is spawned as a child process speaking newline-delimited JSON-RPC over stdio, and inherits the parent environment so it reuses the user's local CLI login. It is not a hosted/sandboxed transport, and it is not a chat/A2A transport.
import {
registerBuiltinAgentHarnesses,
resolveAgentHarness,
} from "@agent-native/core/agent/harness";
registerBuiltinAgentHarnesses();
// Built-in presets (commands overridable via the resolve config):
const gemini = resolveAgentHarness("acp:gemini");
const claude = resolveAgentHarness("acp:claude-code");
// Or any ACP agent by command:
const custom = resolveAgentHarness("acp", {
command: "gemini",
args: ["--experimental-acp"],
});
- The protocol transport (
@zed-industries/agent-client-protocol) is an optional dependency loaded lazily;installPackagesurfaces a clear install hint. - The agent binary (e.g.
@google/gemini-cli,@zed-industries/claude-code-acp) is a separate external CLI the user installs; presets launch it throughnpxby default and the command/args are overridable because agent ACP entry flags still evolve. permissionModemaps onto ACPsession/request_permissionusing the reported tool-call kind: reads always run, edits run underallow-edits, everything risky prompts unlessallow-all. Approvals surface asapproval-requestevents; answer them through the harness session'sapprove().resumeStatecarries the ACPsessionId; resume works when the agent advertises theloadSessioncapability and degrades to a fresh session otherwise.fs/read_text_fileandfs/write_text_fileare served against the session workspace and refuse paths that escape it; terminal methods are not advertised (the agent uses its own shell).
Adapter Guidance
- Keep harness packages optional. Use dynamic imports in adapters and expose an
install hint through
installPackage. - Use the AI SDK harness adapter as one implementation, not as Agent-Native's public abstraction.
- For bridge-backed coding harnesses, require a real sandbox/workspace provider. Do not run arbitrary coding agents in the host process by default.
- Pass only a narrow, intentional set of Agent-Native actions as host tools.
Preserve
defineActionauth, request context, timeouts, truncation, and read-only metadata.
Code Execution Sandbox
- The
run-codetool executes through a pluggableSandboxAdapter(packages/core/src/coding-tools/sandbox/). The defaultLocalChildProcessAdapterspawns a locked-down local Node child process; swap it viaAGENT_NATIVE_SANDBOXor `registerSandboxAdapt
常见问题
harness 与模型提供商是一回事吗?
不是。技能说明,完整的 harness 拥有自己的循环和状态,因此不会作为模型提供商接入。
谁可以读取已保存的会话状态?
框架只负责存储,不检查其内容,因为对 Agent-Native 来说,该状态是不透明的。
支持哪些 harness?
技能列出了几种,包括 Claude Code、Codex、Pi、Cursor 和 Mastra。
详情
作者的原始描述
Add or use full agent harness runtimes like Claude Code, Codex, Pi, Cursor, Mastra, or ACP agents inside Agent-Native.
repo: BuilderIO/agent-native
热度
- GitHub 星标
- 7.6k
- 排名
- #13163
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …