Basic Sub-Agents
Create and coordinate multiple AI agents for complex task delegation. Learn the setup patterns, APIs, and practical examples needed to build reliable...
Create and coordinate multiple AI agents for complex task delegation.
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/sub-agents-basic
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
DB_URL=sqlite://./astreus.dbSimple Sub-Agent Setup
import { Agent } from '@astreus-ai/astreus';
// Create specialized sub-agents
const researcher = await Agent.create({
name: 'Researcher',
model: 'gpt-4o',
systemPrompt: 'You are an expert researcher who gathers comprehensive information.'
});
const writer = await Agent.create({
name: 'Writer',
model: 'gpt-4o',
systemPrompt: 'You are a skilled writer who creates clear, engaging content.'
});
// Create main coordinator agent
const mainAgent = await Agent.create({
name: 'Coordinator',
model: 'gpt-4o',
systemPrompt: 'You coordinate tasks between specialized agents.',
subAgents: [researcher, writer]
});
// Use auto delegation
const result = await mainAgent.ask(
'Research artificial intelligence trends and write a summary',
{
useSubAgents: true,
delegation: 'auto'
}
);
console.log(result);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/sub-agents-basic
Last updated: May 26, 2026