Building Scheduled Workflows in Astreus
Automate AI tasks on schedules. Daily reports, weekly summaries, hourly checks - set it and forget it.
Astreus enables developers to build time-based automated workflows with simple schedule strings and dependency management. This guide shows you how to create workflows that run automatically on your schedule.
Quick Start
Get started by cloning the example repository or installing the package:
Bashgit clone https://github.com/astreus-ai/scheduled-workflows cd scheduled-workflows npm install
Or install directly:
Bashnpm install @astreus-ai/astreus
Create a .env file with your configuration:
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.db
NODE_ENV=development
The database persists workflow state, ensuring tasks continue after restarts.
Creating Your First Agent
Every workflow starts with an agent that handles the AI operations:
TypeScriptconst agent = await Agent.create({ name: 'ContentAgent', model: 'gpt-4o', systemPrompt: 'You are a content creation specialist.' });
The agent encapsulates the AI model and behavior. You can create multiple agents with different capabilities for different tasks.
Building a Workflow Graph
Workflows are represented as graphs with nodes and dependencies:
TypeScriptconst graph = new Graph({ name: 'Quick Test Pipeline', description: 'Test automated workflow with seconds interval', maxConcurrency: 2 }, agent);
The graph manages execution order, concurrency limits, and task dependencies. Setting maxConcurrency prevents overwhelming your API limits or system resources.
Adding Scheduled Tasks
Add task nodes with schedules and dependencies:
TypeScript
The dependsOn array ensures tasks execute in the correct order. If a dependency fails, dependent tasks won't run.
Schedule Format Patterns
Astreus uses human-readable schedule strings:
daily@06:00- Execute daily at 6 AMweekly@monday@09:00- Weekly on Monday at 9 AMmonthly@15@10:00- 15th of each month at 10 AMafter:5s- Delay 5 seconds (testing)after:2h- Delay 2 hoursevery:30m- Repeat every 30 minutes
Use short intervals like after:5s during development for rapid testing, then switch to production schedules.
Running the Workflow
Execute your workflow with a simple call:
TypeScriptconst result = await graph.run();
The run method returns detailed execution results:
TypeScript
You get full visibility into which tasks succeeded, how long they took, and what outputs they produced.
Multi-Step Content Pipeline
Here's a practical example that chains multiple tasks:
TypeScript
This pipeline researches topics at 7 AM, creates drafts at 8 AM, and optimizes them at 9 AM, all automatically.
Testing with Short Intervals
Don't wait hours between test runs. Use short schedules during development:
TypeScript
Using after:5s lets you iterate quickly and catch issues early.
Handling Execution Results
Process workflow results to integrate with other systems:
TypeScript
The results object gives you everything you need to monitor, debug, and respond to workflow outcomes.
Production Deployment
Deploy your workflow as a long-running process:
TypeScript
This setup ensures your workflows continue running and handle shutdown signals gracefully.
Best Practices
Follow these guidelines for reliable workflows:
- Start with
after:5sschedules during development for rapid testing - Use descriptive names for nodes to make debugging easier
- Set appropriate maxConcurrency limits to avoid overwhelming APIs
- Always check result.success before processing outputs
- Use dependsOn to enforce correct task ordering
- Store sensitive configuration in environment variables
- Monitor result.duration to optimize performance
Complete Example
Explore the full implementation at https://github.com/astreus-ai/scheduled-workflows. The repository includes working examples, additional patterns, and production-ready configurations.
Next Steps
Now you can build automated workflows that run on your schedule. Try creating a daily report generator, weekly content summarizer, or hourly data processor. The Astreus API handles the complexity of timing and execution while you focus on the tasks themselves.
This experiment is written for Astreus v0.5.37. Please ensure you are using a compatible version.