Basic Sub-Agents

Example

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/sub-agents-basic
cd sub-agents-basic
npm install

Or Install Package Only

If you prefer to build from scratch:

npm install @astreus-ai/astreus

Environment Setup

# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.db

Simple 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 dev

If you built from scratch, create an index.ts file with the code above and run:

npx tsx index.ts

Repository

The complete example is available on GitHub: astreus-ai/sub-agents-basic

How is this guide?