Integration

Memory for LlamaIndex agents

LlamaIndex retrieves passages from the documents you index. What a passage index does not model is time: which fact is current, what it replaced, and what was true on a given date. This page shows an HTTP pattern for adding dated, source-backed memory to a LlamaIndex agent.

Jump to the code

What the framework does not keep

  • Which value is current. Writing two values for the same fact leaves two records, and similarity does not say which one is true now.
  • When a fact happened. A record has a write time unless your code adds the event time.
  • One person across sources. The same customer in an email and a chat is two entries unless something joins them.

The pattern: memory as a tool

Give the agent two functions: one that sends text with its date, one that asks a question. Your code binds the signed-in user, so the model never chooses whose memory it reads. Pass the returned tools to your agent.

import os
import requests
from llama_index.core.tools import FunctionTool

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 [FunctionTool.from_defaults(fn=recall_memory), FunctionTool.from_defaults(fn=store_memory)]

What recall returns

Ranked memory 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

  • Resuming and replaying one conversation: use LlamaIndex's own thread state. That is its job.
  • Facts that change, histories that need dates and sources, or memory shared across sessions: use the API pattern above.

Frequently asked questions

Is there a LlamaIndex package?

No package is needed. The pattern above uses plain HTTP calls, so it works with any version.

Where does the user id come from?

From your application. Your code reads it from the signed-in user and sends it in the X-Harny-User header and the identity field.

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.