Agent Substrate Documentation

Agent Substrate is an async-first Python runtime framework engineered for production AI agents that call tools, maintain durable memory across sessions, pause with zero server cost, and survive process crashes without losing state or duplicate tool charges.

Most agent frameworks focus on the initial prototype: wrapping an LLM in a simple prompt loop. Agent Substrate is built for day-2 production operations: deterministic replay, PostgreSQL WAL persistence, budget circuit breakers, and zero-cost hibernation.


Getting Started

▶ Quick · 5 Min

Python 3.11+
Install & Run Quickstart

Install the lightweight core runtime and launch your first resilient ReAct agent with automatic token tracking.

$pip install agent-substrate

▶ Guided · 10 Min

Full Stack
PostgreSQL WAL & Hibernation

Configure append-only event journaling, zero-cost sleep during approval gates, and deterministic failover replays.

PostgreSQL WAL · 0 MB SleepDurable

Core Operational Capabilities

1. Durable Write-Ahead Logging (WAL)

Every message, tool invocation request, and state delta commits to an append-only PostgreSQL log before execution. If a worker pod crashes or restarts mid-session, it hot-replays from the last checkpoint in <10ms. Downstream tools use idempotency keys to guarantee that external actions (e.g. charging a card or sending an email) never trigger twice.

2. Zero-Cost Process Hibernation

When an agent waits for human sign-off, a customer reply, or a scheduled cron trigger, keeping the container resident wastes memory and compute. Agent Substrate serializes the execution pointer to PostgreSQL and frees the worker memory entirely (0 MB RAM / 0% CPU). When the resuming webhook arrives, the agent resumes execution instantly.

3. Loop Ceilings & Spend Governance

Production agents risk entering infinite reasoning loops or accumulating unexpected token bills. Agent Substrate enforces hard per-session ceilings on total dollar cost, token consumption, and execution step count. If an agent exceeds these bounds, the circuit breaker halts execution and notifies your alerting system.

4. Open FastMCP Tool Ecosystem

Integrate any external database, SaaS platform, or internal microservice via the Model Context Protocol (FastMCP). Substrate dynamically parses tool definitions from MCP servers and exposes them to reasoning loops with strict Pydantic parameter validation.


Platform Subsystem Matrix

The runtime is structured into decoupled layers, ensuring that changes to storage or telemetry do not impact agent logic:

LayerSubsystem ComponentsOperational ResponsibilitiesReference
L0 KernelIdentity Schemas, Content BlocksImmutable AgentId/ThreadId, typed content envelopes, zero third-party dependenciesKernel API
L1 ReasoningReAct Loop, Supervisor SwarmsDeterministic step execution, agent-to-agent delegation, token sliding-window compactionReAct Agents
L1 SafetyGuardrail Tripwires, Circuit BreakersRegex tripwires, LLM safety evaluators, spend limit bounds, step quotasGuardrails
L2 StoragePostgreSQL WAL, Redis PubSubAppend-only event store, session checkpointing, atomic optimistic lockingPersistence
L2 CapabilitiesFastMCP Bridge, Python SandboxModel Context Protocol gateway, sandboxed code execution, Qdrant vector memoryTool Chaining
L3 ServingHuman-in-the-Loop, SSE StreamingWebhook pause/resume, token-by-token streaming, golden trajectory evalsHibernation

Substrate Layer Stack


Ecosystem Compatibility

Agent Substrate is vendor-agnostic and connects seamlessly with your existing AI stack:

  • Model Providers: OpenAI (GPT-4o, o3-mini), Anthropic (Claude 3.7 Sonnet), Google Gemini (2.0 Flash / Pro), DeepSeek (R1, V3), and local Ollama instances.
  • Data & Cache: PostgreSQL 14+, Redis 7+, Qdrant Vector Search, SeaweedFS Object Storage.
  • Protocols & Standards: Model Context Protocol (FastMCP), OpenTelemetry (OTel Traces & Spans).

Next Steps

Explore the detailed implementation guides:

Was this page helpful?