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.1.2 is an early preview:
- SharedState data model
- StatePatch + apply_patch
- AgentGraph with decorator API
- InMemory and SQLite event stores
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentstate_lib-0.1.3.tar.gz.
File metadata
- Download URL: agentstate_lib-0.1.3.tar.gz
- Upload date:
- Size: 122.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4707e02ad251af47b911c19c6d3ea918d154b2ad0b6615a536612f47e1a4a92f
|
|
| MD5 |
1327e3616abde2be08753c40331cda0e
|
|
| BLAKE2b-256 |
8ed9ef4512eee10c6e5cdd7b73435119a27d6fcdfe45104b053f3ce6e6e64f43
|
File details
Details for the file agentstate_lib-0.1.3-py3-none-any.whl.
File metadata
- Download URL: agentstate_lib-0.1.3-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a7a06b0f1079ad226f9d17e3b22aa7a1396e199a41684b6fc9a529d5d25a8b8
|
|
| MD5 |
03c7cd1daab85d4e3b53c615df166e52
|
|
| BLAKE2b-256 |
6c33b963c215fe39cf896a5ee47611a980c91e4ccf8b09c8410718315d854cd4
|