Skip to main content

Framework-agnostic agent reliability primitives for enforcing contracts, checkpointing, tracing, and execution.

Project description

Stroma

Framework-agnostic reliability primitives for agent pipelines.

from pydantic import BaseModel
from stroma import StromaRunner

class Input(BaseModel):
    value: int

class Output(BaseModel):
    result: int

runner = StromaRunner.quick()

@runner.node("double", input=Input, output=Output)
async def double(state: Input) -> dict:
    return {"result": state.value * 2}

result = await runner.run([double], Input(value=5))
print(result.final_state)  # result=10

Install

Requires Python 3.12+.

uv add stroma

Optional extras:

uv add stroma[redis]       # Redis-backed checkpointing
uv add stroma[langgraph]   # LangGraph adapter
uv add stroma[deepagents]  # DeepAgents adapter

What You Get

  • Contracts — Pydantic-based input/output validation at every node boundary
  • Failure classification — automatic categorization of errors as recoverable, terminal, or ambiguous
  • Retry policies — configurable retries with jittered backoff, per failure class or per node
  • Checkpointing — async-first save and resume across crashes (in-memory or Redis)
  • Cost estimation — model-aware USD cost tracking via KNOWN_MODELS and token/dollar/latency budgets
  • Parallel execution — fan out work to concurrent nodes with parallel(), per-child contract validation, and merged output
  • Node hooks — async on_node_start, on_node_success, and on_node_failure callbacks
  • Shared context — pass a mutable context dict through RunConfig to every node
  • Execution tracing — full record of every node attempt, with diffing and JSON export
  • Per-run logging — structured LoggerAdapter with run_id in every log line
  • Fluent builder API — configure runners with chained .with_budget(), .with_hooks(), .with_redis(), etc.
  • LangGraph adapter — apply contracts to existing LangGraph graphs
  • DeepAgents adapter — contract validation and cost tracking for deepagents graphs
  • Framework-agnostic — works with any async Python code, no framework lock-in

Quick Examples

Cost estimation

Nodes can return token counts and a model name. Stroma computes USD cost automatically from built-in pricing data:

@runner.node("summarize", input=DocInput, output=Summary)
async def summarize(state: DocInput) -> tuple:
    # call your LLM here...
    return ({"text": response}, input_tokens, output_tokens, "gpt-4o")

Parallel execution

Run independent nodes concurrently and merge their outputs:

from stroma import parallel

result = await runner.run(
    [parallel(fetch_metadata, fetch_embeddings), merge_node],
    initial_state,
)

Node hooks

Attach lifecycle callbacks to observe node execution:

from stroma import NodeHooks, RunConfig

async def on_start(run_id, node_id, input_dict):
    print(f"Starting {node_id}")

config = RunConfig(hooks=NodeHooks(on_node_start=on_start))

Shared context

Pass runtime configuration to nodes that accept a second argument:

@runner.node("enrich", input=Input, output=Output)
async def enrich(state: Input, ctx: dict) -> dict:
    api_key = ctx["api_key"]
    # ...

config = RunConfig(context={"api_key": "sk-..."})

Per-node retry policies

Override the global retry policy for specific nodes:

from stroma import FailureClass, FailurePolicy

config = RunConfig(
    node_policies={
        "flaky_node": {
            FailureClass.RECOVERABLE: FailurePolicy(max_retries=5, backoff_seconds=2.0),
        }
    }
)

Async checkpointing

The default store is now async. For distributed pipelines, use the async Redis store:

from stroma import RedisStore, CheckpointManager

store = RedisStore("redis://localhost:6379", ttl_seconds=7200)
manager = CheckpointManager(store)

The original synchronous Redis store is still available as SyncRedisStore.

Documentation

Full documentation including a tutorial and API reference is available at the docs site.

Development

uv sync --extra dev
uv run pytest tests/ -v --cov=stroma --cov-fail-under=85

License

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

stroma-0.2.6.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

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

stroma-0.2.6-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file stroma-0.2.6.tar.gz.

File metadata

  • Download URL: stroma-0.2.6.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stroma-0.2.6.tar.gz
Algorithm Hash digest
SHA256 5ee2bd9da8746298dd092d9f0e33e8622084a1a585b22d67ebd0e154980113b3
MD5 e1767a88212a33862afc2267c78c7ace
BLAKE2b-256 27b3cc90b984519df657f8f3bf80ffbbbb50b75325d7a63f4879266f4127361c

See more details on using hashes here.

Provenance

The following attestation bundles were made for stroma-0.2.6.tar.gz:

Publisher: workflow.yml on jengroff/stroma

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

File details

Details for the file stroma-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: stroma-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stroma-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9b0bce166749eda9f5ca6ddf027d79ee3a2c998d560986a1934f93882c037723
MD5 477a0e114aac529ef9fa5c1db0215e4e
BLAKE2b-256 7c395678907709f25bf509794141512935c3b76caa7aac3fecdf3e7986e6377a

See more details on using hashes here.

Provenance

The following attestation bundles were made for stroma-0.2.6-py3-none-any.whl:

Publisher: workflow.yml on jengroff/stroma

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