An AI legal-advisory assistant built on the OpenAI Assistants API, with a FastAPI backend, async SQLAlchemy + PostgreSQL persistence, and a Streamlit chat UI. Multiple configurable agents are stored in the database, each mapped to an OpenAI Assistant with its own instructions and tools.
┌────────────┐ ┌──────────────────┐ ┌───────────────────┐
│ Streamlit │────▶│ FastAPI (REST) │────▶│ OpenAI Assistants │
│ chat UI │ │ agents / chat │ │ (threads, tools) │
└────────────┘ └────────┬─────────┘ └───────────────────┘
│ async SQLAlchemy
▼
┌──────────────────┐
│ PostgreSQL │
│ agent registry │
└──────────────────┘
main.py— FastAPI app: agent CRUD + question endpointsai.py—AgentManagerAI: OpenAI Assistants thread/run lifecycle, streaming, tool callsmodels/schemas/crud/— SQLAlchemy models, Pydantic schemas, DB operationsapp.py— Streamlit chat frontend with file upload and streaming responsesdatabase.py— async engine/session manager (asyncpg)
export OPENAI_API_KEY=sk-... # your key
docker compose up --buildAPI on http://localhost:8030, PostgreSQL on 5432.
- Create an assistant at platform.openai.com/assistants and note the assistant ID
- Create a
.envfile:DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/lawadviser OPENAI_API_KEY=sk-...
- Install and run:
pip install -r requirements.txt # or: poetry install uvicorn main:app --reload --port 8030 - Register an agent row (assistant ID + instructions) via the API, then chat.
| Variable | Purpose |
|---|---|
DATABASE_URL |
Async PostgreSQL DSN (postgresql+asyncpg://...) |
OPENAI_API_KEY |
OpenAI API key |
Python · FastAPI · OpenAI Assistants API · SQLAlchemy (async) + asyncpg · PostgreSQL · Pydantic v2 · Streamlit · Docker