How yonom/assistant-ui-langgraph-fastapi works
Project type and purpose
• This is a full-stack demonstration app combining:
– A LangGraph AI agent running in Python via FastAPI
– Real-time token streaming from backend to frontend using assistant-stream
– A modern chat UI built with Next.js and assistant-ui
File structure
Top-level:
• backend/ : FastAPI application, LangGraph agent modules, Dockerfile, pyproject.toml
– app/server.py: main FastAPI server, mounts streaming endpoints
– app/add_langgraph_route.py: registers LangGraph routes
– app/langgraph/: agent.py (agent logic), state.py (conversation state), tools.py (external tool wrappers)
• frontend/ : Next.js + assistant-ui client
– app/page.tsx & components/MyAssistant.tsx: chat UI and integration with assistant-stream
– next.config.ts, tailwind.config.ts, postcss.config.mjs: build and styling configuration
Extract additional architectural insights from README
• Backend spun up via “poetry run python -m app.server”
• Frontend launched via “yarn dev”
• .env file in backend for API keys and configuration
a. Main components to include:
1. Frontend UI
– Next.js app
– assistant-ui chat component
2. Streaming Layer
– assistant-stream client (in frontend)
– assistant-stream endpoint (in FastAPI backend)
3. FastAPI Backend
– HTTP/WebSocket server
– LangGraph route registrations
4. LangGraph Agent
– agent.py (core decision logic)
– state.py (conversation memory)
– tools.py (external API/tool connectors)
5. External Tools/APIs
– Any third-party APIs or services invoked by tools.py
6. Infrastructure
– Docker container for backend (optional)
– Environment variables store (.env)
b. Relationships and data flow
1. User types a message in the chat UI
2. Frontend assistant-stream client opens a streaming connection to FastAPI
3. FastAPI receives user input, forwards to the LangGraph Agent
4. Agent processes input, updates state, calls external tools as needed
5. Agent yields tokens/partials back to FastAPI
6. FastAPI pushes tokens over the streaming connection to the frontend
7. Frontend renders tokens in real time in the chat UI
c. Architectural patterns and design principles
• Two-tier, decoupled frontend/backend
• Streaming architecture for real-time updates (event-driven)
• Modular agent design: separate state management, tool integration, decision logic
• Containerization for backend isolation and reproducible deployments
d. Key technologies and frameworks
• Frontend: Next.js, assistant-ui, Tailwind CSS, TypeScript
• Streaming: assistant-stream
• Backend: FastAPI, Python 3.11, LangChain CLI, LangGraph
• Deployment: Docker (backend)