Skip to content

Add PostgreSQL-based session management for agent memory #1405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

syedmuneeb321
Copy link

This PR introduces a new PostgreSQLSession class that stores agent conversation history in a PostgreSQL database. This allows session-based memory to persist across restarts and supports features like message history retrieval, deletion, and clearing.


💡 Key Features:

  • Session-Aware Memory:
    All messages are linked to a session_id, enabling multiple concurrent conversations.

  • Functions Added:

    • add_items(items: list[dict]): Saves messages to the session.
    • get_items() -> list[dict]: Retrieves all messages in order.
    • pop_item() -> dict | None: Gets and deletes the last message.
    • clear_session(): Deletes all messages in the session.

🧪 How to Test:

  1. Set the NEON_DB_URL environment variable with your PostgreSQL connection string.

  2. Run the main.py script to:

    • Start a new session.
    • Add and fetch messages from PostgreSQL.
  3. Optionally, call clear_session() to reset memory.


⚙️ Tech Stack:

  • Language: Python
  • Database: PostgreSQL (tested with Neon DB)
  • Library: asyncpg (for fast async PostgreSQL queries)

This code saves and manages chat messages in a PostgreSQL database using a custom PostgreSQLSession class.
@seratch seratch added the documentation Improvements or additions to documentation label Aug 11, 2025
@seratch
Copy link
Member

seratch commented Aug 11, 2025

Thanks for sending this. This project is going to have #1163 in future releases. So, we won't have this example in this repo.

@seratch seratch closed this Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants