LangGraph Uses Postgres to Maintain Customer History

A customer service agent built with LangGraph gains robustness through Postgres persistence. The Streamlit application can operate with a local PostgreSQL 16 container via Docker or a remote instance, without any change in behavior, and the data is retained after a restart.
Persistence Remains Active When the App Restarts
With a Postgres database, Streamlit and the database operate in separate processes: restarting the application does not restart the database container. Reservations are stored on a persistent Docker volume, allowing the application to retrieve history during new appointments. The database is only deleted if the container is stopped or removed and the volume is cleared. This principle also applies with a remote instance: only the location of Postgres changes, while the application's behavior remains the same.
A Reproducible Local Environment in Just a Few Minutes
Testing with Docker provides a real local PostgreSQL server, equivalent to production, without requiring Postgres installation on the machine. URLs and credentials are centralized in configuration files, ensuring reproducibility. The database, isolated in a container, can be stopped or removed without affecting the rest of the system, facilitating clean and quick testing cycles.
Docker Configuration: Image, Ports, Volume, and Health
The project provides a docker-compose that starts PostgreSQL 16 using the image postgres:16-alpine, with POSTGRES_USER=booking, POSTGRES_PASSWORD=booking, and POSTGRES_DB=booking_agent. The container's port 5432 is exposed on 5432 locally, and a volume booking_pgdata stores the data. A healthcheck pg_isready runs every 5 seconds with a timeout of 5 seconds and 10 attempts. After verifying that Docker Desktop is running, the container is launched with "docker compose up -d". The DATABASE_URL to use is "postgresql://booking:booking@localhost:5432/booking_agent". The application is launched via the provided Streamlit command, and a test reservation was successfully made; the interface did not offer the already booked slot, and the activity is visible in Docker Desktop.
Le brief IA que les pros lisent chaque soir
Les 7 actus IA du jour, décryptées en 5 min. Gratuit.
Inclus dès l'inscription : notre sélection des meilleurs guides & comparatifs IA.
Choisissez votre rythme
Gratuit · Pas de spam · Désabonnement en 1 clic
Hosted Database: Same App, Remote Postgres
A cloud Postgres instance can replace the local container. Simply create the database through the provider, retrieve a connection string of the form "postgresql://USER:PASSWORD@HOST:PORT/DATABASE", place it in the .env file as DATABASE_URL, and then start the application as before. The application's functionality remains the same; only the hosting infrastructure of Postgres changes.
LangGraph Stores Exchanges and Checks Reservations
The progress of the conversation is managed in LangGraph AgentState and recorded as checkpoints. Before proposing time slots, the agent queries existing reservations to avoid offering a time that is already taken; upon confirmation, it logs technician, time slot, address, and price. There are two modes of persistence: in-memory, intended for demonstration and quick testing, and Postgres for durability. Without DATABASE_URL, the application uses InMemoryBookingRepository and MemorySaver without creating tables, and the state is lost upon restart. For a local trial, dependencies are installed with Poetry, a .env file is created, OPENAI_API_KEY is set, and then the interface is launched at localhost:8501. The agent can produce a quote if all necessary information has already been provided, or request size and address otherwise.
Agent Capabilities and Project Roadmap
Built with LangGraph and equipped with state, the agent manages a 15-minute booking journey, integrated into a Streamlit interface and supported by Postgres. Originating from an exchange with a cleaning service, it covers customer inquiries, understanding needs, calculating and presenting the price, acceptance or refusal, proposing optimized schedules, and then confirming and recording the appointment. The code is available on GitHub under customer-service-agent. The project is evolving towards a usable product, with plans to add channels like WhatsApp, a security layer to limit query injection, and improvements to the booking flow and chat experience, which will be the subject of future developments.
Brief IA — L'actualité IA en français
L'essentiel de l'actualité de l'intelligence artificielle, décrypté et expliqué chaque jour.