Python backend utilities for sharing app state with AI agents. v1: {messages, actions, context} model, breaking changes, RAG-ready architecture.
Project description
agent-state-bridge (Python)
Python backend utilities for sharing app state with AI agents. Works with FastAPI, Flask, Django REST Framework, and any Python web framework.
Installation
# Basic installation (FastAPI is recommended)
pip install agent-state-bridge[fastapi]
# Or with Flask
pip install agent-state-bridge[flask]
# Or with Django
pip install agent-state-bridge[django]
# Or install all
pip install agent-state-bridge[all]
Quick Start
FastAPI
from fastapi import FastAPI
from agent_state_bridge.fastapi import create_agent_router
async def my_agent(message: str, state: dict) -> str:
"""Your agent logic here"""
cart_items = state.get("cart", {}).get("items", [])
return f"You have {len(cart_items)} items. You said: {message}"
app = FastAPI()
router = create_agent_router(my_agent, tags=["agent"])
app.include_router(router)
Flask
from flask import Flask
from agent_state_bridge.flask import create_agent_blueprint
def my_agent(message: str, state: dict) -> str:
return f"Processed: {message}"
app = Flask(__name__)
bp = create_agent_blueprint(my_agent)
app.register_blueprint(bp)
Django REST Framework
from agent_state_bridge.django import agent_api_view
@agent_api_view
def my_agent(message: str, state: dict) -> str:
return f"Processed: {message}"
# In urls.py:
# path('chat/', my_agent)
Integration with AI Frameworks
LangChain
from langchain_openai import ChatOpenAI
from agent_state_bridge.fastapi import create_agent_router
llm = ChatOpenAI(model="gpt-4o-mini")
async def langchain_agent(message: str, state: dict) -> str:
response = await llm.ainvoke([{"role": "user", "content": message}])
return response.content
router = create_agent_router(langchain_agent)
Microsoft Agent Framework
from azure.ai.projects import AIProjectClient
from agent_state_bridge.fastapi import create_agent_router
client = AIProjectClient(...)
agent = client.agents.create_agent(model="gpt-4o-mini")
async def agent_handler(message: str, state: dict) -> str:
# Your Agent Framework logic
return response
router = create_agent_router(agent_handler)
See /examples folder for complete examples with LangChain, Agent Framework, and more.
API Reference
Models
AgentRequest: Request model withmessageandstatefieldsAgentResponse: Response model withresponsefield
FastAPI
create_agent_router(handler, prefix="", tags=[]): Create router with/chatendpointAgentBridge: Class-based approach with decorator
Flask
create_agent_blueprint(handler, name="agent", url_prefix=""): Create blueprint@agent_route: Decorator for route handlers
Django
@agent_api_view: Decorator for function-based viewsAgentAPIView: Base class for class-based views
Frontend Integration
This package works seamlessly with the npm package agent-state-bridge for React:
npm install agent-state-bridge
License
MIT
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 agent_state_bridge-1.0.0.tar.gz.
File metadata
- Download URL: agent_state_bridge-1.0.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ac94660e395eec52c657e5b5c040dd35ab18411e201e2bda86f12ecd4823470
|
|
| MD5 |
8e8fcc243118f992b30ec39acbf7baf4
|
|
| BLAKE2b-256 |
d882dbbe60a01bc3804ac592f7031c432dc72650c3d2a32e0414ff1a65a2337a
|
File details
Details for the file agent_state_bridge-1.0.0-py3-none-any.whl.
File metadata
- Download URL: agent_state_bridge-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd49bdb908c95210d269a32d89216b00d7e316eda992efeee97622866871f934
|
|
| MD5 |
22c9d22642fea5af51e96479cbd40d56
|
|
| BLAKE2b-256 |
c0ebb29d084abf9c8f99b0a985b4d68e07f22b558853ca9c95f651d39aad3133
|