复杂工作流

使用高级编排模式构建复杂的多智能体工作流。

快速开始#

克隆完整示例#

最简单的开始方式是克隆完整的示例仓库:

bash
git clone https://github.com/astreus-ai/examples
cd examples/complex-workflows
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, Graph } from '@astreus-ai/astreus';

// Create specialized agents
const researcher = await Agent.create({
  name: 'Researcher',
  model: 'gpt-6-astra',
  systemPrompt: 'You research topics thoroughly.'
});

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

// Create workflow pipeline
const pipeline = new Graph({
  name: 'content-pipeline'
}, researcher);

// Define workflow steps
const research = pipeline.addTaskNode({
  prompt: 'Research AI trends in 2024',
  agentId: researcher.id
});

const article = pipeline.addTaskNode({
  prompt: 'Write an article based on the research',
  agentId: writer.id,
  dependencies: [research]
});

// Execute the workflow
const results = await pipeline.run();

// Parse the result and extract the response
if (results.success && results.results[article]) {
  const articleResult = JSON.parse(results.results[article]);
  console.log(articleResult.response);
}

运行示例#

如果你克隆了仓库:

bash
npm run dev

仓库#

完整示例可在 GitHub 上获取:examples/complex-workflows