Skip to main content

Anchor

The PostgreSQL-Authoritative Durable Execution Engine for AI Agent Workflows.

Eliminate lost state and duplicate API calls when executing multi-step LLM agent pipelines. Anchor guarantees atomic two-phase tool journaling, monotonic epoch fencing, and sub-second crash recovery.

Apache 2.0 License PyPI version Python 3.12

Author & System Architect: Aditya Nemalinkedin.com/in/adityaxnemaGitHub Repository


🚀 Quickstart (Under 60 Seconds)

No API keys, no cloud subscriptions, no external services required to get started.

1. Install the Python SDK

pip install anchor-runtime

2. Boot Local Cluster & UI

# 🌟 Recommended (1-Click Launch & Auto-Browser):
anchor dev             # On Windows if PATH is not configured: python -m anchor.cli dev

Scaffolds workspace, boots PostgreSQL 16, Redis 7, API Server (:8000), 3 worker replicas, and auto-opens the Operator Console UI at http://localhost:3000.

Alternative manual boot: anchor init (Windows: python -m anchor.cli init) followed by docker compose up -d.

3. Write & Run Your Agent (app.py)

Create app.py:

import anchor, json

# 1. Custom Tool 0: Fetch Customer Data (Retry-Safe)
@anchor.tool(safety="retry_safe", naturally_idempotent=True)
def fetch_customer(customer_id: str) -> dict:
    return {"id": customer_id, "email": "aditya@anchor.dev", "tier": "VIP"}

# 2. Custom Tool 1: Dispatch Email Notification (Unsafe Side-Effect)
@anchor.tool(safety="unsafe")
def send_welcome_email(email: str, tier: str) -> dict:
    return {"status": "sent", "to": email, "tier": tier}

# 3. Multi-Tool Durable Agent Workflow
@anchor.agent(name="onboarding_agent")
def onboarding_agent(ctx: anchor.StepContext):
    customer = yield anchor.ToolCall("fetch_customer", {"customer_id": ctx.input["customer_id"]})
    email_res = yield anchor.ToolCall("send_welcome_email", {"email": customer["email"], "tier": customer["tier"]})
    yield anchor.Done({"status": "completed", "customer": customer, "email": email_res})

# 4. Trigger & Submit to Cluster
if __name__ == "__main__":
    result = anchor.run("onboarding_agent", input={"customer_id": "cust_99"})
    print(json.dumps(result, indent=2))

Run python app.py. anchor.run() serializes the workflow AST and submits it to PostgreSQL. Cluster workers claim the run, execute steps, and log atomic two-phase tool journals. Inspect live execution at http://localhost:3000!


💡 Why Choose Anchor?

Current AI agent frameworks (LangGraph, CrewAI) rely on in-memory buffers or naive Redis checkpoints — causing process crashes to re-execute non-idempotent tool calls, double-charge payment APIs, and corrupt database state.

Meanwhile, legacy enterprise orchestrators (Temporal, AWS Step Functions) require hosting massive external clusters ($5,000+/mo cloud tax) built for microservices, not non-deterministic Python LLM loops.

Anchor fills this void as a lightweight, PostgreSQL-authoritative engine embedding atomic two-phase tool journaling (INTENT / RESULT) and monotonic epoch fencing (AN001) to guarantee zero duplicate side-effects and sub-second recovery natively in SQL.

📊 Competitive Architecture Comparison Matrix

Feature Anchor Runtime LangGraph / CrewAI Temporal / Step Functions
State Authority PostgreSQL 16 Engine (FOR UPDATE SKIP LOCKED) Volatile Memory / Redis Checkpoints Dedicated Cassandra / MySQL Cluster
Infrastructure Tax $0/mo (Runs in existing DB) $0/mo (Unsafe) $5,000+/mo (Massive External Cluster)
Two-Phase Side-Effect Guard Atomic INTENT / RESULT Journal ❌ Duplicate API Calls ⚠️ Activity Heartbeats
Monotonic Epoch Fencing Database Constraint (AN001) ❌ Split-Brain Risk ❌ Application-Level
SIGKILL Recovery Time P50 < 3.1s ❌ Process Crash Data Loss ⚠️ 10s+ Timeout Window
Developer API Native Python Generators Complex Graph State Handoffs Multi-File SDK Boilerplate

💰 Financial ROI & Execution Safety

