核心组件
本文档介绍 OpenHuman 的核心组件及其功能。
Agent(智能体)
Agent 是 OpenHuman 的核心抽象单位:
const agent = await client.agents.create({
name: '我的 Agent',
description: '描述 Agent 的功能',
instructions: 'Agent 的行为指令',
model: 'gpt-4',
tools: ['web-search', 'calculator'],
});
Agent 的生命周期
- 创建 - 实例化 Agent
- 配置 - 设置工具和参数
- 运行 - 执行任务
- 监控 - 跟踪执行状态
- 销毁 - 清理资源
Tools(工具)
Tools 是 Agent 调用外部系统的接口:
内置工具
| 工具 | 功能 |
|---|---|
web-search | 网络搜索 |
calculator | 数学计算 |
code-interpreter | 代码执行 |
file-system | 文件操作 |
自定义工具
const customTool = {
name: 'weather',
description: '获取天气信息',
parameters: {
type: 'object',
properties: {
city: { type: 'string' },
},
required: ['city'],
},
execute: async ({ city }) => {
const response = await fetch(`https://api.weather.com?q=${city}`);
return await response.json();
},
};
await client.tools.register(customTool);
Memory(记忆)
Memory 用于存储 Agent 的上下文:
const memory = await client.memory.create({
agentId: agent.id,
type: 'vector', // 'vector' | 'buffer' | 'summary'
settings: {
maxTokens: 8000,
retentionDays: 30,
},
});
Memory 类型
- Vector Memory - 基于向量存储,支持语义检索
- Buffer Memory - 滑动窗口记忆
- Summary Memory - 自动摘要记忆
Chain(链)
Chain 用于组合多个操作:
const chain = await client.chains.create({
name: '研究链',
steps: [
{ type: 'search', query: '{{input}}' },
{ type: 'analyze', data: '{{previous}}' },
{ type: 'summarize', text: '{{previous}}' },
],
});