基本的なサブエージェント

複雑なタスク委任のために複数のAIエージェントを作成・連携させます。

クイックスタート#

完全なサンプルをクローンする#

最も簡単な始め方は、完全なサンプルリポジトリをクローンすることです。

bash
git clone https://github.com/astreus-ai/examples
cd examples/sub-agents-basic
npm install

またはパッケージのみをインストール#

ゼロから構築したい場合は次のようにします。

bash
npm install @astreus-ai/astreus

環境設定#

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

シンプルなサブエージェントのセットアップ#

typescript
import { Agent } from '@astreus-ai/astreus';

// Create specialized sub-agents
const researcher = await Agent.create({
  name: 'Researcher',
  model: 'gpt-6-astra',
  systemPrompt: 'You are an expert researcher who gathers comprehensive information.'
});

const writer = await Agent.create({
  name: 'Writer',
  model: 'gpt-6-astra',
  systemPrompt: 'You are a skilled writer who creates clear, engaging content.'
});

// Create main coordinator agent
const mainAgent = await Agent.create({
  name: 'Coordinator',
  model: 'gpt-6-astra',
  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);

サンプルの実行#

リポジトリをクローンした場合は次を実行します。

bash
npm run dev

ゼロから構築した場合は、上記のコードを含むindex.tsファイルを作成し、次を実行します。

bash
npx tsx index.ts

リポジトリ#

完全なサンプルはGitHubで公開されています: examples/sub-agents-basic