Advanced~35 minHazelJS
AgentGraph, Supervisor, and Delegate
Compose multi-agent topologies with documented AgentGraph, createSupervisor, @Delegate, and pipeline—full examples.
- Authors
- editorial-team
- Published
- Last reviewed
Progress is stored locally in this browser.
Direct answer
Documented multi-agent surfaces in @hazeljs/agent: @Delegate, AgentGraph (createGraph / edges / parallel), createSupervisor, and runtime.pipeline. Prefer these over undocumented callAgent mentions.
Docs: Agent package — multi-agent.
@Delegate — peer call as tool
typescript
import { Agent, Tool, Delegate } from '@hazeljs/agent';
@Agent({ name: 'research-agent', systemPrompt: 'Research specialist.' })
export class ResearchAgent {
@Tool({ description: 'Research a topic', parameters: [
{ name: 'topic', type: 'string', required: true },
]})
async research(input: { topic: string }) {
return { topic: input.topic, findings: '...' };
}
}
@Agent({
name: 'writer-agent',
systemPrompt: 'Write posts. Delegate research first.',
})
export class WriterAgent {
@Delegate({
agent: 'research-agent',
description: 'Research a topic before writing.',
inputField: 'query',
})
async researchTopic(query: string): Promise<string> {
return ''; // body never called — runtime replaces with execute
}
@Tool({ description: 'Write a blog post', parameters: [
{ name: 'topic', type: 'string', required: true },
]})
async writeBlogPost(input: { topic: string }) {
return { title: `About ${input.topic}`, body: '...' };
}
}
AgentGraph — sequential pipeline
typescript
import { END } from '@hazeljs/agent';
runtime.registerAgent(ResearchAgent);
runtime.registerAgent(WriterAgent);
const graph = runtime
.createGraph('blog-pipeline')
.addNode('researcher', { type: 'agent', agentName: 'research-agent' })
.addNode('writer', { type: 'agent', agentName: 'writer-agent' })
.addNode('publisher', {
type: 'function',
fn: async (input) => {
await cms.publish(input.body);
return { published: true };
},
})
.addEdge('researcher', 'writer')
.addEdge('writer', 'publisher')
.addEdge('publisher', END)
.setEntryPoint('researcher')
.compile();
const result = await graph.run('Write a post about GraphRAG', {
sessionId: 'blog-001',
});
Supervisor — LLM router
typescript
const supervisor = runtime.createSupervisor({
agents: [billingAgent, shippingAgent, faqAgent],
});
// execute via documented supervisor entry — see Agent package
pipeline() shorthand
typescript
const result = await runtime
.pipeline('content-creation', ['ResearchAgent', 'WriterAgent', 'EditorAgent'])
.execute('Write an article about TypeScript');
Next
/learn/orchestration-and-multi-agent/flow-vs-multi-agent-orchestration
Artifact: Graph sketch: router → specialists → merge