Integration
Memory for Microsoft Agent Framework agents
This page shows how to add Harny memory to a Microsoft Agent Framework agent so it can read dated, per-user memory.
What Harny memory adds
- Current value. Harny keeps dated memory, so a changed value with a newer timestamp becomes the current one and the earlier value stays answerable by date.
- When a fact happened. Harny stores each memory with its timestamp, so you can ask what was true on a given date.
- One person, kept separate. Harny keeps each person's memory separate from every other person's.
The pattern: memory as a tool
Write plain Python functions that call the Harny Memory API for recall and ingest, and give them to your agent as tools. The agent then reads and writes memory through those functions.
Call the Memory API from your server, never from a browser. Your app sends the signed-in user's id in the X-Harny-User header.
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 agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
agent = Agent(
client=OpenAIChatClient(),
instructions="Call recall_memory before you answer a question about a customer.",
tools=make_memory_tools(user_id),
)
result = await agent.run("What is the Acme pilot budget?")
print(result)What recall returns
Recall returns results with id, rank, occurredAt, content, artifact and sources. Each source carries sourceId, occurredAt and label.
POST https://api.harny.ai/v1/memory/ingesttakesid,content,labelandtimestamp.POST https://api.harny.ai/v1/memory/recalltakesqueryandidentity, and returns results withsources.
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 state for the agent's working state within a run, such as the instructions, the tools it can call and the messages in the current conversation.
- Add Harny when the agent needs memory that is dated, kept per person, and still answerable after a fact changes.
Frequently asked questions
Is a package needed?
Harny's Python SDK is installed with pip install harny. The memory calls use the Memory API routes, so you can also call them directly from your server with your app key.
Where does the user id come from?
Your app sets the user id from its own sign-in and sends it in the X-Harny-User header. A user key (fsk_) names its own user and needs no X-Harny-User.
Keep reading
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.