import { Agent } from '@ag-kit/agents';
import { OpenAIProvider } from '@ag-kit/providers/openai';
const provider = new OpenAIProvider({
apiKey: process.env.OPENAI_API_KEY,
defaultModel: 'gpt-4'
});
const localAgent = new Agent({
name: 'coordinator-agent',
model: provider,
instructions: 'You coordinate with other agents.'
});
// 通过 HTTP 请求进行 A2A 通信
async function delegateTask(task: any) {
const response = await fetch('http://other-agent:3000/send-message', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: [{
role: 'user',
content: `Agent task: ${JSON.stringify(task)}`
}]
})
});
return response.json();
}
// 注意:Agent 事件处理应在 Agent 的 run 方法中实现