高级功能
本指南深入介绍 OpenHuman 的高级功能,帮助您充分发挥 agent 的能力。
多模态交互
图像处理
const response = await client.agents.run(agent.id, {
message: '描述这张图片',
attachments: [
{
type: 'image',
url: 'https://example.com/image.jpg',
},
],
});
文件处理
const response = await client.agents.run(agent.id, {
message: '总结这个 PDF',
attachments: [
{
type: 'file',
name: 'report.pdf',
url: 'https://example.com/report.pdf',
},
],
});
本地 AI
在您的机器上运行 AI 模型,保持数据私密:
[local_ai]
enabled = true
provider = "ollama" # or "lm_studio"
ollama_url = "http://localhost:11434"
embedding_model = "all-minilm:latest"
memory_model = "gemma3:1b-it-qat"
可选择三种预设:
- 仅 Embeddings - 本地向量计算
- 记忆 + 反思 - 本地处理记忆和反思
- 全本地 - 所有工作负载本地运行
自定义工具
注册 HTTP 请求工具
const httpTool = await client.tools.register({
name: 'http-request',
description: '发送 HTTP 请求',
parameters: {
type: 'object',
properties: {
url: { type: 'string' },
method: { type: 'string', enum: ['GET', 'POST'] },
},
},
execute: async ({ url, method }) => {
const response = await fetch(url, { method });
return await response.json();
},
});
注册数据库工具
const dbTool = await client.tools.register({
name: 'query-db',
description: '查询数据库',
parameters: {
type: 'object',
properties: {
sql: { type: 'string' },
},
},
execute: async ({ sql }) => {
const result = await db.query(sql);
return result;
},
});
Agent 链式调用
const chain = await client.chains.create({
name: '研究写作链',
steps: [
{
type: 'agent',
agentId: researchAgent.id,
prompt: '研究 {{input}} 相关主题',
},
{
type: 'agent',
agentId: writerAgent.id,
prompt: '基于以下研究结果写一篇文章:{{previous}}',
},
],
});
const result = await client.chains.run(chain.id, {
input: 'AI Agent 的发展趋势',
});
远程 Core
将 Rust core 部署在远程服务器,通过 RPC 连接:
[core]
mode = "remote"
rpc_url = "https://your-core.example/rpc"
token = "your-core-token"
适合团队共享同一个 core 实例,或在不同网络环境下访问。
Webhook 回调
await client.agents.update(agent.id, {
webhook: {
url: 'https://your-server.com/webhook',
events: ['onComplete', 'onError'],
},
});