Skip to main content

A minimal, local-first orchestration engine for AI agents: cyclic state graphs executed by supersteps (Pregel/BSP).

Project description

Sanctum

CI PyPI coverage license: MIT python

Where agents are summoned, bound, and set to work — a minimal, local-first orchestration engine for cyclic state graphs.

Sanctum models multi-agent orchestration as a ritual of invocation: knowledge lives in the Grimoire (tools), the Sanctum prepares and controls the ritual (the engine), entities are summoned (agents), and all of them cooperate over a shared energy — the Aether (state) — until a result is manifested. Beneath the metaphor sits a precise execution model: a cyclic state graph run by supersteps (Pregel/BSP), where nodes execute in parallel, return partial state deltas merged through per-channel reducers, and conditional edges close the loops that make agentic behavior (think → act → observe → …) possible. The core is pure Python standard library — no proprietary APIs, no mandatory dependencies — designed to run entirely on local models.

Documentation · Getting started · Comparison with LangGraph / n8n / ADK · Design document

The self-contained trace viewer (illustration of render_trace output)

Features

Cyclic state graphs BSP supersteps, static fan-out, conditional edges, cycles bounded by recursion_limit — not a DAG
Deterministic state Per-Conduit reducers applied in Sigil insertion order; identical runs, even under parallelism
Local-first Oracles Ollama (native & /v1), llama-server, vLLM, LM Studio, in-process GGUF — never a proprietary API in the core
Robust tool-calling Malformed JSON repaired, unknown Spells corrected conversationally, prompted fallback for models without tools
Seals & time-travel JSON checkpoints per superstep (memory/SQLite/Postgres), resume, interrupt() human-in-the-loop, replay from any Seal
Streaming Omens Typed, timestamped events; combinable modes; live tokens from inside a Sigil
Resilience policies Per-Sigil timeout, retries with backoff+jitter, fallback Sigils reading __errors__
Wards middleware Transform or veto deltas, observe every event: audit JSONL, usage tally, redaction
Local tracing One-file HTML viewer, zero external requests: python -m sanctum.trace render run.sanctum-trace.json
Zero-dependency core Python stdlib only; everything else is an optional extra

Quickstart

pip install sanctum-engine
from sanctum import END, Ritual

ritual = Ritual()
ritual.add_sigil("cleanse", lambda aether: {"text": aether["text"].strip()})
ritual.add_sigil("transmute", lambda aether: {"text": aether["text"].upper()})
ritual.set_entry_point("cleanse")
ritual.add_edge("cleanse", "transmute")
ritual.add_edge("transmute", END)

rite = ritual.compile()
print(rite.invoke({"text": "  fiat lux  "}))
# {'text': 'FIAT LUX'}

Summoning an Entity

summon() builds the canonical ReAct loop (oracle → spells → oracle → … → END) entirely on the public primitives:

import asyncio
from sanctum import Tome, spell, summon
from sanctum.oracle.ollama import OllamaOracle   # pip install "sanctum-engine[ollama]"

@spell
def word_count(text: str) -> int:
    """Count the words in a text."""
    return len(text.split())

entity = summon(
    OllamaOracle(arcana="qwen2.5:7b"),
    Tome([word_count]),
    role="You are a scribe.",
    spell_calling="auto",   # prompted fallback if the model lacks native tools
)
result = asyncio.run(entity.ainvoke(
    {"messages": [{"role": "user", "content": "How many words in 'fiat lux'?"}]}
))
print(result["messages"][-1]["content"])

Examples

The examples/ gallery runs on scripted oracles by default — no model required — and every script takes --oracle ollama:

Ecosystem

Sanctum owns execution; AgentGrimoire owns capability — a folder-per-Spell tool library loadable by convention with Tome.load_from_directory(path). Either side evolves without touching the other.

Development

pip install -e ".[dev]"
ruff check . && pytest --cov=sanctum      # unit suite: no models, no services
python benchmarks/superstep_overhead.py  # engine overhead: tens of µs/superstep

Contributions welcome — see CONTRIBUTING.md (includes how to run the opt-in integration tests against a local Ollama) and the design document for the rationale behind every trade-off. Licensed MIT.

Project details


Download files

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

Source Distribution

sanctum_engine-0.3.0.tar.gz (126.8 kB view details)

Uploaded Source

Built Distribution

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

sanctum_engine-0.3.0-py3-none-any.whl (87.0 kB view details)

Uploaded Python 3

File details

Details for the file sanctum_engine-0.3.0.tar.gz.

File metadata

  • Download URL: sanctum_engine-0.3.0.tar.gz
  • Upload date:
  • Size: 126.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for sanctum_engine-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bcbefbdccee07239c1133a2fac67d26ec2f4d972d05a706b2018cd11b06bdcea
MD5 cd7d735af39f95b1921e185405d17eaf
BLAKE2b-256 01dc0867dd31722243a6715807c05f042b9741a35dceb9268b94134f312864c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanctum_engine-0.3.0.tar.gz:

Publisher: release.yml on zquintero246/sanctum-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanctum_engine-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: sanctum_engine-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 87.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for sanctum_engine-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dfbb991d334e7ad0d6db4bc4fab0ad5c6f8c36784021fc78d09d77259b49531
MD5 a48549de3fe0ba19a96f1a7d1d5bc5d8
BLAKE2b-256 1044e9de0aa9a3e17a3009b7cbb52b7371e1a73bfe16404e251bb4d5eac596ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanctum_engine-0.3.0-py3-none-any.whl:

Publisher: release.yml on zquintero246/sanctum-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page