---
type: email
from: Syed Muneeb Abbas <notifications@github.com>
subject: [openai/openai-agents-python] Add PostgreSQL-based session management

 for agent memory (PR #1405)
received: 2026-03-05 09:55:18
date_header: Fri, 08 Aug 2025 02:21:14 -0700
priority: normal
status: awaiting_approval
uid: 26912
---

## Email Content

**From:** Syed Muneeb Abbas <notifications@github.com>
**Subject:** [openai/openai-agents-python] Add PostgreSQL-based session management

 for agent memory (PR #1405)
**Date:** Fri, 08 Aug 2025 02:21:14 -0700

### Body (preview)

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() -&gt; list[dict]`: Retrieves all messages in order.

  * `pop_item() -&gt; 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)





You can view, comment on, or merge this pull request online at:



  https://github.com/openai/openai-agents-python/pull/1405



-- Commit Summary --



  * add: pg session



-- File Changes --



    A examples/postgresql_session/main.py (38)

    A examples/postgresql_session/pg_session.py (74)

    M pyproject.toml (1)

    M uv.lock (53)



-- Patch Links --



https://github.com/openai/openai-agents-python/pull/1405.patch

https://github.com/openai/openai-agents-python/pull/1405.diff



-- 

Reply to this email directly or view it on GitHub:

https://github.com/openai/openai-agents-python/pull/1405

You are receiving this because you are subscribed to this thread.



Message ID: &lt;openai/openai-agents-python/pull/1405@github.com&gt;

---

## Suggested Actions
- [ ] Reply
- [ ] Archive
- [ ] Escalate
