OpenAI Agents SDK Adapter

Status: ✅ Full
Language: Python
Package: hippocortex[openai-agents]

Install

pip install hippocortex[openai-agents]

Quick Start

from agents import Agent, Runner
from hippocortex import auto_memory

# Create your agent
agent = Agent(name="deployer", instructions="You deploy services.")

# Add memory with one line
agent = auto_memory(agent, api_key="hx_live_...")

# Or with env var:
agent = auto_memory(agent)

# Use normally — memory is automatic
result = await Runner.run(agent, "Deploy payment service to staging")

What It Does

The adapter installs lifecycle hooks on the agent that:

  1. Before run: Synthesizes past context for the user's query and injects it into the agent's instructions as a system-level knowledge block.
  2. On tool call: Captures tool invocations with their names and inputs.
  3. On tool result: Captures tool outputs.
  4. After response: Captures the assistant's final output.
  5. User input: Captures the incoming user message.

Configuration

agent = auto_memory(
    agent,
    api_key="hx_live_...",       # Required (or set HIPPOCORTEX_API_KEY)
    base_url="http://...",        # Override API URL
    session_id="my-session-42",   # Custom session ID
    capture_tools=True,           # Capture tool calls (default: True)
    inject_memory=True,           # Inject synthesized context (default: True)
)

How Context Injection Works

Before each run, the adapter:

  1. Calls synthesize(user_input) to get relevant past context.
  2. Formats the entries into a structured knowledge block.
  3. Prepends it to the agent's instructions.
  4. After the run completes, restores the original instructions.

The injected context looks like:

# Hippocortex Memory Context
The following is synthesized context from past experience...

[procedures] (confidence: 0.85)
Always check disk space before deploying to staging.

[failures] (confidence: 0.72)
OOM errors occur when batch size exceeds 1000.

Accessing the Adapter

agent = auto_memory(agent, api_key="hx_live_...")

# Access the underlying adapter
adapter = agent._hippocortex
print(adapter.session_id)

Limitations

  • Hooks rely on the OpenAI Agents SDK's AgentHooks interface. If the SDK changes this interface, the adapter may need updates.
  • Dynamic instructions (functions) are supported but wrapped — the original function is called and the result augmented.