Integration

Memory for OpenAI Agents SDK agents

The OpenAI Agents SDK keeps the agent's own state: tools, handoffs and session history for a conversation. This page shows how to add Harny memory to an agent so each signed-in person has a private, dated memory the agent can read.

Jump to the code

What the framework does not keep

  • Which value is current. Harny memory is dated: a changed value with a newer timestamp becomes the current value, and the earlier value stays answerable by date.
  • When a fact happened. You send a timestamp with each item, and recall returns occurredAt for each result.
  • One person across sources. Harny keeps one private memory per person, and your app names the person with the X-Harny-User header.

The pattern: memory as a tool

Each function is wrapped with function_tool and given to the agent. The code binds the signed-in user to each tool. The tools call the Memory API with that user's id, and the agent answers from what those calls return.

The agent keeps its own session history for the conversation. Harny holds the person's memory, which the agent reads through recall with an as-of date or a time range when the question depends on when something happened.

import os
import requests

BASE = "https://api.harny.ai/v1/memory"

def make_memory_tools(user_id: str):
    headers = {
        "Authorization": f"Bearer {os.environ['HARNY_APP_KEY']}",
        "X-Harny-User": user_id,  # set by your application, never by the model
    }

    def recall_memory(question: str) -> str:
        """Look up what is known about this user that is relevant to a question."""
        r = requests.post(f"{BASE}/recall", headers=headers,
                          json={"query": question, "identity": user_id})
        return r.text

    def store_memory(text: str, happened_at: str) -> str:
        """Save a fact with the ISO time it happened."""
        r = requests.post(f"{BASE}/ingest", headers=headers,
                          json={"content": text, "timestamp": happened_at})
        return r.text

    return [recall_memory, store_memory]

from agents import Agent, Runner, function_tool

agent = Agent(
    name="Account assistant",
    instructions="Use recall_memory before you answer a question about a customer.",
    tools=[function_tool(f) for f in make_memory_tools(user_id)],
)
result = Runner.run_sync(agent, "What is the Acme pilot budget?")
print(result.final_output)

What recall returns

Memory results with dated sources and source labels. Every result has a rank, names the data point (source) behind it and the date it happened.

  • POST https://api.harny.ai/v1/memory/ingest takes id, content, label and timestamp.
  • POST https://api.harny.ai/v1/memory/recall takes query and identity, and returns results with sources.

Example: your agent asks “what is the Acme pilot budget?” and gets this back. Your code hands the model the content and the source label, so it can say who said it and when.

{
  "asOf": "2026-07-29T00:00:00Z",
  "results": [
    {
      "rank": 1,
      "occurredAt": "2026-07-28T16:00:00Z",
      "content": "Acme pilot budget: currently 40k.",
      "sources": [
        { "sourceId": "call-8821", "label": "Email from Nadia" }
      ]
    }
  ]
}

When to use which

  • Use the framework's own session state for the current conversation's messages, tool calls and handoffs, which is its job.
  • Add Harny when an agent must remember a person's facts across sessions, know which value is current, or answer what was true on a past date.

Frequently asked questions

Is a package needed?

The Python SDK is installed with pip install harny. Your agent can also call the Memory API directly with your app key, from a server.

Where does the user id come from?

Your app sets the X-Harny-User header to the id of the person who is signed in. The tool binds that id. End users need no Harny account.

Go on. Get Harny.

The first 500 monthly-active end users are free for good. Create an app key and make your first call in minutes.