Basic Graphs

Create simple workflow graphs to orchestrate multi-step processes.

Quick Start#

Clone the Complete Example#

The easiest way to get started is to clone the complete example repository:

bash
git clone https://github.com/astreus-ai/examples
cd examples/basic-graphs
npm install

Or Install Package Only#

If you prefer to build from scratch:

bash
npm install @astreus-ai/astreus

Environment Setup#

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

Basic Graph Workflow#

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

// Create an agent
const agent = await Agent.create({
  name: 'WorkflowAgent',
  model: 'gpt-4o'
});

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

Running the Example#

If you cloned the repository:

bash
npm run dev

Repository#

The complete example is available on GitHub: examples/basic-graphs