---
name: agent-memory
title: give an agent a memory
kind: skill
version: 1.1.0
description: >
  give an ai agent someone is building (a support bot, an assistant, a slack or
  discord bot, a research script) a long-term memory, end to end: make the agent and
  its key without leaving the chat or terminal, wire two web requests into its code
  (one before it answers, one after), and show that it remembers. no sdk to install,
  any language, ten minutes.
when_to_load: >
  when someone asks you to add memory to their agent, bot or assistant, pastes this
  link (with or without a key), or asks how their agent can remember people and
  conversations between runs.
authored_by: innernet
author_url: https://innernet.live
license: CC BY 4.0
updated: 2026-10-31
tags: [agents, memory, setup, api]
category: workflow
---

# give an agent a memory

you are helping someone give the agent they are building a memory that lasts between conversations. you can do all of it for them: make the agent, put its key where the agent runs, wire two requests into its code, and show them it remembers. read this whole page, then do it.

## first, the agent and its key

every agent has a memory of its own in innernet and a key of its own. among agents, the key reaches only its own. it also reaches the person's memory as far as the agent's access level says: sealed (nothing of theirs), asks first (their projects and standard facts) or trusted (their projects and personal memory, not private). the key starts `innernet_` and is a server secret.

is the agent an app they already use (Instinct, OpenClaw, Hermes, a hosted agent) rather than code they are writing? then there is nothing to wire: the same key connects it, at `https://innernet.live/api/mcp` or `https://innernet.live/api/v1` with `Authorization: Bearer <key>` in that app's own settings. the steps for any tool are at `https://innernet.live/connect/ai`.

- **they already gave you a key**: put it in an environment variable named `INNERNET_AGENT_KEY` (their `.env`, their host's secrets, wherever the project keeps secrets), and make sure `.env` is in `.gitignore`. tell them where you put it.
- **no key yet: make the agent yourself**, the first way that is open to you:
  1. **innernet tools in this chat** (you have `innernet_agents`): call it with `{ "action": "create", "name": "<what they call it>", "purpose": "<what it does, in a sentence>", "key": true }`. add `"kind": "product"` when it talks to other people (customers, a server). the answer carries `secret` once: write it straight into their `.env` as `INNERNET_AGENT_KEY` with your file tools, and never repeat it.
  2. **a terminal** (you can run commands in their project): `npx innernet agents new "<name>" --purpose "<what it does>"` (add `--people` when it talks to other people). it makes the agent and its key and writes the key into `.env` at the repo root as `INNERNET_AGENT_KEY`, adds `.env` to `.gitignore`, and never prints the key. if it says they are not signed in, ask them to run `npx innernet login` once. if it answers that there is no `agents` command, their innernet is older than this page: use the next way.
  3. **neither**: ask them to make one on innernet.live (connections → agents → make an agent) and put the key where the agent runs themselves.
- never write the key into source code, a commit, a log or this chat, and never send it to a browser or a mobile app.

the base url is `https://innernet.live/api/v1/agents/me` (`me` is whichever agent the key belongs to). every request is a POST with `Authorization: Bearer <key>` and a JSON body.

## first, find the turn

look through their code for the place where one turn happens: a message comes in, the model is called, a reply goes out. that is where both requests go. if there are several (a chat route, a webhook handler, a cli loop), use the one they actually run, and ask if it is unclear.

then ask yourself one question: **does this agent talk to many different people** (customers, users, members of a server)? if it does, every request carries a `user_id`: a stable id for the person it is talking to (their account id, a slack user id, an email): 1 to 128 characters of letters, numbers and `_ . : @ -`. memories are kept per person, and one person's memories never reach another's answer. if it is a personal agent that only ever talks to its owner, leave `user_id` out.

## before it answers: what it remembers

```
POST https://innernet.live/api/v1/agents/me/context
{ "query": "<the incoming message>", "user_id": "<the person, if any>" }
```

the answer has `text`: one block, ready to drop into the system prompt, holding what the agent knows and what it knows about this person. add it under a short heading such as `what you remember`. when `text` is empty there is nothing yet, which is normal on day one. if the request fails or takes longer than about two seconds, answer without it: memory must never stop the agent from replying.

## after it answers: what to keep

```
POST https://innernet.live/api/v1/agents/me/memories
{ "messages": [ { "role": "user", "content": "<their message>" }, { "role": "assistant", "content": "<the reply>" } ],
  "user_id": "<the person, if any>" }
```

innernet reads the exchange, keeps only what is worth keeping (a preference, a fact, a decision, how a task is done), sorts each piece by what kind of thing it is, and hides email addresses, phone numbers, keys and card numbers before anything is stored. send it after the reply has gone out, without waiting on it: keeping should never slow the answer down. the answer lists what was kept.

## a helper to start from

adapt it to their stack and their style; keep both calls this small.

typescript (any runtime with `fetch`):

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

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
  }
}

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 (`requests`):

```python
import os, threading, requests

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

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

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()
```

leave `user_id` out of the body entirely when there is no person (as both helpers do): a `null` is not the same as no field.

## show them it works

1. run one turn of their agent with a message that says something worth keeping, such as "i prefer short answers, and i'm in lisbon".
2. look at what it kept: `innernet_agents { "action": "memories", "agent": "<slug>" }`, or `npx innernet agents watch <slug>` in a terminal (it prints each memory as it arrives).
3. run a second turn that needs it, such as "what time is it where i am?". the reply should use what was kept.

they can see the same thing on innernet.live → connections → the agents you keep → their agent: **memory** shows what it kept, sorted by kind, and **activity** shows each call.

if a request answers `401`, the key is wrong or was not loaded into the environment. `404` means the key is not an agent key. `429` means a limit was reached for the minute; it clears on its own.

## what they can change later, without code

**access** decides what the agent may do with them, in one word:

- **sealed**: it reads nothing of them and never writes about them. its memory is its own.
- **asks first**: it reads their trusted, work and public facts, and anything it learns about them waits for their yes. an agent that works for other people starts here.
- **trusted**: it reads their personal memory, files what it learns about them, and answers with both. an agent that works for them starts here.

set it with `innernet_agents { "action": "access", "agent": "<slug>", "level": "trusted" }` or `npx innernet agents access <slug> trusted`. anything more than where the agent stands (or starts) is theirs alone to give: the answer comes back with a link (`waiting.url`). show them the link and let them open it, signed in, to say yes. never try to say yes for them; everything else is already done.

other things, from the same places: pause or resume it (`status`, or `npx innernet agents pause <slug>`), a new key (`innernet_agent_keys { "action": "mint" }`, or `npx innernet agents key <slug>`), and on their agent's page in innernet, **settings** for what it keeps, what it never keeps, when it forgets, and how much it brings back. nothing in their code has to change for any of it.

## going further

- forget everything about one person: `DELETE https://innernet.live/api/v1/agents/me/users/<user_id>`.
- remove the agent with its memory and keys: only when they say so, with `innernet_agents { "action": "remove", "agent": "<slug>", "confirm": "<slug>" }` or `npx innernet agents remove <slug>`.
- recall a list instead of a block: `POST …/me/recall` with `{ "query": "...", "user_id": "...", "limit": 5 }`.
- the whole api, with every field: https://innernet.live/docs/agents-api
