Alt Ajanlar

Koordinasyon içinde çalışan özelleşmiş ajanlarla akıllı görev devri

Genel Bakış#

Alt Ajanlar (Sub-Agents), bir ana ajanın görevleri özelleşmiş alt ajanlara akıllıca devrettiği sofistike çoklu ajan koordinasyonunu mümkün kılar. Her alt ajanın kendi uzmanlığı, yetenekleri ve rolü vardır; tek bir ajan için zorlayıcı olacak karmaşık iş akışlarını tamamlamak üzere birlikte çalışırlar.

Yeni: Alt Ajanlar artık Graph iş akışlarıyla sorunsuz biçimde entegre olur ve karmaşık iş akışı orkestrasyon sistemleri genelinde hiyerarşik görev dağıtımını mümkün kılar.

Alt Ajanlar Oluşturma#

Alt ajanlar bağımsız olarak oluşturulur ve ardından bir ana koordinatör ajana bağlanır:

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

// Create specialized sub-agents
const researcher = await Agent.create({
  name: 'ResearcherBot',
  model: 'gpt-6-astra',
  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-6-astra',
  systemPrompt: 'You are a skilled content writer who creates engaging, well-structured content.',
  vision: true
});

const analyst = await Agent.create({
  name: 'AnalystBot', 
  model: 'gpt-6-astra',
  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-6-astra',
  systemPrompt: 'You coordinate complex tasks between specialized sub-agents.',
  subAgents: [researcher, writer, analyst]
});

Devir Stratejileri#

Otomatik Devir#

Ana ajan, görevleri analiz edip en uygun şekilde atamak için LLM zekasını kullanır:

typescript
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
  }
);

Görev Analizi#

Ana ajan, karmaşık görevi LLM akıl yürütmesiyle analiz eder.

Ajan Eşleştirme#

Her alt ajanın yeteneklerini ve uzmanlık alanlarını değerlendirir.

Optimal Atama#

En uygun ajanlar için belirli alt görevler oluşturur.

Koordineli Yürütme#

Yürütme akışını ve sonuç birleştirmeyi yönetir.

Manuel Devir#

Belirli görevleri, ajan kimliklerini kullanarak açıkça belirli ajanlara atayın:

typescript
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'
    }
  }
);

Sıralı Devir#

Alt ajanlar sırayla çalışır ve önceki sonuçların üzerine inşa eder:

typescript
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
  }
);

Koordinasyon Kalıpları#

Paralel Yürütme#

Alt ajanlar maksimum verimlilik için eş zamanlı çalışır:

typescript
const result = await mainAgent.ask(
  'Multi-faceted analysis task',
  {
    useSubAgents: true,
    delegation: 'auto',
    coordination: 'parallel'  // All agents work concurrently
  }
);

Sıralı Yürütme#

Alt ajanlar, bağlam aktarımıyla belirli bir sırada çalışır:

typescript
const result = await mainAgent.ask(
  'Research → Analyze → Report workflow',
  {
    useSubAgents: true,
    delegation: 'auto', 
    coordination: 'sequential'  // Agents work in dependency order
  }
);

Alt Ajan Yapılandırması#

Özelleşmiş Roller#

Alt ajanları belirli uzmanlık alanları için yapılandırın:

typescript
// 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
});

Graph Entegrasyonu#

Alt Ajanlar, karmaşık orkestrasyon için Graph iş akışlarıyla sorunsuz biçimde çalışır:

typescript
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();

Graph Alt Ajan Özellikleri#

  • Otomatik Algılama: Graph düğümleri, faydalı olduğunda alt ajanları otomatik olarak kullanır
  • Bağlam Aktarımı: İş akışı bağlamı, daha iyi koordinasyon için alt ajanlara aktarılır
  • Performans Optimizasyonu: Gerçek zamanlı izleme ve otomatik strateji ayarı
  • Esnek Yapılandırma: Graph yapılandırmasından devralınan, düğüm başına alt ajan ayarları

Gelişmiş Örnekler#

İçerik Üretim Hattı#

typescript
const contentPipeline = await Agent.create({
  name: 'ContentPipeline',
  model: 'gpt-6-astra',
  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'
  }
);

Pazar Araştırması İş Akışı#

typescript
const marketResearch = await Agent.create({
  name: 'MarketResearchTeam',
  model: 'gpt-6-astra',
  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'
    }
  }
);

Yanıt Tipleri#

Alt ajan metodları, işleme bağlı olarak farklı yanıt biçimleri döndürür.

Alt Ajanlarla Yürütme Yanıtı#

Temel alt ajan yürütmesi, nihai birleşik sonucu bir string olarak döndürür:

typescript
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."

Görev Devri Yanıtı#

Görev devri, alt ajanın yanıtını bir string olarak döndürür:

typescript
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."

Ajan Koordinasyonu Yanıtı#

Birden fazla ajanı koordine etmek, bir görev-sonuç çifti dizisi döndürür:

typescript
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."
  }
]

Alt Ajanlarla Agent.ask() Yanıtı#

Alt ajan seçenekleriyle agent.ask() kullanmak, nihai yanıt string'ini döndürür:

typescript
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."

Manuel Görev Ataması Yanıtı#

Manuel atama da birleşik sonuçları içeren bir string döndürür:

typescript
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."