LangGraph AI Agent Integrated with Postgres
The AI assistant now handles permanent bookings with database connectivity
1LangGraph-Based AI Assistant
In the first three articles of this series, developers built a stateful LangGraph agent capable of managing 15-minute booking processes. The assistant functions like a real customer service rep, responding to queries and calculating service fees. Streamlit UI enhanced user experience before Postgres database integration was completed.
2Data Persistence Solutions
The project implements two data storage methods: in-memory and Postgres. While in-memory mode serves quick testing purposes using InMemoryBookingRepository, Postgres integration ensures booking information persists. When DATABASE_URL remains unset, the system defaults to memory-based storage without creating database tables.
3Postgres Test Environment with Docker
Using docker-compose, a PostgreSQL 16 container was configured. The database running inside the container persists data through Docker's booking_pgdata volume. This approach lets developers test against a real database environment without installing Postgres locally.
4Integration Steps
To launch the test environment, ensure Docker Desktop is running. The container starts via docker compose up -d command. Adding DATABASE_URL to .env file enables application-database connectivity. Streamlit UI connects to the containerized Postgres via localhost:5432.
5Cloud Database Alternative
For those preferring cloud solutions, the system supports Postgres providers like Supabase or RDS. After adding the connection string to .env, the application functions identically. The only difference lies in the database running on remote servers rather than locally.
6Booking Validation Mechanism
The system reads existing bookings from the database to avoid offering occupied time slots. Upon confirmation, each booking records technician details, time range, address, and price. Cross-browser testing verified the system's correct functionality.
7Developer Experience
Project dependencies are managed through poetry. Environment variables are configured by copying .env.example. While OPENAI_API_KEY is mandatory, leaving DATABASE_URL empty runs the app in in-memory mode. All source code was shared on GitHub for community contributions.
8Production Readiness
This integration demonstrates AI assistants' real-world applicability. The persistent data system stands ready for industries like cleaning services. Docker portability enables easy deployment across different environments.
Original article: Towards Data Science — LangGraph Tabanlı AI Asistanı Postgres ile Entegre Edildi