Vendor-agnostic agent framework abstraction layer - Terraform for AI Agents
Project description
AgentLegatus
Vendor-agnostic agent framework abstraction layer — Terraform for AI Agents.
Switch between AI agent frameworks (LangGraph, AutoGen, CrewAI, Google ADK, AWS Strands, Microsoft Agent Framework) with minimal configuration changes. AgentLegatus provides a unified API, a Roman military hierarchy for orchestrating multi-agent workflows, and built-in benchmarking to compare providers side by side.
Quick Start
# Install core
pip install -e .
# Install with all optional backends
pip install -e ".[all]"
Define and run a workflow
import asyncio
from agentlegatus.core.event_bus import EventBus
from agentlegatus.core.executor import WorkflowExecutor
from agentlegatus.core.state import InMemoryStateBackend, StateManager
from agentlegatus.core.workflow import (
ExecutionStrategy, WorkflowDefinition, WorkflowStep,
)
from agentlegatus.hierarchy.legatus import Legatus
from agentlegatus.providers.mock import MockProvider
from agentlegatus.tools.registry import ToolRegistry
async def main():
event_bus = EventBus()
state_manager = StateManager(InMemoryStateBackend(), event_bus=event_bus)
provider = MockProvider(config={})
executor = WorkflowExecutor(provider, state_manager, ToolRegistry(), event_bus)
workflow = WorkflowDefinition(
workflow_id="hello",
name="Hello Workflow",
version="1.0.0",
provider="mock",
execution_strategy=ExecutionStrategy.SEQUENTIAL,
steps=[
WorkflowStep(step_id="greet", step_type="agent", config={"agent_id": "greeter"}),
],
)
legatus = Legatus(config={}, event_bus=event_bus)
result = await legatus.execute_workflow(workflow, executor=executor, state_manager=state_manager)
print(f"Status: {result.status.value}, Time: {result.execution_time:.3f}s")
asyncio.run(main())
CLI
legatus init --provider mock
legatus apply workflow.yaml
legatus apply workflow.yaml --dry-run
legatus plan workflow.yaml
legatus benchmark workflow.yaml --providers mock,langgraph --iterations 5
legatus switch langgraph
legatus providers
legatus status <workflow-id>
legatus cancel <workflow-id>
Architecture
CLI (legatus)
└── Legatus (Orchestrator)
├── EventBus ──► Observability (OpenTelemetry, Prometheus)
├── StateManager (in-memory / Redis / Postgres)
└── Centurion (Workflow Controller)
├── Sequential / Parallel / Conditional execution
└── Cohort (Agent Group)
└── Agent (Worker)
├── ToolRegistry
└── MemoryManager
Features
- Provider Abstraction —
BaseProviderinterface with runtime switching and state migration via Portable Execution Graphs - Roman Hierarchy — Legatus → Centurion → Cohort → Agent, with sequential, parallel, and conditional execution strategies
- Event-Driven — Unified
EventBuswith subscription, history, correlation/trace ID propagation - State Management — Scoped state (workflow/step/agent/global) with snapshot/restore, backed by in-memory, Redis, or Postgres
- Tool Registry — Register tools once, auto-convert to OpenAI/Anthropic formats, cached per provider
- Memory Abstraction — Short-term (TTL), long-term, episodic, and semantic memory types with Redis and vector store backends
- Benchmark Engine — Run identical workflows across providers, compare latency (p50/p95/p99), cost, tokens, and success rate
- Observability — OpenTelemetry tracing, Prometheus metrics export, structured logging via structlog
- Security — Input sanitization, path traversal prevention, PII detection/redaction, rate limiting, audit logging, HTTPS with cert validation
- Checkpoint & Recovery — Checkpoint workflow state for resumption after failures or timeouts
- Retry Logic — Configurable exponential backoff with max delay capping
Optional Dependencies
pip install -e ".[langgraph]" # LangGraph provider
pip install -e ".[redis]" # Redis state/memory backend
pip install -e ".[postgres]" # Postgres state backend
pip install -e ".[vector]" # ChromaDB vector memory
pip install -e ".[observability]" # OpenTelemetry + Prometheus + structlog
pip install -e ".[dev]" # black, ruff, mypy, isort
pip install -e ".[test]" # pytest, hypothesis, coverage
Configuration
AgentLegatus supports YAML/JSON config files with environment variable overrides:
default_provider: mock
providers:
- name: mock
- name: openai
api_key: ${OPENAI_API_KEY}
state:
backend: memory
memory:
backend: memory
observability:
enable_tracing: false
enable_prometheus: false
Load via code or CLI:
from agentlegatus.config.loader import ConfigLoader
config = ConfigLoader.load("agentlegatus.yaml")
Examples
See the examples/ directory:
| File | Description |
|---|---|
basic_workflow.py |
Sequential workflow execution |
provider_switching.py |
Runtime provider switching with state preservation |
benchmark.py |
Cross-provider benchmarking |
event_monitoring.py |
Event subscription and real-time monitoring |
custom_tools.py |
Tool creation and registration |
state_management.py |
State operations, snapshots, and restore |
Development
# Install dev + test dependencies
pip install -e ".[dev,test]"
# Run all tests (936 tests, 88% coverage)
pytest
# Run by category
pytest tests/unit/
pytest tests/integration/
pytest tests/property/
# Coverage report
pytest --cov=agentlegatus --cov-report=html
# Linting
ruff check agentlegatus/
black --check agentlegatus/
Requirements
- Python 3.10+
- Core: click, pydantic, httpx, rich, pyyaml
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentlegatus-0.1.0.tar.gz.
File metadata
- Download URL: agentlegatus-0.1.0.tar.gz
- Upload date:
- Size: 77.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f732f99b423f95b1507cefe764c27988a2f4e32e33bfd56f074e3c4a0b98bbea
|
|
| MD5 |
c22fbf83b1d8b5ddb5c60a0fbf296c15
|
|
| BLAKE2b-256 |
3f0bec518580c86152d854e5ac760ef8b3c0ed4aff8d16debbc90ce760f37d5c
|
File details
Details for the file agentlegatus-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentlegatus-0.1.0-py3-none-any.whl
- Upload date:
- Size: 97.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10e04acfb525984ae2d3b8553555e6306b016c68a99062041dd1a1a5d9305a8f
|
|
| MD5 |
6e536bdad51d0f900a3cbd3c5934f7d4
|
|
| BLAKE2b-256 |
d96d803d8218c585188b2361a82543a72ac7874d72bedbd3001805eba054fbc7
|