Skip to main content

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/batch calls) — the same trade-off as the SDK's SQLAlchemy session against a remote database.
  • Rows are metered like any other PerSQL usage; see pricing.
  • PerSQLSession implements the Session protocol (get_items / add_items / pop_item / clear_session). Compaction-aware extras (run_compaction) are not implemented.

License

MIT © PerSQL

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai_agents_persql-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openai_agents_persql-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

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

Hashes for openai_agents_persql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cbb15678f2ef18572220c55ea1976a0379fc3dd271fd854299162763c127fae2
MD5 a2db8ba3dff8099feb0be2e805a42244
BLAKE2b-256 d09206fd958fde59dbf98258c466135fb137967da2b8bccc887db75e089ddfcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for openai_agents_persql-0.1.0.tar.gz:

Publisher: python-release-agents.yml on persql/persql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openai_agents_persql-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_agents_persql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82d72e0aa04c5b2638efca992f74fd701f53181506758b594393e4602d5c10f9
MD5 784f1f822ffb8448dd27d8862f89e852
BLAKE2b-256 9fedc051b0ba650e5e86d371b9e52d0dddd2939a16e95c97241901576349be33

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page