名称: 新智能体创建 描述: 提供在Unite-Hub中创建新AI智能体的分步模板和指导,包括正确注册、测试和治理
新智能体创建技能
分步智能体实施
使用时机: 为Unite-Hub创建新的AI智能体
快速启动模板
1. 创建智能体文件
位置: src/lib/agents/my-new-agent.ts
import { BaseAgent, AgentTask, AgentConfig } from './base-agent';
import { getAnthropicClient } from '@/lib/anthropic/lazy-client';
export class MyNewAgent extends BaseAgent {
constructor() {
super({
name: 'MyNewAgent',
queueName: 'my-new-agent-queue',
concurrency: 1,
retryDelay: 5000
});
}
protected async processTask(task: AgentTask): Promise<any> {
// 你的智能体逻辑在这里
const client = getAnthropicClient();
const response = await client.messages.create({
model: 'claude-sonnet-4-5-20250929',
max_tokens: 4096,
messages: [{
role: 'user',
content: `任务: ${task.task_type}
载荷: ${JSON.stringify(task.payload)}`
}]
});
return {
result: response.content[0].text,
workspace_id: task.workspace_id,
model_used: 'claude-sonnet-4-5-20250929',
input_tokens: response.usage.input_tokens,
output_tokens: response.usage.output_tokens
};
}
}
2. 在编排器中注册
文件: src/lib/agents/orchestrator-router.ts
// 添加到AgentIntent枚举
export type AgentIntent =
| 'my_new_agent' // ← 添加此项
| 'email' | 'content' | ...;
// 添加到classifyIntent函数
if (objective.includes('我的任务关键词')) {
return 'my_new_agent';
}
3. 添加到注册表
文件: .claude/agents/registry.json
{
"id": "my-new-agent",
"name": "我的新智能体",
"version": "1.0.0",
"file": "src/lib/agents/my-new-agent.ts",
"capabilities": ["capability_1", "capability_2"],
"queueName": "my-new-agent-queue",
"models": ["claude-sonnet-4-5-20250929"],
"governance": "HUMAN_GOVERNED",
"verification_required": true,
"budget_daily_usd": 10.00,
"category": "marketing"
}
4. 创建测试
文件: tests/agents/my-new-agent.test.ts
import { describe, it, expect, vi } from 'vitest';
import { MyNewAgent } from '@/lib/agents/my-new-agent';
describe('MyNewAgent', () => {
it('成功处理任务', async () => {
const agent = new MyNewAgent();
const task = {
id: 'test-1',
workspace_id: 'ws-123',
task_type: 'my_task',
payload: { data: 'test' },
priority: 5,
retry_count: 0,
max_retries: 3
};
const result = await agent.processTask(task);
expect(result).toBeDefined();
expect(result.workspace_id).toBe('ws-123');
});
});
5. 创建CLI运行器(可选)
文件: scripts/run-my-agent.mjs
import { MyNewAgent } from '../src/lib/agents/my-new-agent.js';
const agent = new MyNewAgent();
await agent.start();
console.log('MyNewAgent 正在运行...');
检查清单
- [ ] 创建继承BaseAgent的智能体文件
- [ ] 实现processTask()方法
- [ ] 添加到orchestrator-router.ts的意图枚举
- [ ] 添加到编排器路由逻辑
- [ ] 在.claude/agents/registry.json中注册
- [ ] 创建测试(要求100%通过)
- [ ] 添加CLI运行器脚本(可选)
- [ ] 在.claude/agent.md中记录文档
- [ ] 设置适当的预算限制
- [ ] 选择治理模式(HUMAN_GOVERNED vs AUTONOMOUS)
标准: 所有智能体必须按workspace_id过滤,遵守预算,通过验证