Integration

Memory for AutoGen agents

This page shows how to add Harny memory to an AutoGen agent so each person's facts stay dated and separate. Harny gives each person who uses your app a private 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. Send a timestamp (ISO 8601 with zone) with each fact, so a question about what was true in March can be answered from a dated record.
  • One person across sources. Each person's memory is separate, and your app names the person with the X-Harny-User header, so facts from different chats or tools can be saved to the same person.

The pattern: memory as a tool

Write plain functions and give them to the agent as tools. Each function calls the Memory API for the signed-in user, so the agent can save and recall that person's memory.

The code binds the signed-in user to each tool call, so the model never chooses whose memory it reads.

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 autogen_agentchat.agents import AssistantAgent

agent = AssistantAgent(
    name="account_assistant",
    model_client=model_client,  # the model client you already use in AutoGen
    tools=make_memory_tools(user_id),
    system_message="Call recall_memory before you answer a question about a customer.",
)

What recall returns

Memory results with dated sources and source labels. Every result 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 AutoGen's own state for the working conversation inside one run, where its job is to keep the messages the agent needs right now.
  • Add Harny when facts must survive past the conversation, carry a date, and stay private to each person.

Frequently asked questions

Is a package needed?

The Memory API is a set of HTTP routes, so you can call it from your server with the app key. The Python SDK, installed with pip install harny, is an option for agent loops built on Harny.

Where does the user id come from?

Your app sets the user id from the signed-in person and sends it in the X-Harny-User header. 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.