サブエージェント
Astreusのドキュメントでサブエージェントについて学び、エージェントシステムを構築するためのセットアップの手引き、APIのパターン、実践的な例を確認しましょう。 信頼性の高いAstreusエージェントシステムを構築するために必要なセットアップのパターン、API、実践的な例を学びましょう。
専門化されたエージェントが連携して動作する、知的なタスク委任
概要
サブエージェントは、メインエージェントが専門化されたサブエージェントへ知的にタスクを委任する、高度なマルチエージェント連携を実現します。各サブエージェントは独自の専門性、機能、役割を持ち、単一のエージェントでは対応が難しい複雑なワークフローを完了するために協力して動作します。
新機能: サブエージェントはグラフワークフローとシームレスに統合され、複雑なワークフローオーケストレーションシステム全体で階層的なタスク分配を可能にします。
サブエージェントの作成
サブエージェントは独立して作成された後、メインのコーディネーターエージェントにアタッチされます。
import { Agent } from '@astreus-ai/astreus';
// Create specialized sub-agents
const researcher = await Agent.create({
name: 'ResearcherBot',
model: 'gpt-4o',
systemPrompt: 'You are an expert researcher who gathers and analyzes information thoroughly.',
memory: true,
knowledge: true
});
const writer = await Agent.create({
name: 'WriterBot',
model: 'gpt-4o',
systemPrompt: 'You are a skilled content writer who creates engaging, well-structured content.',
vision: true
});
const analyst = await Agent.create({
name: 'AnalystBot',
model: 'gpt-4o',
systemPrompt: 'You are a data analyst who provides insights and recommendations.',
useTools: true
});
// Create main agent with sub-agents
const mainAgent = await Agent.create({
name: 'CoordinatorAgent',
model: 'gpt-4o',
systemPrompt: 'You coordinate complex tasks between specialized sub-agents.',
subAgents: [researcher, writer, analyst]
});委任戦略
自動委任
メインエージェントはLLMの知能を使ってタスクを分析し、最適に割り当てます。
const result = await mainAgent.ask(
'Research AI market trends, analyze the data, and write an executive summary',
{
useSubAgents: true,
delegation: 'auto' // AI-powered task distribution
}
);タスク分析
メインエージェントがLLM推論を使って複雑なタスクを分析します。
エージェントのマッチング
各サブエージェントの能力と専門性を評価します。
最適な割り当て
最も適切なエージェントに対して具体的なサブタスクを作成します。
連携した実行
実行フローと結果の集約を管理します。
手動委任
IDを使って特定のタスクを特定のエージェントに明示的に割り当てます。
const result = await mainAgent.ask(
'Complex multi-step project',
{
useSubAgents: true,
delegation: 'manual',
taskAssignment: {
[researcher.id]: 'Research market opportunities in healthcare AI',
[analyst.id]: 'Analyze market size and growth potential',
[writer.id]: 'Create executive summary with recommendations'
}
}
);逐次委任
サブエージェントが順番に、前の結果を踏まえて動作します。
const result = await mainAgent.ask(
'Create a comprehensive business plan for an AI startup',
{
useSubAgents: true,
delegation: 'sequential' // Each agent builds on the previous work
}
);連携パターン
graph TD
A[Main Coordinator Agent] --> B{Task Analysis}
B -->|Research Tasks| C[ResearcherBot]
B -->|Analysis Tasks| D[AnalystBot]
B -->|Content Tasks| E[WriterBot]
C --> F[Research Results]
D --> G[Analysis Results]
E --> H[Written Content]
F --> I[Result Aggregation]
G --> I
H --> I
I --> J[Final Output]
style A fill:#333,stroke:#333,stroke-width:4px
style C fill:#333,stroke:#333,stroke-width:2px
style D fill:#333,stroke:#333,stroke-width:2px
style E fill:#333,stroke:#333,stroke-width:2px並列実行
サブエージェントが同時に動作し、最大限の効率を実現します。
const result = await mainAgent.ask(
'Multi-faceted analysis task',
{
useSubAgents: true,
delegation: 'auto',
coordination: 'parallel' // All agents work concurrently
}
);逐次実行
サブエージェントがコンテキストを引き継ぎながら順番に動作します。
const result = await mainAgent.ask(
'Research → Analyze → Report workflow',
{
useSubAgents: true,
delegation: 'auto',
coordination: 'sequential' // Agents work in dependency order
}
);サブエージェントの設定
専門化された役割
特定の専門分野向けにサブエージェントを設定します。
// Research Specialist
const researcher = await Agent.create({
name: 'ResearchSpecialist',
systemPrompt: 'You conduct thorough research using multiple sources and methodologies.',
knowledge: true, // Access to knowledge base
memory: true, // Remember research context
useTools: true // Use research tools
});
// Content Creator
const creator = await Agent.create({
name: 'ContentCreator',
systemPrompt: 'You create compelling content across different formats and audiences.',
vision: true, // Process visual content
useTools: true // Use content creation tools
});
// Technical Analyst
const analyst = await Agent.create({
name: 'TechnicalAnalyst',
systemPrompt: 'You analyze technical data and provide actionable insights.',
useTools: true // Use analysis tools
});グラフとの統合
サブエージェントは複雑なオーケストレーションのために、グラフワークフローとシームレスに連携します。
import { Agent, Graph } from '@astreus-ai/astreus';
// Create specialized sub-agents
const researcher = await Agent.create({
name: 'ResearchBot',
systemPrompt: 'You conduct thorough research and analysis.',
knowledge: true
});
const writer = await Agent.create({
name: 'WriterBot',
systemPrompt: 'You create compelling content and reports.',
vision: true
});
// Main coordinator with sub-agents
const coordinator = await Agent.create({
name: 'ProjectCoordinator',
systemPrompt: 'You coordinate complex projects using specialized teams.',
subAgents: [researcher, writer]
});
// Create sub-agent aware graph
const projectGraph = new Graph({
name: 'Market Analysis Project',
defaultAgentId: coordinator.id,
subAgentAware: true,
optimizeSubAgentUsage: true
}, coordinator);
// Add tasks with intelligent sub-agent delegation
const researchTask = projectGraph.addTaskNode({
name: 'Market Research',
prompt: 'Research AI healthcare market trends and opportunities',
useSubAgents: true,
subAgentDelegation: 'auto'
});
const reportTask = projectGraph.addTaskNode({
name: 'Executive Report',
prompt: 'Create comprehensive executive report based on research',
dependencies: [researchTask],
useSubAgents: true,
subAgentCoordination: 'sequential'
});
// Execute the graph
const result = await projectGraph.run();グラフのサブエージェント機能
- 自動検出: グラフノードは有益な場合、自動的にサブエージェントを使用します
- コンテキストの引き継ぎ: ワークフローのコンテキストがサブエージェントに流れ、連携が向上します
- パフォーマンス最適化: リアルタイムの監視と自動的な戦略調整
- 柔軟な設定: グラフ設定からの継承を伴う、ノード単位のサブエージェント設定
応用例
コンテンツ制作パイプライン
const contentPipeline = await Agent.create({
name: 'ContentPipeline',
model: 'gpt-4o',
subAgents: [researcher, writer, analyst]
});
const blogPost = await contentPipeline.ask(
'Create a comprehensive blog post about quantum computing applications in finance',
{
useSubAgents: true,
delegation: 'auto',
coordination: 'sequential'
}
);市場調査ワークフロー
const marketResearch = await Agent.create({
name: 'MarketResearchTeam',
model: 'gpt-4o',
subAgents: [researcher, analyst, writer]
});
const report = await marketResearch.ask(
'Analyze the fintech market and create investor presentation',
{
useSubAgents: true,
delegation: 'manual',
coordination: 'parallel',
taskAssignment: {
[researcher.id]: 'Research fintech market trends and competitors',
[analyst.id]: 'Analyze market data and financial projections',
[writer.id]: 'Create compelling investor presentation'
}
}
);レスポンスの型
サブエージェントのメソッドは、操作内容に応じて異なるレスポンス形式を返します。
サブエージェントを使った実行のレスポンス
基本的なサブエージェント実行は、最終的な統合結果を文字列として返します。
const result = await mainAgent.executeWithSubAgents(
"Research renewable energy and create comprehensive report",
[researchAgent, writerAgent],
{ coordination: 'sequential' }
);
// Response: string
"Research complete: Solar and wind energy show 23% growth year-over-year. Report includes market analysis, technology trends, and investment opportunities across 15 regions."タスク委任のレスポンス
タスク委任は、サブエージェントのレスポンスを文字列として返します。
const result = await mainAgent.delegateTask(
"Translate this document to Spanish",
translatorAgent
);
// Response: string
"Documento traducido exitosamente. El contenido ha sido adaptado para audiencia hispanohablante manteniendo el tono profesional original."エージェント連携のレスポンス
複数のエージェントの連携は、タスクと結果のペアの配列を返します。
const results = await mainAgent.coordinateAgents([
{ agent: analyzerAgent, prompt: "Analyze Q4 sales data" },
{ agent: reportAgent, prompt: "Create executive summary" },
{ agent: visualizerAgent, prompt: "Generate performance charts" }
], 'sequential');
// Response structure:
[
{
task: {
agent: analyzerAgent, // IAgent object
prompt: "Analyze Q4 sales data"
},
result: "Q4 analysis complete: Revenue increased 18%, top products identified, seasonal trends mapped."
},
{
task: {
agent: reportAgent,
prompt: "Create executive summary"
},
result: "Executive summary created with key findings: 18% growth driven by product line expansion..."
},
{
task: {
agent: visualizerAgent,
prompt: "Generate performance charts"
},
result: "Performance visualizations generated: 5 charts showing revenue trends, product mix, and regional distribution."
}
]サブエージェントを使ったAgent.ask()のレスポンス
サブエージェントオプションを指定してagent.ask()を使うと、最終的なレスポンス文字列が返されます。
const result = await mainAgent.ask(
"Create market analysis presentation",
{
useSubAgents: true,
delegation: 'auto',
coordination: 'parallel'
}
);
// Response: string
"Market analysis presentation completed with 3 specialized teams: Research team gathered competitor data, Analysis team processed financial metrics (showing 12% market growth), and Content team created 25-slide deck with executive summary."手動タスク割り当てのレスポンス
手動割り当ての場合も、統合結果を文字列として返します。
const result = await coordinatorAgent.ask(
"Develop comprehensive product launch strategy",
{
useSubAgents: true,
delegation: 'manual',
coordination: 'sequential',
taskAssignment: {
[marketResearcher.id]: "Research target market and competitors",
[strategyAnalyst.id]: "Develop go-to-market strategy",
[contentCreator.id]: "Create launch materials and messaging"
}
}
);
// Response: string
"Product launch strategy complete: Target market identified (tech-savvy professionals 25-40), competitive positioning defined (premium quality, mid-tier pricing), go-to-market plan created with 3-phase rollout, and launch materials prepared including website, social media, and press kit."最終更新日: 2026年7月6日
このセクション内
はじめに
実世界のタスクを効果的に解決する自律システムを構築するための、オープンソースAIエージェントフレームワーク。 信頼性の高いAstreusエージェントシステムを構築するために必要なセットアップのパターン、API、実践的な例を学びましょう。
インストール
npm、yarn、pnpmでAstreusをインストールし、必要なNode.jsのバージョンを確認して、フレームワークでAIエージェントを構築するためのローカルプロジェクトを準備します。
クイックスタート
Astreusのドキュメントでクイックスタートについて学び、エージェントシステムを構築するためのセットアップの手引き、APIのパターン、実践的な例を確認しましょう。 信頼性の高いAstreusエージェントシステムを構築するために必要なセットアップのパターン、API、実践的な例を学びましょう。
コンテキスト
Astreusのドキュメントでコンテキストについて学び、エージェントシステムを構築するためのセットアップの手引き、APIのパターン、実践的な例を確認しましょう。 信頼性の高いAstreusエージェントシステムを構築するために必要なセットアップのパターン、API、実践的な例を学びましょう。