基础 Graph
创建简单的工作流图来编排多步骤流程。
快速开始#
克隆完整示例#
最简单的开始方式是克隆完整的示例仓库:
git clone https://github.com/astreus-ai/examples
cd examples/basic-graphs
npm install或仅安装包#
如果你更喜欢从零开始构建:
npm install @astreus-ai/astreus环境配置#
# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.db基础图工作流#
import { Agent, Graph } from '@astreus-ai/astreus';
// Create an agent
const agent = await Agent.create({
name: 'WorkflowAgent',
model: 'gpt-6-astra'
});
// Create a simple sequential graph
const graph = new Graph({
name: 'research-workflow'
}, agent);
// Add tasks with dependencies
const research = graph.addTaskNode({
prompt: 'Research artificial intelligence trends'
});
const summary = graph.addTaskNode({
prompt: 'Summarize the research findings',
dependencies: [research]
});
// Execute the workflow
const results = await graph.run();
// Parse the result and extract the response
if (results.success && results.results[summary]) {
const summaryResult = JSON.parse(results.results[summary]);
console.log(summaryResult.response);
}运行示例#
如果你克隆了仓库:
npm run dev仓库#
完整示例可在 GitHub 上获取:examples/basic-graphs