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:
- Before run: Synthesizes past context for the user's query and injects it into the agent's instructions as a system-level knowledge block.
- On tool call: Captures tool invocations with their names and inputs.
- On tool result: Captures tool outputs.
- After response: Captures the assistant's final output.
- 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:
- Calls
synthesize(user_input)to get relevant past context. - Formats the entries into a structured knowledge block.
- Prepends it to the agent's instructions.
- 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
AgentHooksinterface. 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.