AI代理构建工具

OpenHarness是一个基于Vercel AI SDK的通用AI代理开发工具包,支持多轮会话、中间件组合和子代理功能,适用于代码重构、文件管理等开发场景。

  • by MaxGfeller
  • TypeScript
  • 本地部署
  • 621 星标
  • 更新于
在 GitHub 查看 MaxGfeller/open-harness

使用说明

OpenHarness

在代码中构建功能强大的通用AI代理。基于 Vercel的AI SDK,灵感来自Claude Code、Codex和类似的代理工具。

文档

包裹

包装 描述
@openharness/core 代理、会话、对话、中间件、工具、UI流集成
@openharness/provider-chatgpt 用于ChatGPT订阅支持的本地线束的实验性ChatGPT/Codex OAuth模型提供程序
@openharness/provider-vfs 用于沙盒、内存或SQLite支持的文件访问的虚拟文件系统提供程序
@openharness/react React钩子和AI SDK 5聊天UI的提供者
@openharness/vue Vue 3可组合和AI SDK 5聊天UI的提供者

快速开始

npm install @openharness/core @ai-sdk/openai
import { Agent, createFsTools, createBashTool, NodeFsProvider, NodeShellProvider } from "@openharness/core";
import { openai } from "@ai-sdk/openai";

const agent = new Agent({
  name: "dev",
  model: openai("gpt-5.4"),
  tools: {
    ...createFsTools(new NodeFsProvider()),
    ...createBashTool(new NodeShellProvider()),
  },
  maxSteps: 20,
});

for await (const event of agent.run([], "Refactor the auth module")) {
  if (event.type === "text.delta") process.stdout.write(event.text);
}

多回合会话

import { Session } from "@openharness/core";

const session = new Session({ agent, contextWindow: 128_000 });

for await (const event of session.send("List all TypeScript files")) {
  if (event.type === "text.delta") process.stdout.write(event.text);
}

// Session remembers the conversation, handles compaction and retry
for await (const event of session.send("Now refactor the largest one")) {
  if (event.type === "text.delta") process.stdout.write(event.text);
}

可组合中间件

import { Conversation, toRunner, apply, withTurnTracking, withCompaction, withRetry } from "@openharness/core";

const runner = apply(
  toRunner(agent),
  withTurnTracking(),
  withCompaction({ contextWindow: 200_000, model: agent.model }),
  withRetry({ maxRetries: 5 }),
);

const chat = new Conversation({ runner });
for await (const event of chat.send("Fix the bug")) { /* ... */ }

子代理

默认情况下,内置子代理保持无状态,但您现在可以选择加入:

  • 在运行时解析动态子代理目录
  • 基于以下内容构建的可恢复子代理会话 Session
  • 具有单独运行ID和会话ID的后台运行

示例

示例 运行
CLI代理 --具有工具批准的终端代理和子代理 pnpm --filter cli-demo start 或 pnpm --filter cli-demo start -- --chatgpt
Next.js聊天 --与进行流式聊天 @openharness/react pnpm --filter nextjs-demo dev
Nuxt聊天 --与进行流式聊天 @openharness/vue pnpm --filter nuxt-demo dev

默认情况下,示例使用 OPENAI_API_KEYCLI代理可以改为使用ChatGPT/Codex OAuth --chatgpt.

要运行它们:

git clone https://github.com/MaxGfeller/open-harness.git
cd open-harness
echo "OPENAI_API_KEY=sk-..." > .env
pnpm install && pnpm build

了解更多

请参阅完整文档 docs.open-harness.dev 用于:

  • 代理 --无状态执行器、事件、配置
  • 会话 --压缩、重试、持久化、挂钩
  • 中间件 -可组合中间件与对话API
  • 工具 --文件系统、bash、自定义工具、权限
  • 子代理 --嵌套委托、动态目录、可恢复会话和后台执行
  • MCP 服务器 --模型上下文协议集成
  • 技能 --按需指令包
  • UI集成 --React和Vue流媒体

许可证

麻省理工学院——见 许可证 了解详情。