When AI agents execute multi-step tasks — searching database records, calling third-party APIs, or processing payments — server crashes normally result in lost progress and double-billing. Anchor acts as an immutable flight recorder: every step is saved before it runs, so if a server dies, another takes over instantly with zero wasted credits.

  • Financial Savings Analysis: On 1,000,000 multi-step LLM requests per month with a 2% node crash rate, unmanaged retries cost over $12,400/mo in duplicate prompt tokens. Anchor's step-level result cache reduces wasted token charges to $0.
  • Idempotent Side-Effect Guarding: If a worker process is terminated by Kubernetes SIGKILL while calling a payment endpoint or database mutation, Anchor checks the TOOL_INTENT sequence ID on recovery to prevent duplicate charges or corrupt row insertions.

🏗️ Deep Architectural Intricacies & System Invariants

Anchor enforces mathematical correctness through five formal SQL invariants verified continuously by an automated chaos harness:

1. Database-Authoritative State Engine

All run ownership, sequence allocation, and lease renewals occur inside single PostgreSQL transactions using SELECT ... FOR UPDATE SKIP LOCKED CTEs. No component outside the database is ever authoritative about who owns an agent run.

2. Two-Phase Tool Intent Journaling

Before a side-effect tool call is executed, Anchor writes a TOOL_INTENT record. Upon completion, it commits TOOL_RESULT. On crash recovery, replayed steps load cached results in <5ms without executing side effects a second time.

3. Monotonic Epoch Fencing (AN001_FENCED_WRITE)

Every worker lease renewal or run claim increments the run's monotonic epoch token. Delayed writes from a zombie worker with a stale epoch are blocked at the database constraint boundary with AN001_FENCED_WRITE.

4. Explicit Tool Safety Spectrum

  • retry_safe: Read-only or naturally idempotent tools. Safe to re-execute immediately on worker crash recovery.
  • reconcilable: Side-effecting tools accepting idempotency keys. Anchor queries external system state before re-running.
  • unsafe: Non-idempotent side effects (e.g., sending emails or wire transfers). If a crash lands in the uncertainty window, Anchor halts the run to the needs_review queue for human approval instead of guessing.

5. Automated Adversarial Chaos Harness

An integrated chaos harness continuously injects process SIGKILL signals against active worker nodes and runs automated SQL assertions (I1I5) after every test, proving zero duplicate tool calls and zero stranded runs under load.


🛠️ Repository Layout

Anchor/
├── anchor/                      # Python Core SDK & Engine Daemon
│   ├── api/                     # FastAPI Router & Endpoint Definitions
│   ├── core/                    # PostgreSQL Protocol Logic, Fencing & Replay
│   ├── chaos/                   # Automated Chaos Harness & SQL Invariant Asserter
│   └── worker/                  # Worker Claim Loop & Process Lifecycle
├── web/                         # Production Next.js 14 Operator Console UI
├── demo-site/                   # Standalone Interactive Demo & Scaffold Site
├── ops/
│   ├── compose/                 # Production Docker Compose Stack & Dockerfiles
│   └── migrations/              # Alembic DDL Migrations (001_foundation to 006_chaos)
└── pyproject.toml               # Python Package Spec (anchor-runtime)

Architecture

An end-to-end FAANG-level architectural breakdown of the Anchor Durable Execution Engine:

                                    ┌───────────────────────┐
                                    │    Client SDK / API   │
                                    │  (POST /api/runs)     │
                                    └───────────┬───────────┘
                                                │
                                                ▼
                                    ┌───────────────────────┐
                                    │   FastAPI Daemon      │
                                    │   (Stateless Router)  │
                                    └───────────┬───────────┘
                                                │
                                                ▼
  ┌───────────────────────────────────────────────────────────────────────────────────┐
  │                           PostgreSQL 16 Engine Core                               │
  │  ┌───────────────────────┐   ┌───────────────────────┐   ┌─────────────────────┐  │
  │  │  SELECT FOR UPDATE    │   │ Two-Phase Tool        │   │ AN001 Epoch Fencing │  │
  │  │  SKIP LOCKED Queue    │   │ INTENT/RESULT Journal │   │ Monotonic Triggers  │  │
  │  └───────────────────────┘   └───────────────────────┘   └─────────────────────┘  │
  └─────────────────────────────────────▲─────────────────────────────────────────────┘
                                        │
           ┌────────────────────────────┼────────────────────────────┐
           │                            │                            │
  ┌────────┴────────┐          ┌────────┴────────┐          ┌────────┴────────┐
  │ Worker Replica  │          │ Worker Replica  │          │ Worker Replica  │
  │  (Process A)    │          │  (Process B)    │          │  (Process C)    │
  └─────────────────┘          └─────────────────┘          └─────────────────┘

