Openai Django Sessions banner
knowsuchagency knowsuchagency

Openai Django Sessions

Development community

Description

Django ORM-based session backend for the OpenAI Agents SDK

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

openai-django-sessions

Django ORM-based session backend for the [OpenAI Agents SDK](https://github.com/openai/openai-agents-python).

Store your agent conversation history in any Django-supported database (PostgreSQL, MySQL, SQLite, etc.) with full async support.

Installation

pip install openai-django-sessions

Requirements

  • Python 3.12+
  • Django 5.0+
  • openai-agents 0.1.0+

Quick Start

from agents import Agent, Runner
from openai_django_sessions import DjangoSession

async def chat():
    # Create a session (auto-creates tables in development)
    session = DjangoSession("user-123", create_tables=True)

    agent = Agent(name="Assistant", instructions="You are a helpful assistant.")

    # First message
    result = await Runner.run(agent, "Hello!", session=session)
    print(result.final_output)

    # Follow-up (session maintains conversation history)
    result = await Runner.run(agent, "What did I just say?", session=session)
    print(result.final_output)

Usage

Basic Usage

from openai_django_sessions import DjangoSession

# Simple instantiation
session = DjangoSession("user-123")

# With auto table creation (for development/testing)
session = DjangoSession("user-123", create_tables=True)

Custom Table Names

session = DjangoSession(
    "user-123",
    sessions_table="my_agent_sessions",
    messages_table="my_agent_messages",
    create_tables=True,
)

Using with Django Settings

# Semantic alias that uses Django's configured database
session = DjangoSession.from_settings("user-123", create_tables=True)

API Reference

DjangoSession

class DjangoSession(SessionABC):
    def __init__(
        self,
        session_id: str,
        *,
        sessions_table: str = "agent_sessions",
        messages_table: str = "agent_messages",
        create_tables: bool = False,
    ) -> None: ...

    @classmethod
    def from_settings(
        cls,