A production-grade distributed workflow execution engine designed to orchestrate complex agentic workflows with built-in fault tolerance, retries, and scalability.
This project provides a robust framework for executing workflows composed of interdependent nodes (agents) in a distributed manner. It includes:
- Workflow DAG Execution: Define workflows as directed acyclic graphs (DAGs) with dependencies
- Fault Tolerance: Automatic retry mechanisms and graceful failure handling
- Distributed Task Processing: Async task queue integration using Redis
- Persistent State: PostgreSQL-backed workflow and execution tracking
- RESTful API: FastAPI-based HTTP endpoints for workflow management
- Database Migrations: Alembic for schema versioning and migrations
The engine consists of the following components:
- Engine: Core orchestration logic for executing workflows
- Worker: Distributed task processor for executing individual nodes
- API: FastAPI application for workflow management and monitoring
- Database: SQLAlchemy ORM with async PostgreSQL support
- Queue: Redis-backed distributed task queue (arq)
- Python 3.11 or higher
- PostgreSQL 12+
- Redis 6.0+
- Poetry (for dependency management)
git clone https://github.com/yasaman138/agentic-workflow-engine.git
cd "agentic-workflow-engine"poetry installThis will install all dependencies specified in pyproject.toml, including:
- FastAPI and Uvicorn
- SQLAlchemy with async PostgreSQL support
- Arq for distributed task processing
- Alembic for database migrations
- Development tools (pytest, mypy, ruff)
Create a .env file in the project root:
DATABASE_URL=postgresql+asyncpg://postgres:supersecretpassword@localhost:5432/workflow_engine
REDIS_URL=redis://localhost:6379
LOG_LEVEL=INFOdocker-compose up -dThis will start:
- PostgreSQL database (port 5432)
- Redis server (port 6379)
poetry run alembic upgrade headpoetry run uvicorn app.api:app --reloadThe API will be available at http://localhost:8000
poetry run python -m app.workerThe worker will process tasks from the Redis queue.
Workflows are defined as JSON DAGs. Use the API endpoints to:
- Create workflows
- Trigger executions
- Monitor progress
- Retrieve results
Example DAG structure:
{
"nodes": [
{"id": "node1", "type": "agent"},
{"id": "node2", "type": "agent"}
],
"edges": [
{"source": "node1", "target": "node2"}
]
}Run the test suite using pytest:
poetry run pytestWith coverage:
poetry run pytest --cov=appTest files include:
tests/test_engine.py: Engine logic teststests/test_worker.py: Worker process tests
The project uses:
- Ruff: Fast Python linter and formatter
- MyPy: Static type checking with strict mode enabled
- Pytest: Testing framework with async support
Run linting and type checking:
poetry run ruff check .
poetry run mypy appFormat code:
poetry run ruff format .pyproject.toml: Project metadata and dependenciespytest.ini: Pytest configurationalembic.ini: Database migration configurationdocker-compose.yml: Local development servicesDockerfile: Container image definition
Database schemas are managed using Alembic. To create a new migration:
poetry run alembic revision --autogenerate -m "description"Apply migrations:
poetry run alembic upgrade headEnsure PostgreSQL and Redis are running:
docker-compose psReset the database:
docker-compose down -v
docker-compose up -d
poetry run alembic upgrade headEnsure the project root is in your Python path:
poetry run python -c "import app".
├── alembic/ # Database migrations
│ ├── versions/ # Migration files
│ ├── env.py # Migration environment
│ └── script.py.mako # Migration template
├── app/ # Main application
│ ├── __init__.py # Package initialization
│ ├── api.py # FastAPI application
│ ├── database.py # Database configuration
│ ├── engine.py # Workflow execution engine
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic schemas
│ └── worker.py # Task worker
├── scripts/ # Utility scripts
│ └── entrypoint.sh # Docker entrypoint
├── tests/ # Test suite
│ ├── conftest.py # Pytest configuration
│ ├── test_engine.py # Engine tests
│ └── test_worker.py # Worker tests
├── docker-compose.yml # Docker services configuration
├── Dockerfile # Container image
├── pyproject.toml # Poetry project configuration
├── pytest.ini # Pytest configuration
└── alembic.ini # Alembic configuration
- Create a feature branch from
main - Make changes and ensure tests pass
- Run linting and type checks
- Submit a pull request