Astreus

예약된 워크플로우

간단한 스케줄 문자열과 의존성 관리를 사용하여 시간 기반 자동화 워크플로우를 구축합니다. 안정적인 Astreus 에이전트 시스템을 구축하는 데 필요한 설정 패턴, API, 실용적인 예제를 알아보세요.

간단한 스케줄 문자열과 의존성 관리를 사용하여 시간 기반 자동화 워크플로우를 구축합니다.

빠른 시작

전체 예제 클론하기

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

git clone https://github.com/astreus-ai/examples
cd examples/scheduled-workflows
npm install

또는 패키지만 설치하기

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

npm install @astreus-ai/astreus

환경 설정

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

빠른 테스트 예제 (초 단위)

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

const agent = await Agent.create({
  name: 'ContentAgent',
  model: 'gpt-4o',
  systemPrompt: 'You are a content creation specialist.'
});

const graph = new Graph({
  name: 'Quick Test Pipeline',
  description: 'Test automated workflow with seconds interval',
  maxConcurrency: 2
}, agent);

// 5초 후 실행
const researchNode = graph.addTaskNode({
  name: 'Content Research',
  prompt: 'Research trending topics in AI and technology. Find 3-5 compelling topics for blog content.',
  schedule: 'after:5s'
});

// 10초 후 실행
const creationNode = graph.addTaskNode({
  name: 'Content Creation',
  prompt: 'Based on the research findings, create a short blog post summary on one of the trending topics.',
  schedule: 'after:10s',
  dependsOn: ['Content Research']
});

// 15초 후 실행
const seoNode = graph.addTaskNode({
  name: 'SEO Optimization',
  prompt: 'Optimize the blog post for SEO: add meta description and keywords.',
  schedule: 'after:15s',
  dependsOn: ['Content Creation']
});

// 20초 후 실행
const publishNode = graph.addTaskNode({
  name: 'Content Publishing',
  prompt: 'Create a social media post for the optimized content.',
  schedule: 'after:20s',
  dependsOn: ['SEO Optimization']
});

console.log('Starting scheduled workflow test...');
console.log('Tasks will run at:');
console.log('- Research: 5 seconds from now');
console.log('- Creation: 10 seconds from now');
console.log('- SEO: 15 seconds from now');
console.log('- Publishing: 20 seconds from now\n');

// 그래프를 실행하고 결과 가져오기
const result = await graph.run();

// 실행 결과 표시
console.log('\n=== Workflow Execution Results ===');
console.log('Success:', result.success);
console.log(`Completed: ${result.completedNodes} tasks`);
console.log(`Failed: ${result.failedNodes} tasks`);
console.log(`Duration: ${result.duration}ms`);

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

// 오류 확인
if (result.errors && Object.keys(result.errors).length > 0) {
  console.log('\n=== Errors ===');
  for (const [nodeId, error] of Object.entries(result.errors)) {
    console.log(`[${nodeId}]: ${error}`);
  }
}

console.log('\n✅ Scheduled workflow test completed!');

일일 콘텐츠 파이프라인 (프로덕션)

실제 일일 스케줄을 사용하는 프로덕션 환경에서는:

// Schedule format examples:
// 'daily@06:00' - Every day at 6 AM
// 'weekly@monday@09:00' - Every Monday at 9 AM  
// 'monthly@15@10:00' - 15th of every month at 10 AM
// 'after:5s' - After 5 seconds (for testing)
// 'after:2h' - After 2 hours
// 'every:30m' - Every 30 minutes

const researchNode = graph.addTaskNode({
  name: 'Content Research',
  prompt: 'Research trending topics in AI and technology.',
  schedule: 'daily@06:00'
});

예제 실행하기

저장소를 클론했다면:

npm run dev

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

npx tsx index.ts

저장소

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

마지막 업데이트: 2026년 7월 6일