This project provides:
- LangGraph/LangChain SQL AI agent
- FastAPI backend API (
/chat,/health) for diagnostics - MCP server facade (MCP over Streamable HTTP) exposing
chat_agent - Open WebUI as primary frontend (using Azure AI Foundry / Azure OpenAI model provider)
- Postgres-backed LangGraph short-term + long-term memory
Tool name: chat_agent
Inputs:
user_id(required)message(required)thread_id(optional)db_path(optional, SQLite file path)db_uri(optional, SQLAlchemy URI e.g. SQL Server)
Outputs:
answeruser_idthread_id
- Configure env:
cp .env.example .env- Download sample SQLite DB:
bash scripts/download_adventureworks.sh- Ensure
.envhas Azure model connection values:
AZURE_OPENAI_API_KEYOPENWEBUI_OPENAI_BASE_URL(OpenAI-compatible base URL, e.g.https://<resource>.openai.azure.com/openai/v1)OPENWEBUI_MODEL_IDset to your Foundry deployment (for examplegpt-5.2)
- Start stack:
docker compose up -d --build- If you previously ran Open WebUI with other providers, reset persisted UI config:
docker compose down -v
docker compose up -d --build- Open Open WebUI:
http://localhost:3000
- Register MCP server in Open WebUI:
- URL:
http://mcp-server:8001/mcp(from inside Docker network) - If your Open WebUI MCP form expects host URL from browser network, use
http://localhost:8001/mcp.
- In Open WebUI, select your Azure Foundry model/deployment and invoke MCP tools from chat.
Set your model/system prompt in Open WebUI to include this policy:
You have an MCP tool named chat_agent. Use it whenever user memory or SQL may be involved.
Always call chat_agent for:
- user profile statements: "my name is ...", "I prefer ...", "remember that ..."
- memory recall requests: "what is my name?", "what do you remember about me?"
- Company Store SQL/database questions.
Do not answer from your own context if memory may be relevant. Ask chat_agent first.
Pass through user_id and thread_id exactly as provided by tool context.
Reuse returned thread_id for follow-up turns.
Why: with smart auto-call, Open WebUI may skip tool calls if the tool looks SQL-only. The MCP metadata and this policy make memory-capture/recall turns route to chat_agent.
You can run the agent against either database type:
- SQLite (default): use bundled
APP_DEFAULT_SQLITE_DB_PATHor passdb_pathper request/tool call. - SQL Server: set
APP_DEFAULT_SQL_URI(SQLAlchemy URI) or passdb_uriper request/tool call.
Selection precedence:
db_urifrom request/tool callAPP_DEFAULT_SQL_URI(if configured)db_pathfrom request/tool call orAPP_DEFAULT_SQLITE_DB_PATH
- Set
OPENWEBUI_MODEL_ID=gpt-5.2in.env(or your exact Foundry deployment name). - Restart with clean config:
docker compose down -v
docker compose up -d --build- Optional hard filter in UI (recommended to hide all others):
Admin Settings -> Connections -> OpenAI -> Model IDs (Filter) ->
gpt-5.2
mcp-serveruvicorn backend.main:app --reload --port 8000If tool calls fail with 404 Resource not found, check:
AZURE_OPENAI_ENDPOINTshould behttps://<resource>.openai.azure.comAZURE_OPENAI_DEPLOYMENTmust be exact deployment nameAZURE_OPENAI_API_VERSIONmust match deployment support