# Basic Sub-Agents URL: /docs/examples/sub-agents-basic Source: /app/src/content/docs/examples/sub-agents-basic.mdx import { DocImage } from '@/components/DocImage'; 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: ```bash git clone https://github.com/astreus-ai/sub-agents-basic cd sub-agents-basic npm install ``` ### Or Install Package Only If you prefer to build from scratch: ```bash npm install @astreus-ai/astreus ``` ## Environment Setup ```bash # .env OPENAI_API_KEY=sk-your-openai-api-key-here DB_URL=sqlite://./astreus.db ``` ## Simple Sub-Agent Setup ```typescript 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: ```bash npm run dev ``` If you built from scratch, create an `index.ts` file with the code above and run: ```bash npx tsx index.ts ``` ## Repository The complete example is available on GitHub: [astreus-ai/sub-agents-basic](https://github.com/astreus-ai/sub-agents-basic)