그래프 + 서브 에이전트

정교한 계층적 작업 분배를 위해 그래프 워크플로우와 서브 에이전트 조율을 결합합니다.

빠른 시작#

전체 예제 클론하기#

가장 쉬운 시작 방법은 전체 예제 저장소를 클론하는 것입니다:

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

또는 패키지만 설치하기#

처음부터 직접 구축하려면:

bash
npm install @astreus-ai/astreus

환경 설정#

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

그래프 + 서브 에이전트 통합#

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

// 전문화된 서브 에이전트 생성
const researcher = await Agent.create({
  name: 'ResearchSpecialist',
  model: 'gpt-6-astra',
  systemPrompt: 'You conduct thorough research and gather comprehensive information.',
  knowledge: true,
  memory: true
});

const analyst = await Agent.create({
  name: 'DataAnalyst', 
  model: 'gpt-6-astra',
  systemPrompt: 'You analyze data and provide actionable insights.',
  useTools: true
});

const writer = await Agent.create({
  name: 'ContentWriter',
  model: 'claude-sonnet-5',
  systemPrompt: 'You create compelling, well-structured content.',
  vision: true
});

// 서브 에이전트를 가진 메인 코디네이터 에이전트 생성
const coordinator = await Agent.create({
  name: 'ProjectCoordinator',
  model: 'gpt-6-astra',
  systemPrompt: 'You coordinate complex projects using specialized sub-agents.',
  subAgents: [researcher, analyst, writer]
});

// 서브 에이전트 인식 그래프 생성
const projectGraph = new Graph({
  name: 'Market Analysis Project',
  subAgentAware: true,
  maxConcurrency: 2
}, coordinator);

// 서브 에이전트를 활용하는 작업 추가
const researchTask = projectGraph.addTaskNode({
  name: 'Market Research',
  prompt: 'Research the AI healthcare market, including key players, market size, and growth trends',
  useSubAgents: true,
  subAgentDelegation: 'auto'
});

const analysisTask = projectGraph.addTaskNode({
  name: 'Data Analysis',
  prompt: 'Analyze the research data and identify key opportunities and challenges',
  dependencies: [researchTask],
  useSubAgents: true,
  subAgentCoordination: 'parallel'
});

const reportTask = projectGraph.addTaskNode({
  name: 'Executive Report',
  prompt: 'Create a comprehensive executive report with recommendations',
  dependencies: [analysisTask],
  useSubAgents: true
});

// 지능적인 서브 에이전트 조율로 그래프 실행
const result = await projectGraph.run();

// 결과 표시
console.log('Project completed:', result.success);
console.log(`Tasks completed: ${result.completedNodes}/${result.completedNodes + result.failedNodes}`);
console.log(`Duration: ${result.duration}ms`);

// 작업 결과 표시
if (result.results) {
  console.log('\nTask Results:');
  for (const [nodeId, nodeResult] of Object.entries(result.results)) {
    console.log(`\n${nodeId}:`, nodeResult);
  }
}

// 마지막 작업에서 최종 보고서 가져오기
const finalReport = result.results?.[reportTask];
if (finalReport) {
  console.log('\n=== Final Executive Report ===');
  console.log(finalReport);
}

예제 실행하기#

저장소를 클론했다면:

bash
npm run dev

처음부터 구축했다면, 위 코드로 index.ts 파일을 만들고 다음을 실행하세요:

bash
npx tsx index.ts

저장소#

전체 예제는 GitHub에서 확인할 수 있습니다: examples/graph-sub-agents