# LangGraph AI Agent Integrated with Postgres

The AI assistant now handles permanent bookings with database connectivity

- **Source:** [Towards Data Science](https://towardsdatascience.com)
- **Published:** 2026-08-28
- **Topic:** [Data & AI](https://brifing.si/c/data-ai)
- **Original article:** <https://towardsdatascience.com/connecting-my-langgraph-ai-agent-to-postgres/>
- **On Brifing:** https://brifing.si/s/467a64c8-42f8-4079-a91d-91aff3f0b3d3

## LangGraph-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.

## Data 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.

## Postgres 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.

## Integration 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.

## Cloud 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.

## Booking 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.

## Developer 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.

## Production 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.

## Sources covering this story

- https://towardsdatascience.com/connecting-my-langgraph-ai-agent-to-postgres/ — 

---

_Summary written by Brifing from the original reporting. Copyright in the original article belongs to its publisher; read the full piece at the link above._
