展示HN:Hive Agent – 在您的应用中嵌入类似Claude的AI代理
嘿,HN,
我每天都在使用Claude Code进行开发,并一直在思考:如果我能为我的用户提供相同的体验——一个探索上下文、规划、执行工具并构建事物的AI代理——但将其原生嵌入到我自己的应用程序中会怎么样?
因此,我构建了*Hive Agent*,这是一个开源的TypeScript框架,重现了Claude Code的核心架构,作为一个可以集成到任何应用中的库。
*它的功能:*
- *工作区系统* — 通过虚拟文件系统为代理提供任何上下文。将用户的数据、项目文件、API响应等输入给它——无论你的应用需要什么。代理使用类似bash的命令进行读取、写入和搜索。
- *内置探索与规划代理* — 就像Claude Code一样,Hive会自动生成子代理,以在行动之前调查工作区数据,并为复杂任务设计逐步计划。
- *子代理编排* — 生成具有不同模型(Claude、OpenAI)、不同工具和结构化输入/输出的专业代理。研究代理可以使用GPT-4,而主代理使用Claude。
- *自定义工具* — 定义你的应用所需的任何工具。API调用、数据库查询、浏览器自动化、文档生成——代理会根据需要调用它们。
- *无状态与无服务器准备* — 没有持久状态。可以在Firebase Functions、Vercel、AWS Lambda中运行。传入历史记录,传出历史记录。
- *执行追踪与成本跟踪* — 完整的层级追踪,按模型的令牌使用和成本细分。
- *交互模式* — 代理可以暂停并提出澄清问题,就像Claude Code一样。
*你可以用它构建的东西:*
- 针对你平台的AI编码助手
- 理解用户上下文的文档生成器
- 项目搭建工具
- 具有访问你内部API的支持代理
- 任何需要AI探索数据、规划和行动的工作流程
*快速示例:*
```typescript
import { Hive, ClaudeProvider } from '@alexnetrebskii/hive-agent'
const agent = new Hive({
systemPrompt: '你是一个项目生成器...',
tools: [myApiTool, myDbTool],
llm: new ClaudeProvider({ apiKey: process.env.ANTHROPIC_API_KEY }),
workspace: new Workspace({
paths: { 'user/requirements.json': { value: userReqs } }
})
})
const result = await agent.run('根据我的要求创建一个新项目')
```
代理将探索工作区,规划方法,创建文件,调用你的工具——一切都是自主完成的。
*链接:*
- GitHub: [https://github.com/anetrebskii/hive-agent](https://github.com/anetrebskii/hive-agent)
- 安装: `pnpm add @alexnetrebskii/hive-agent`
- MIT许可证
我希望能收到任何构建代理驱动功能的人的反馈。你希望内置哪些工具或模式?试试看,告诉我有什么问题。
查看原文
Hey HN,<p>I've been building with Claude Code daily and kept thinking: what if I could give my users the same experience — an AI agent that explores context, plans, executes tools, and builds things — but embedded natively in my own application?<p>So I built *Hive Agent*, an open-source TypeScript framework that reproduces the core Claude Code architecture as a library you can integrate into any app.<p>*What it does:*<p>- *Workspace system* — Give the agent any context via a virtual filesystem. Feed it your user's data, project files, API responses — whatever your app needs. The agent reads, writes, and searches through it using bash-like commands.
- *Built-in Explore & Plan agents* — Just like Claude Code, Hive auto-spawns sub-agents to investigate workspace data before acting and to design step-by-step plans for complex tasks.
- *Sub-agent orchestration* — Spawn specialized agents with different models (Claude, OpenAI), different tools, and structured I/O. A research agent can use GPT-4, while the main agent uses Claude.
- *Custom tools* — Define any tool your app needs. API calls, database queries, browser automation, document generation — the agent calls them as needed.
- *Stateless & serverless-ready* — No persistent state. Works in Firebase Functions, Vercel, AWS Lambda. Pass history in, get history out.
- *Execution tracing & cost tracking* — Full hierarchical traces with per-model token usage and cost breakdown.
- *Interactive mode* — Agent can pause and ask clarifying questions, just like Claude Code does.<p>*What you can build with it:*<p>- AI coding assistants scoped to your platform
- Document generators that understand your users' context
- Project scaffolding tools
- Support agents with access to your internal APIs
- Any workflow where an AI needs to explore data, plan, and act<p>*Quick example:*<p>```typescript
import { Hive, ClaudeProvider } from '@alexnetrebskii/hive-agent'<p>const agent = new Hive({
systemPrompt: 'You are a project generator...',
tools: [myApiTool, myDbTool],
llm: new ClaudeProvider({ apiKey: process.env.ANTHROPIC_API_KEY }),
workspace: new Workspace({
paths: { 'user/requirements.json': { value: userReqs } }
})
})<p>const result = await agent.run('Create a new project based on my requirements')
```<p>The agent will explore the workspace, plan the approach, create files, call your tools — all autonomously.<p>*Links:*<p>- GitHub: <a href="https://github.com/anetrebskii/hive-agent" rel="nofollow">https://github.com/anetrebskii/hive-agent</a>
- Install: `pnpm add @alexnetrebskii/hive-agent`
- MIT licensed<p>I'd love feedback from anyone building agent-powered features. What tools or patterns would you want built-in? Try it out and let me know what breaks.