Skip to main content

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 with message and state fields
  • AgentResponse: Response model with response field

FastAPI

  • create_agent_router(handler, prefix="", tags=[]): Create router with /chat endpoint
  • AgentBridge: 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 views
  • AgentAPIView: 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

Release files for agent-state-bridge 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-state-bridge 1.0.0
File Size Uploaded
agent_state_bridge-1.0.0.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-state-bridge 1.0.0
File Interpreter ABI Platform
agent_state_bridge-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / agent_state_bridge-1.0.0.tar.gz

Download URL agent_state_bridge-1.0.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5ac94660e395eec52c657e5b5c040dd35ab18411e201e2bda86f12ecd4823470
BLAKE2b-256 checksum
How to use checksums
d882dbbe60a01bc3804ac592f7031c432dc72650c3d2a32e0414ff1a65a2337a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / agent_state_bridge-1.0.0-py3-none-any.whl

Download URL agent_state_bridge-1.0.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd49bdb908c95210d269a32d89216b00d7e316eda992efeee97622866871f934
BLAKE2b-256 checksum
How to use checksums
c0ebb29d084abf9c8f99b0a985b4d68e07f22b558853ca9c95f651d39aad3133
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page