HeadlinesBriefing favicon HeadlinesBriefing.com

Building a Streamlit UI for LangGraph AI Agent

Towards Data Science •
×

The article details how to wrap a LangGraph‑based AI agent in a clean, interactive Streamlit interface, turning a CLI‑only booking assistant into a customer‑facing web app. The original mezzo‑stateful agent handled the entire booking cycle: greeting, price calculation, slot selection, and confirmation. While the CLI was functional for tests, it lacked visual appeal, so the author introduces Streamlit as a lightweight wrapper that preserves conversation state via session_state, allowing the agent to run unchanged under different front‑ends.

Key steps include installing Streamlit with *poetry*, creating a `streamlit_app.py` that imports the graph builder, models, and observability utilities, and initializing a persistent graph instance with a unique thread ID for Langfuse tracing. The helper function `_invoke` submits user input to the graph, updates the agent state, and handles errors. Rendering functions like `_render_messages` display chat bubbles, while booking details, price quotes, and time options are shown as structured widgets.

The final section shows how to launch the app locally with `poetry run streamlit run …` and explains that an `OPENAI_API_KEY` for OpenAI's gpt-4o-mini is required. The result is a polished, production‑ready interface that demonstrates the agent’s capabilities to real users.