for await (const event of stream) {
if (event.type === "tool_start" && event.toolName === "agent_find") {
const tool = parseToolEvent(event);
console.log(`Looking for an agent to: ${tool?.action}`);
}
if (event.type === "tool_start" && event.toolName === "swarm_delegate") {
const tool = parseToolEvent(event);
console.log(`Delegating to agent: ${tool?.agent}`);
}
if (event.type === "tool_end" && event.toolName === "swarm_delegate") {
const tool = parseToolEvent(event);
if (tool?.error) {
console.error(`Delegation failed: ${tool.error}`);
} else {
console.log("Delegation complete");
}
}
}