Skip to main content

Stateful coordination layer for multi-agent AI systems

Project description

AgentStateLib

AgentStateLib is a Python library for building reliable multi-agent workflows. It gives multiple agents a shared, typed state and a simple graph router, so you can coordinate them without passing raw strings around. [file:1]

Installation

pip install agentstate-lib

Quick start

import asyncio
from agentstatelib import SharedState, AgentGraph, StatePatch

graph = AgentGraph()

@graph.node("planner", context=["goal"])
async def planner(context: dict) -> StatePatch:
    goal = context["goal"]
    return StatePatch(
        agent_id="planner",
        target="facts.planned",
        value=True,
        reason=f"planned goal: {goal!r}",
    )

@graph.node("summarizer", context=["facts.planned", "goal"])
async def summarizer(context: dict) -> StatePatch:
    planned = context.get("facts", {}).get("planned")
    goal = context.get("goal")
    summary = f"Workflow for goal {goal!r} planned={planned}"
    return StatePatch(
        agent_id="summarizer",
        target="facts.summary",
        value=summary,
        reason="add summary",
    )

graph.edge(
    "planner",
    "summarizer",
    condition=lambda s: s.get("facts", {}).get("planned") is True,
)

async def main() -> None:
    state = SharedState(goal="Write a multi-agent blog post")
    final_state = await graph.run(state, start="planner")
    print(final_state.facts)

if __name__ == "__main__":
    asyncio.run(main())

Core ideas

  • SharedState: a Pydantic model that holds the workflow’s goal, tasks, artifacts, decisions, and facts.
  • StatePatch: what agents return. A structured change like “set facts.planned = True”.
  • AgentGraph: runs agents as a directed graph. Each agent is just an async function that receives a small context dict and returns a StatePatch.
  • Context slicing: each agent declares which paths it needs (e.g. ["goal", "facts.planned"]), and only sees that subset of the state.
  • Event store: every applied patch is recorded as an event in a pluggable store (in-memory or SQLite), so you can replay or debug workflows. [file:1]

Status

Version 0.5.0 — all Phase 2E features are implemented and tested (93 tests pass, mypy strict: 0 errors).

Phase 1–2E implemented:

  • SharedState, StatePatch, AgentGraph, round-based parallel execution
  • Conflict detection with LastWriteWins, PriorityBased, RejectIncoming strategies
  • InvariantChecker framework with two built-in checkers
  • Append-only event log (16 typed events) — InMemoryStore, SQLiteStore, PostgreSQLStore
  • Checkpointing to disk with save/load/recovery
  • ReplayDebugger for step-through inspection of any past state
  • Full trace model: ContextSliced, PromptAssembled, ModelCalled, ModelReturned, ValidationFailed, RetryAttempted, ToolCalled, ToolReturned
  • LLMAgent base class with retry-with-correction loop
  • OpenTelemetry tracing (optional, graceful no-op fallback)
  • Rich terminal dashboard (optional)
  • FastAPI HTTP server with SSE streaming and web dashboard
  • Human-in-the-loop approval gates with REST API and programmatic resolution
  • WorkflowSummary analysis with anomaly detection

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

agentstate_lib-0.5.0.tar.gz (182.0 kB view details)

Uploaded Source

Built Distribution

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

agentstate_lib-0.5.0-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file agentstate_lib-0.5.0.tar.gz.

File metadata

  • Download URL: agentstate_lib-0.5.0.tar.gz
  • Upload date:
  • Size: 182.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for agentstate_lib-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f7c770a59edade07be2e332d1c3ba931df17bf5f616c7973a3daf2a3dbf50002
MD5 80c3fc44705c52053c6ed0ad7ecd3fac
BLAKE2b-256 71235af92e6c5ac288cb8dd8c108b2d9ee8dda3bcb4e141faee3be2dab414515

See more details on using hashes here.

File details

Details for the file agentstate_lib-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: agentstate_lib-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 53.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for agentstate_lib-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfc2eb53d82884debc45f5fc6a3d95af7c7d7ca8fd3efb0f7689b77369e060e1
MD5 14b6c877c2668512403a5d2a96135cd3
BLAKE2b-256 edf8907f20c98d7c2b567b3004be09d7a0830a2776f0b1219d4935a9f3a1cccf

See more details on using hashes here.

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