58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
import { Tool } from '../types/index.js';
|
||
import { subAgentManager } from './manager.js';
|
||
|
||
/**
|
||
* spawn_agent — 创建一个指定角色和名称的子 Agent
|
||
*/
|
||
export const spawnAgentTool: Tool = {
|
||
name: 'spawn_agent',
|
||
description: '创建一个子Agent,指定其名称和角色/系统提示词。用于创建具有特定人设的对话角色(如销售、顾客等)。',
|
||
parameters: {
|
||
type: 'object',
|
||
properties: {
|
||
name: { type: 'string', description: '子Agent的唯一名称,如"sales"、"customer"' },
|
||
role_prompt: { type: 'string', description: '子Agent的角色描述/系统提示词,如"你是一个热情的汽车销售"' },
|
||
},
|
||
required: ['name', 'role_prompt'],
|
||
},
|
||
execute: async (args) => {
|
||
const { name, role_prompt } = args;
|
||
try {
|
||
const agent = subAgentManager.spawn(name as string, role_prompt as string);
|
||
return `子Agent "${agent.name}" 创建成功。`;
|
||
} catch (e: any) {
|
||
return `创建失败: ${e.message}`;
|
||
}
|
||
},
|
||
};
|
||
|
||
/**
|
||
* run_conversation — 运行两个子 Agent 之间的多轮对话
|
||
*/
|
||
export const runConversationTool: Tool = {
|
||
name: 'run_conversation',
|
||
description: '在两个已创建的子Agent之间运行多轮对话。一方先发起,另一方回应,交替进行。返回完整对话记录。',
|
||
parameters: {
|
||
type: 'object',
|
||
properties: {
|
||
agent1: { type: 'string', description: '发起方Agent名称(先说话的那个)' },
|
||
agent2: { type: 'string', description: '回应方Agent名称' },
|
||
max_turns: { type: 'number', description: '最大对话轮次,如5表示agent1发起 + 4轮交替 = 共5次发言' },
|
||
topic: { type: 'string', description: '对话主题/场景描述,如"汽车购买谈判"' },
|
||
},
|
||
required: ['agent1', 'agent2', 'max_turns', 'topic'],
|
||
},
|
||
execute: async (args) => {
|
||
const { agent1, agent2, max_turns, topic } = args;
|
||
return await subAgentManager.runConversation(
|
||
agent1 as string,
|
||
agent2 as string,
|
||
max_turns as number,
|
||
topic as string,
|
||
);
|
||
},
|
||
};
|
||
|
||
/** 所有 sub-agent 管理工具(仅供主 Agent 使用) */
|
||
export const subAgentTools: Tool[] = [spawnAgentTool, runConversationTool];
|