/community/guides/agent memory
innernet
docsskillscommunitycompanydeveloperssecurityprivacytermscontact

agent memory · step 5 of 8

wire it into your code

an agent's memory is two small calls, one before it answers and one after. here they are in curl, typescript and python, ready to copy, with the one rule for agents that talk to many people, and what comes back.

/community/guides/agent-memory-in-your-code
5 of 8
step 1 of 83 minmeet agent memoryevery agent you build or use, from a support bot to Grok Bot, Hermes or OpenClaw, can keep a memory of its own. what that memory is, the three ways to make one, and the film of it working. start here.
step 2 of 83 minmake one on the dashboardthe easiest way in, even if you have never wired a memory before. connect an agent in the agents space, paste one block into the ai you code with, and watch it remember.
step 3 of 83 minmake one from the terminalone command in your agent's folder makes the agent and its key, puts the key straight into .env and keeps it out of git. then set what it may do with you, try it, and watch what it keeps, without leaving the terminal.
step 4 of 83 minmake one from any chatany ai connected to innernet can make and run your agents for you. say what you want in plain words, teach the agent one thing and ask it back before any code runs, and let a coding agent wire it in end to end.
step 5 of 84 minwire it into your codean agent's memory is two small calls, one before it answers and one after. here they are in curl, typescript and python, ready to copy, with the one rule for agents that talk to many people, and what comes back.
step 6 of 84 minyour personal agentsGrok Bot, Muse, Hermes, OpenClaw and Instinct, each on one memory. how to connect every one of them, what each can do once it's in, and how to give a personal agent a memory of its own.
step 7 of 83 minwhat it may do with youone choice decides how far an agent goes with you, sealed, asks first or trusted, and four lines say exactly what gets in and out. what it learns about you waits for your yes, and only you can give an agent more of you.
step 8 of 84 minsee everything it keepsan agent's memory is never a black box. its own page shows what it keeps, sorted by kind, every call it made, what its memory did for it, its keys, its sub-agents and the people it serves, and every setting is yours to change.

whichever door you used, an agent's memory comes down to two requests. the ai you code with can add them for you (say "give my agent a memory: innernet.live/skills/agent-memory/raw"), but they're small enough to read and write yourself.

the loop: before it answers, ask what it remembers; after it answers, send the exchange
the loop: before it answers, ask what it remembers; after it answers, send the exchange

every request carries the agent's key, from the environment:

Authorization: Bearer $INNERNET_AGENT_KEY

and goes to the agent's own address. with an agent's key, the agent is always me:

https://innernet.live/api/v1/agents/me

before it answers: what it remembers

send the message that just came in. what comes back in text is ready to put in your prompt: what the agent knows, dated, best first.

curl https://innernet.live/api/v1/agents/me/context \
  -H "Authorization: Bearer $INNERNET_AGENT_KEY" \
  -H "content-type: application/json" \
  -d '{"query": "the message that just came in"}'

after it answers: what to keep

send the exchange. innernet keeps what matters, decides what kind of thing each piece is, and hides keys, passwords and card numbers before anything is stored. you never decide what to keep by hand.

curl https://innernet.live/api/v1/agents/me/memories \
  -H "Authorization: Bearer $INNERNET_AGENT_KEY" \
  -H "content-type: application/json" \
  -d '{"messages": [{"role": "user", "content": "…"}, {"role": "assistant", "content": "…"}]}'

the same, as a helper

typescript

const MEMORY = "https://innernet.live/api/v1/agents/me";
const headers = { Authorization: `Bearer ${process.env.INNERNET_AGENT_KEY}`, "Content-Type": "application/json" };

// before it answers: what it remembers, ready for the prompt
export async function remembered(query: string, userId?: string): Promise<string> {
  try {
    const res = await fetch(`${MEMORY}/context`, { method: "POST", headers, body: JSON.stringify({ query, user_id: userId }), signal: AbortSignal.timeout(2000) });
    return res.ok ? ((await res.json()).text ?? "") : "";
  } catch {
    return ""; // answer without memory rather than not at all
  }
}

// after it answers: what to keep
export function keep(userMessage: string, reply: string, userId?: string): void {
  void fetch(`${MEMORY}/memories`, {
    method: "POST",
    headers,
    body: JSON.stringify({ messages: [{ role: "user", content: userMessage }, { role: "assistant", content: reply }], user_id: userId }),
  }).catch(() => {});
}

python

import os, threading, requests

MEMORY = "https://innernet.live/api/v1/agents/me"
HEADERS = {"Authorization": f"Bearer {os.environ['INNERNET_AGENT_KEY']}"}

# before it answers: what it remembers, ready for the prompt
def remembered(query, user_id=None):
    try:
        body = {"query": query, **({"user_id": user_id} if user_id else {})}
        r = requests.post(f"{MEMORY}/context", headers=HEADERS, json=body, timeout=2)
        return r.json().get("text", "") if r.ok else ""
    except requests.RequestException:
        return ""  # answer without memory rather than not at all

# after it answers: what to keep
def keep(user_message, reply, user_id=None):
    body = {"messages": [{"role": "user", "content": user_message}, {"role": "assistant", "content": reply}], **({"user_id": user_id} if user_id else {})}
    threading.Thread(target=lambda: requests.post(f"{MEMORY}/memories", headers=HEADERS, json=body, timeout=10), daemon=True).start()

then, where your agent answers:

const memory = await remembered(message, customerId);
const reply = await answer({ system: `${instructions}\n\nwhat you remember:\n${memory}`, message });
keep(message, reply, customerId);

two things are worth copying as they are. the read gives up after two seconds, so a slow moment never holds an answer back. the keep runs after the reply is sent, so it never adds a wait.

one rule for agents that talk to many people

if your agent talks to different people (customers, users, members of a server), send a user_id with both calls: a stable id for the person it's talking to, like their account id, a slack id or an email. each person's memory then stays theirs, and never reaches anyone else's answer.

{ "query": "where is my order?", "user_id": "cus_8f2a" }

a personal agent that only ever talks to you leaves user_id out entirely. a null is not the same as no field.

when someone asks to be forgotten, it's one call:

curl -X DELETE https://innernet.live/api/v1/agents/me/users/cus_8f2a \
  -H "Authorization: Bearer $INNERNET_AGENT_KEY"

good to know

  • a key reaches one agent. ask it for another agent and it says there is no such agent. it never reaches your projects or your own memory directly.
  • what it reads of you is yours to set. with asks first or trusted, the context may carry what the agent may read of you, as deep as you allowed. what it may do with you explains each level.
  • a list instead of a block. POST …/me/recall with {"query": "…", "limit": 5} gives the memories one by one, each with a score.
  • a webhook, if your server wants to know. on the agent's page, settings → webhook sends a signed note when a memory is made, changed or forgotten, or when something waits for your yes.
  • every call and field is in the agents api. every setting is in agent settings.

next

bring the agents you already use into it: your personal agents.



every chapter

the fundamentals5 guidesconnecting your ai5 guidesagent memory8 guidesthe dashboard4 guidesfor builders2 guidessharing3 guides

one memory, every ai tool.

innernet is memory your ai tools read live: every project, every decision, every skill, in one place, connected once.

start your innernetevery guide