Dosu LogoDosu Logo
Ask
Join our Discord
assistant-ui's SpacePublic
assistant-ui
Documentsassistant-ui's Space
README
README
Type
External
Status
Published
Created
Mar 17, 2026
Updated
Aug 29, 2026
Updated by
Dosu Bot
Source
python/assistant-transport-backend/README.md

Assistant Transport Backend#

A simple Python server that demonstrates the assistant-transport protocol using FastAPI and assistant-stream. This backend returns static responses to show how the streaming protocol works with assistant-ui frontend applications.

Features#

  • ๐Ÿš€ FastAPI-based - High-performance async server
  • ๐Ÿ“ก Streaming Responses - Real-time responses using assistant-stream
  • ๐Ÿ”„ State Management - Uses assistant-stream's object-stream state utilities
  • ๐Ÿ”Œ Assistant-Transport Protocol - Full compatibility with assistant-ui
  • ๐ŸŒ CORS Enabled - Works with any frontend origin
  • ๐Ÿ“ฆ Simple Setup - Minimal dependencies
  • ๐Ÿงช Static Responses - No API keys required, perfect for testing

Prerequisites#

  • Python 3.9 or higher
  • uv

Quick Start#

1. Install Dependencies#

uv sync

2. Configure Environment (Optional)#

# Copy example environment file
cp .env.example .env
# Edit .env file if needed

Default configuration:

# Server Configuration
HOST=0.0.0.0
PORT=8000
DEBUG=true

# CORS Configuration 
CORS_ORIGINS=http://localhost:3000

3. Start the Server#

# Using the installed command
assistant-transport-backend

# Or run directly
python main.py

# Or using uvicorn
uvicorn main:app --reload --host 0.0.0.0 --port 8000

The server will be available at:

  • API: http://localhost:8000
  • Health Check: http://localhost:8000/health
  • Assistant Endpoint: http://localhost:8000/assistant

API Endpoints#

POST /assistant#

Main endpoint that implements the assistant-transport protocol.

Request Format:

{
  "commands": [
    {
      "type": "add-message",
      "message": {
        "role": "user",
        "parts": [
          {"type": "text", "text": "Hello!"}
        ]
      }
    }
  ],
  "system": "You are a helpful assistant",
  "tools": {},
  "runConfig": {}
}

Response: Streaming response using assistant-stream format with static responses.

GET /health#

Health check endpoint that returns server status and current conversation state.

POST /cancel#

Cancel the current request (placeholder for request cancellation).

Static Response Patterns#

The backend recognizes these message patterns and returns appropriate static responses:

  • Greetings (hello, hi) โ†’ Welcome message
  • Weather (weather) โ†’ Sunny static response
  • What/What is โ†’ Explanation of what the backend does
  • Help โ†’ Available command information
  • Other messages โ†’ Acknowledgment with echo

Integration with Frontend#

This backend works with the with-assistant-transport frontend example:

  1. Start backend: python main.py
  2. Start frontend: cd ../../examples/with-assistant-transport && pnpm dev
  3. Frontend connects to http://localhost:8000/assistant

Project Structure#

python/assistant-transport-backend/
โ”œโ”€โ”€ main.py # FastAPI server and main entry point
โ”œโ”€โ”€ pyproject.toml # Project configuration and dependencies
โ”œโ”€โ”€ .env.example # Environment variables template
โ””โ”€โ”€ README.md # This file

How It Works#

Assistant-Stream Integration#

The backend uses assistant_stream.create_run() to create a streaming controller that:

  1. Manages State: Updates conversation state with messages
  2. Streams Text: Uses controller.append_text() for character-by-character streaming
  3. Updates State: Uses controller.state to update the object-stream state
  4. Handles Protocol: Automatically formats responses for assistant-transport

State Management#

# Initialize state
conversation_state = {
    "messages": [],
    "provider": "static"
}

# Create run controller with state
controller = create_run(conversation_state)

# Update state during processing
controller.state.provider = "processing"
controller.state.messages.append(new_message)

# Stream text responses
for char in response_text:
    controller.append_text(char)

Development#

Running in Development Mode#

# Enable debug mode and auto-reload
DEBUG=true python main.py

Adding Response Patterns#

Edit the static response logic in main.py:

# Add new patterns
if "goodbye" in user_message:
    response_text = "Goodbye! Thanks for testing the assistant-transport backend!"

Testing#

# Test the health endpoint
curl http://localhost:8000/health

# Test the assistant endpoint
curl -X POST http://localhost:8000/assistant \
  -H "Content-Type: application/json" \
  -d '{"commands":[{"type":"add-message","message":{"role":"user","parts":[{"type":"text","text":"Hello!"}]}}]}'

Environment Variables#

VariableDescriptionDefault
HOSTServer host0.0.0.0
PORTServer port8000
DEBUGEnable debug modefalse
LOG_LEVELLogging levelinfo
CORS_ORIGINSAllowed CORS originshttp://localhost:3000

License#

This project is part of the assistant-ui monorepo and follows the same MIT licensing terms.

Learn More#

  • assistant-ui Documentation
  • Assistant Transport Protocol
  • assistant-stream Package
  • FastAPI Documentation
Documents
AG-UI Message History Management
CHANGELOG
CHANGELOG
CHANGELOG
external-store
overview
README
AG-UI Streaming State Management
hooks
index
introduction
overview
part-1
README
README
stockbroker
AI SDK Integration
ai-sdk
assistant-runtime-provider
expo
hooks
index
index
index
introduction
migration
migration
overview
part-2
README
README
README
README
README
README
README
README
stockbroker
Cloud Message Pagination
index
Generative UI Date and Time Controls
In-Memory Thread Lifecycle
CHANGELOG
CHANGELOG
CHANGELOG
Local Runtime Message History
CHANGELOG
Markdown Preprocessing and Repair
CHANGELOG
CHANGELOG
MCP App Tool UI Rendering
CHANGELOG
CHANGELOG
message
MCP OAuth State Management
MessageRepository Branch Pointer Invariant
Next.js Cache Components
Remote Thread List Runtime
adapters
CHANGELOG
CHANGELOG
hooks
index
README
README
thread-runtime
Render Prop Leakage
Run Cancellation and Abort Signal Propagation
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
README
Run Telemetry Model ID Extraction
SSR-Safe Thread ID Generation
Stream Decoder Buffer Limits
CHANGELOG
CHANGELOG
StreamdownTextPrimitive
index
Streaming Markdown Rendering
CHANGELOG
CHANGELOG
index
introduction
part-1
AGENTS
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CODE_OF_CONDUCT
CONTRIBUTING
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README_LANGGRAPH
SECURITY
SPEC
SPEC_AssistantFrame
SPEC_ModelContextRegistry
action-bar
action-bar-more
adapters
artifacts
assistant-if
assistant-modal
assistant-modal
assistant-runtime
assistant-sidebar
attachment
attachment
attachment-runtime
branch-picker
chatgpt
claude
composer
composer-runtime
composition
context-display
custom-backend
custom-backend
error
file
form-demo
grok
heat-graph
hooks
image
index
index
index
index
index
index
index
index
index
markdown
mem0
mermaid
message-part
message-part-runtime
message-runtime
message-timing
modal
model-selector
part-3
perplexity
pick-a-runtime
primitives
primitives
quote
reasoning
selection-toolbar
sources
suggestion
syntax-highlighting
thread
thread
thread-list
thread-list
thread-list-item
thread-list-item-more
thread-list-item-runtime
thread-list-runtime
tool-fallback
tool-group
tw-shimmer
v4-legacy
v5-legacy