Skip to main content

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 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

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

agent_state_bridge-1.0.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

agent_state_bridge-1.0.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

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

Hashes for agent_state_bridge-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5ac94660e395eec52c657e5b5c040dd35ab18411e201e2bda86f12ecd4823470
MD5 8e8fcc243118f992b30ec39acbf7baf4
BLAKE2b-256 d882dbbe60a01bc3804ac592f7031c432dc72650c3d2a32e0414ff1a65a2337a

See more details on using hashes here.

File details

Details for the file agent_state_bridge-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_state_bridge-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd49bdb908c95210d269a32d89216b00d7e316eda992efeee97622866871f934
MD5 22c9d22642fea5af51e96479cbd40d56
BLAKE2b-256 c0ebb29d084abf9c8f99b0a985b4d68e07f22b558853ca9c95f651d39aad3133

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