Graph + Sub-Agents
Combine Graph workflows with Sub-Agent coordination for sophisticated hierarchical task distribution.
Combine Graph workflows with Sub-Agent coordination for sophisticated hierarchical task distribution.
Quick Start
Clone the Complete Example
The easiest way to get started is to clone the complete example repository:
git clone https://github.com/astreus-ai/examples
cd examples/graph-sub-agents
npm installOr Install Package Only
If you prefer to build from scratch:
npm install @astreus-ai/astreusEnvironment Setup
# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
ANTHROPIC_API_KEY=your-anthropic-api-key-here
DB_URL=sqlite://./astreus.dbGraph + Sub-Agent Integration
import { Agent, Graph } from '@astreus-ai/astreus';
// Create specialized sub-agents
const researcher = await Agent.create({
name: 'ResearchSpecialist',
model: 'gpt-4o',
systemPrompt: 'You conduct thorough research and gather comprehensive information.',
knowledge: true,
memory: true
});
const analyst = await Agent.create({
name: 'DataAnalyst',
model: 'gpt-4o',
systemPrompt: 'You analyze data and provide actionable insights.',
useTools: true
});
const writer = await Agent.create({
name: 'ContentWriter',
model: 'claude-3-5-sonnet-20241022',
systemPrompt: 'You create compelling, well-structured content.',
vision: true
});
// Create main coordinator agent with sub-agents
const coordinator = await Agent.create({
name: 'ProjectCoordinator',
model: 'gpt-4o',
systemPrompt: 'You coordinate complex projects using specialized sub-agents.',
subAgents: [researcher, analyst, writer]
});
// Create graph with sub-agent awareness
const projectGraph = new Graph({
name: 'Market Analysis Project',
subAgentAware: true,
maxConcurrency: 2
}, coordinator);
// Add tasks that leverage sub-agents
const researchTask = projectGraph.addTaskNode({
name: 'Market Research',
prompt: 'Research the AI healthcare market, including key players, market size, and growth trends',
useSubAgents: true,
subAgentDelegation: 'auto'
});
const analysisTask = projectGraph.addTaskNode({
name: 'Data Analysis',
prompt: 'Analyze the research data and identify key opportunities and challenges',
dependencies: [researchTask],
useSubAgents: true,
subAgentCoordination: 'parallel'
});
const reportTask = projectGraph.addTaskNode({
name: 'Executive Report',
prompt: 'Create a comprehensive executive report with recommendations',
dependencies: [analysisTask],
useSubAgents: true
});
// Execute the graph with intelligent sub-agent coordination
const result = await projectGraph.run();
// Display results
console.log('Project completed:', result.success);
console.log(`Tasks completed: ${result.completedNodes}/${result.completedNodes + result.failedNodes}`);
console.log(`Duration: ${result.duration}ms`);
// Display task results
if (result.results) {
console.log('\nTask Results:');
for (const [nodeId, nodeResult] of Object.entries(result.results)) {
console.log(`\n${nodeId}:`, nodeResult);
}
}
// Get the final report from the last task
const finalReport = result.results?.[reportTask];
if (finalReport) {
console.log('\n=== Final Executive Report ===');
console.log(finalReport);
}Running the Example
If you cloned the repository:
npm run devIf you built from scratch, create an index.ts file with the code above and run:
npx tsx index.tsRepository
The complete example is available on GitHub: examples/graph-sub-agents
Last updated: July 6, 2026
In this section
Your First Agent
Create your first AI agent with Astreus framework. Learn the setup patterns, APIs, and practical examples needed to build reliable Astreus agent systems.
Agent with Memory
Build agents with persistent memory capabilities. Learn the setup patterns, APIs, and practical examples needed to build reliable Astreus agent systems.
Agent with Knowledge
Create agents with knowledge base capabilities for enhanced information retrieval. Learn the setup patterns, APIs, and practical examples needed to build...
Agent with Vision
Create agents capable of processing and analyzing images. Learn the setup patterns, APIs, and practical examples needed to build reliable Astreus agent systems.