OpenAI Agents SDK session memory backed by PerSQL — durable conversation history in an isolated SQLite database per agent.
Project description
openai-agents-persql
Session memory for the OpenAI Agents SDK backed by PerSQL — durable conversation history in an isolated SQLite database per agent.
pip install openai-agents-persql
Usage
import os
from agents import Agent, Runner
from persql import PerSQL
from openai_agents_persql import PerSQLSession
client = PerSQL(token=os.environ["PERSQL_TOKEN"])
session = PerSQLSession("user-42", client.database("acme/agent-state"))
agent = Agent(name="assistant", instructions="Be helpful.")
result = await Runner.run(agent, "hi", session=session)
result = await Runner.run(agent, "remember me?", session=session) # history persists
Or let the session own its client:
with PerSQLSession.from_token("user-42", os.environ["PERSQL_TOKEN"], "acme/agent-state") as session:
result = Runner.run_sync(agent, "hi", session=session)
Async apps can pass an AsyncPerSQLDatabase instead — calls are awaited natively rather than dispatched to a thread:
from persql import AsyncPerSQL
async with AsyncPerSQL(token=os.environ["PERSQL_TOKEN"]) as client:
session = PerSQLSession("user-42", client.database("acme/agent-state"))
result = await Runner.run(agent, "hi", session=session)
Storage layout
Two tables, created lazily on first use — the same layout as the SDK's built-in SQLiteSession:
agent_sessions(session_id, created_at, updated_at)agent_messages(id, session_id, message_data, created_at)
Items are stored as JSON text, so the history is queryable like any other data:
SELECT session_id, COUNT(*) AS items, MAX(created_at) AS last_active
FROM agent_messages GROUP BY session_id ORDER BY 2 DESC;
Table names are configurable via sessions_table= / messages_table=.
Local tests, no network
The persql SDK's local mode runs the same session against in-process SQLite:
session = PerSQLSession("test", PerSQL(local=":memory:").database("test/db"))
Limits
- Each session operation is one HTTP round-trip to the database (reads and writes alike ride single
query/batchcalls) — the same trade-off as the SDK's SQLAlchemy session against a remote database. - Rows are metered like any other PerSQL usage; see pricing.
PerSQLSessionimplements theSessionprotocol (get_items/add_items/pop_item/clear_session). Compaction-aware extras (run_compaction) are not implemented.
License
MIT © PerSQL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openai_agents_persql-0.1.0.tar.gz.
File metadata
- Download URL: openai_agents_persql-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbb15678f2ef18572220c55ea1976a0379fc3dd271fd854299162763c127fae2
|
|
| MD5 |
a2db8ba3dff8099feb0be2e805a42244
|
|
| BLAKE2b-256 |
d09206fd958fde59dbf98258c466135fb137967da2b8bccc887db75e089ddfcf
|
Provenance
The following attestation bundles were made for openai_agents_persql-0.1.0.tar.gz:
Publisher:
python-release-agents.yml on persql/persql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openai_agents_persql-0.1.0.tar.gz -
Subject digest:
cbb15678f2ef18572220c55ea1976a0379fc3dd271fd854299162763c127fae2 - Sigstore transparency entry: 1796472722
- Sigstore integration time:
-
Permalink:
persql/persql@91db733fbe6149a007d207b827f371e6123d6a84 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/persql
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release-agents.yml@91db733fbe6149a007d207b827f371e6123d6a84 -
Trigger Event:
push
-
Statement type:
File details
Details for the file openai_agents_persql-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openai_agents_persql-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82d72e0aa04c5b2638efca992f74fd701f53181506758b594393e4602d5c10f9
|
|
| MD5 |
784f1f822ffb8448dd27d8862f89e852
|
|
| BLAKE2b-256 |
9fedc051b0ba650e5e86d371b9e52d0dddd2939a16e95c97241901576349be33
|
Provenance
The following attestation bundles were made for openai_agents_persql-0.1.0-py3-none-any.whl:
Publisher:
python-release-agents.yml on persql/persql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openai_agents_persql-0.1.0-py3-none-any.whl -
Subject digest:
82d72e0aa04c5b2638efca992f74fd701f53181506758b594393e4602d5c10f9 - Sigstore transparency entry: 1796472846
- Sigstore integration time:
-
Permalink:
persql/persql@91db733fbe6149a007d207b827f371e6123d6a84 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/persql
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release-agents.yml@91db733fbe6149a007d207b827f371e6123d6a84 -
Trigger Event:
push
-
Statement type: