Skip to content

Conversation

@palaniappan-r
Copy link
Collaborator

  • Added PostgreSQL schema with Conversation and Message tables using SQLAlchemy ORM
  • Updated chat endpoints to persist conversations and added CRUD operations for conversation management
  • Added a PostgreSQL service in docker-compose with automatic database initialization

Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Copilot AI review requested due to automatic review settings November 2, 2025 14:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds PostgreSQL database integration for conversation persistence, enabling the chatbot to store and retrieve conversation history. The PR removes deprecated chain-based endpoints and replaces them with a unified conversation-based API.

  • Adds PostgreSQL database with Docker Compose configuration and SQLAlchemy models for conversations and messages
  • Implements CRUD operations for conversation and message management with new REST API endpoints
  • Refactors chat endpoints to use database-backed conversation history instead of in-memory chat history
  • Removes legacy chain-based routers in favor of graph-based agent retrieval

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docker-compose.yml Adds PostgreSQL service with health checks and connects backend to database
docker-compose.dev.yml Adds pgAdmin service for development database management
backend/src/database/models.py Defines SQLAlchemy models for Conversation and Message entities
backend/src/database/crud.py Implements database CRUD operations for conversations and messages
backend/src/database/config.py Configures database connection, session management, and initialization
backend/src/database/init.py Exports database module public API
backend/src/api/routers/conversations.py Refactors chat endpoints to use database persistence and adds conversation management endpoints
backend/src/api/routers/chains.py Removes deprecated chain-based router (file deleted)
backend/src/api/models/response_model.py Adds response models for conversation and message data
backend/src/api/main.py Updates router imports and adds database initialization on startup
backend/src/api/api_docs.md Documents new conversation API endpoints
backend/pyproject.toml Adds PostgreSQL and SQLAlchemy dependencies
backend/main.py Moves app import after environment variable setup
backend/Dockerfile Adds PostgreSQL client libraries and environment variables
backend/Dockerfile_slim Adds PostgreSQL client libraries and environment variables
backend/.env.example Adds PostgreSQL configuration variables
Comments suppressed due to low confidence (4)

backend/src/api/routers/conversations.py:348

  • The streaming endpoint does not persist user messages or assistant responses to the database. Unlike the non-streaming endpoint (get_agent_response), this function creates a conversation but never calls crud.create_message for the user input or assistant response, meaning streaming conversations won't be saved or retrievable later.
    backend/src/api/routers/conversations.py:233
  • The title is set to the first 100 characters of the user's question every time a conversation is created, but when an existing conversation is retrieved, its title is never updated. This creates inconsistent behavior where the first message sets the title, but subsequent messages in the same conversation cannot update it. Consider either always updating the title for new conversations or implementing a separate endpoint to update titles explicitly.
    backend/src/api/routers/conversations.py:389
  • The delete_conversation endpoint queries the database twice: once with get_conversation to check existence (line 386), then crud.delete_conversation queries it again internally (line 58-59 in crud.py). This is inefficient. Consider removing the existence check since crud.delete_conversation already returns a boolean indicating success, or refactor to use a single query.
    backend/src/api/routers/conversations.py:360
  • The POST endpoint at the root path '' creates an empty conversation without any initial message or title. This design could lead to orphaned empty conversations if clients call this endpoint but never send messages. Consider requiring an initial message or title in the request body, or implement a cleanup mechanism for empty conversations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

palaniappan-r and others added 14 commits November 2, 2025 17:02
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
- use uuid
- standardise var names

Signed-off-by: Jack Luar <[email protected]>
- async bug `get_tools`
- pass chat history in prompt

Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
@luarss luarss enabled auto-merge (squash) November 15, 2025 08:03
luarss
luarss previously approved these changes Nov 15, 2025
Signed-off-by: Jack Luar <[email protected]>
@luarss luarss disabled auto-merge November 15, 2025 09:39
@luarss luarss enabled auto-merge (squash) November 15, 2025 09:40
@luarss luarss merged commit cb4d1bd into master Nov 15, 2025
2 checks passed
@luarss luarss deleted the backend-db branch November 15, 2025 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants