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.2.0.tar.gz (108.9 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.2.0-py3-none-any.whl (80.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sanctum_engine-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3773cb6f553de6cdfa9ec130fdf5a87f7b38c117c4703d7541f2e3fa087bb889
MD5 e4192fec5ad61ed38237971ba8983100
BLAKE2b-256 8bbed35cac1a5ae76e71ae094c83f85707f014b07543384d74a24b12ae6b6e59

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanctum_engine-0.2.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.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for sanctum_engine-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4a57d496ee016d9b38f6cc1092ad475cdb17025b8e6132e5fb5f4a40d58d16b
MD5 2ec785430e8e31619a8fef833137aef8
BLAKE2b-256 fa1445bd5b1201feb813339b7aeab00813bec56e40e3e049edb5b8261729b6c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanctum_engine-0.2.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