1. Database-Authoritative State Engine (Zero External Broker Tax)

  • Mechanism: Rather than relying on external distributed orchestrators (Temporal, AWS Step Functions) or volatile brokers (Redis, RabbitMQ), Anchor delegates run ownership, sequence allocation, and lease renewals exclusively to PostgreSQL 16.
  • Concurrency: Workers claim unassigned or expired runs using SELECT ... FOR UPDATE SKIP LOCKED CTEs. This guarantees atomicity under high-throughput parallel worker fleets without lock contention or double-claiming.

2. Two-Phase Tool Intent Journaling (TOOL_INTENT $\rightarrow$ TOOL_RESULT)

  • Protocol: Every side-effecting tool invocation (@anchor.tool) undergoes a two-phase transactional commit protocol:
    1. Phase 1 (TOOL_INTENT): Pre-execution intent is written to PostgreSQL with a deterministic, canonical idempotency hash.
    2. Execution: The tool function runs (e.g. calling an external HTTP API or processing a payment).
    3. Phase 2 (TOOL_RESULT): Post-execution result is committed to the journal.
  • SIGKILL Fault Tolerance: If a worker process is terminated by Kubernetes SIGKILL during tool execution, recovery workers inspect the TOOL_INTENT journal ID and execute the declared tool policy (retry_safe, reconcilable, unsafe), preventing duplicate charges or corrupt row mutations.

3. Monotonic Epoch Fencing (AN001_FENCED_WRITE)

  • Constraint Layer: Every lease acquisition or renewal increments the run's monotonic epoch integer token.
  • Zombie Worker Shield: If a worker experiences a long GC pause or network partition, another worker claims the run and increments the epoch. Delayed writes from the stale worker are rejected at the database trigger boundary with AN001_FENCED_WRITE, preventing split-brain state corruption.

4. Continuous Chaos Invariant Audit Suite

An integrated, continuous chaos harness injects hard process terminations (SIGKILL) against active worker nodes and executes 5 automated SQL invariant assertions (I1I5) after every test run:

  • I1 (Idempotency): COUNT(duplicate_side_effects) == 0
  • I2 (Log Monotonicity): Append-only event sequence integrity.
  • I3 (Single Writer): Epoch-fenced single-active-writer guarantee.
  • I4 (Terminal Reachability): All runs reach deterministic terminal states (completed, failed, needs_review).
  • I5 (Replay Determinism): Step replays reconstruct full generator state from journal logs in <5ms.

📄 License & Commercial Rights

Anchor is open-source software licensed under the Apache License 2.0. You are free to use, modify, distribute, and embed Anchor in commercial products without copyleft restrictions.

Author & Creator: Aditya Nema
Connect on LinkedIn: linkedin.com/in/adityaxnema
GitHub Repository: github.com/n43ms/Anchor

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anchor_runtime-1.4.8.tar.gz (671.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anchor_runtime-1.4.8-py3-none-any.whl (218.6 kB view details)

Uploaded Python 3

File details

Details for the file anchor_runtime-1.4.8.tar.gz.

File metadata

  • Download URL: anchor_runtime-1.4.8.tar.gz
  • Upload date:
  • Size: 671.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for anchor_runtime-1.4.8.tar.gz
Algorithm Hash digest
SHA256 dd9c83d44ce147e8f188b0cc431936d90c796ad9f5b6555fcdb654fc3b7541ab
MD5 e571fba658c5ffeeb33c1ec0af98d695
BLAKE2b-256 e8d2dc47d709de295009dfa949ef368cb736c60603d43b0eac2321351dbd6759

See more details on using hashes here.

File details

Details for the file anchor_runtime-1.4.8-py3-none-any.whl.

File metadata

  • Download URL: anchor_runtime-1.4.8-py3-none-any.whl
  • Upload date:
  • Size: 218.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for anchor_runtime-1.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e87ae04822bf0b3238cb2e412a75c59b6b389c18e1887d5391340e883dd84436
MD5 7745ad91b7da0ce8154d81ea2ecddef6
BLAKE2b-256 7f8b733c545a5e114407d45ad74b66c47d2eec77de514919b02ec02d9ea04019

See more details on using hashes here.

Release history Release notifications | RSS feed

1.5.6

2 files

1.5.4

2 files

1.5.3

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

This release

1.4.8 This release

2 files

1.4.7

2 files

1.4.6

2 files

1.4.5

2 files

1.4.4

2 files

1.4.3

2 files

1.4.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page