> ## Documentation Index
> Fetch the complete documentation index at: https://www.sapientpriors.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Memories

> How turns become memories, how to list an agent's turns with filters, and how to forget specific turns in v2.

## How turns map to memories

You do not edit individual extracted facts directly. Every memory in Priors is tied back to the **turn** (message or document piece) that produced it:

```text theme={null}
Turn (a user message, an agent reply, or one piece of a file)
 └── Memories (one or more dated facts extracted from that turn)
```

When you list memories with [GET`/v2/agents/{agent_id}/memories`](https://www.sapientpriors.com/docs/api-reference/v2/memories/list-memories), Priors returns the agent's journaled turns (newest first) along with each turn's learning `state`. When you forget a turn with [DELETE`/v2/agents/{agent_id}/memories/{turn_id}`](https://www.sapientpriors.com/docs/api-reference/v2/memories/forget-a-memory), Priors deletes every memory made from that turn in one call.

Both endpoints need a role that may see the agent's memories: Org admin, Project admin, or Agent admin of that agent, or the creator of a private agent. See [Roles and permissions](https://www.sapientpriors.com/docs/access/roles.md).

* With a service-account key, call **without** `X-SP-End-User`. An end user can only chat and teach.
* A caller who reaches the agent without that role gets `403 forbidden`. A caller who does not reach it gets `404 agent_not_found`.

## List memories (turns)

Send [GET`/v2/agents/{agent_id}/memories`](https://www.sapientpriors.com/docs/api-reference/v2/memories/list-memories). Narrow results with optional query filters:

| Parameter | Meaning |
| - | - |
| `thread_id` | Return only turns from this thread (works even after the thread was deleted). |
| `file_id` | Return only turns that came from or cited this file. |
| `speaker_id` | Return only turns sent with this `speaker_id`. |
| `limit` | Page size (1 to 100, default 50). |
| `cursor` | Pass `next_cursor` from the previous response to read the next page. |

```bash theme={null}
curl "https://app.sapientpriors.com/api/v2/agents/agent_01J.../memories?thread_id=thread_01J...&limit=50" \
  -H "Authorization: Bearer $SP_API_KEY"
```

```json theme={null}
{
  "items": [
    {
      "turn_id": "thread_01J...:4",
      "thread_id": "thread_01J...",
      "speaker": "Priya",
      "speaker_id": "prospect-4471",
      "text": "Our new phone number is 555-0199.",
      "timestamp": "2026-09-17T10:12:00Z",
      "file_ids": [],
      "state": "learned",
      "file_piece": false
    }
  ],
  "next_cursor": null
}
```

### Turn fields

| Field | Meaning |
| - | - |
| `turn_id` | Identifier to pass (URL-encoded) to [DELETE`.../memories/{turn_id}`](https://www.sapientpriors.com/docs/api-reference/v2/memories/forget-a-memory). |
| `state` | `learned` (memories exist), `learning` (still being extracted), `not_learned` (extraction failed; resend if needed), or `forgotten` (memories were deleted). |
| `file_piece` | `true` when this turn is a piece of an uploaded document; delete the file instead of the individual piece. |

## Forget a turn's memories

Send [DELETE`/v2/agents/{agent_id}/memories/{turn_id}`](https://www.sapientpriors.com/docs/api-reference/v2/memories/forget-a-memory). **Always URL-encode `turn_id`** because an id can contain `/` or `#`.

```bash theme={null}
curl -X DELETE "https://app.sapientpriors.com/api/v2/agents/agent_01J.../memories/thread_01J...%3A4" \
  -H "Authorization: Bearer $SP_API_KEY"
```

**Success:** status `204` with no body.

### What forgetting removes, and what stays

* **Removed:** every memory extracted from that exact `turn_id`.
* **Stays (marked `forgotten`):** the turn record remains in conversation history with `state: "forgotten"` so service restarts or resumes never re-learn it.
* **Stays (other turns):** memories extracted from **other** turns are untouched. If the same fact was repeated in a second user message, or echoed in an agent reply that was learned (`learn_reply: true`), list the thread's turns and forget those turns too.

> [!WARNING]
>
> Deleting a turn removes only the memories made from that turn. When removing sensitive data or correcting a mistake, inspect adjacent turns in the same thread (including agent replies) and forget any turn that restated the same fact.

### Errors on `DELETE /v2/agents/{agent_id}/memories/{turn_id}`

| Status | `code` | Cause | What to do |
| - | - | - | - |
| `403` | `forbidden` | Caller reaches the agent, but its role cannot see or delete memories, or the call sent `X-SP-End-User`. | Use a key with the Project admin role or Agent admin of this agent, without `X-SP-End-User`. |
| `404` | `agent_not_found` | Caller does not reach the agent, or the agent does not exist. | Check `agent_id` and which project your key belongs to. |
| `404` | `not_found` | No turn matches `turn_id`. | Check the id and URL encoding. |
| `409` | `conflict` | The turn is a document piece (`file_piece: true`), is still `learning`, or multiple turns share the same id. | For a file piece, call [DELETE`/v2/agents/{agent_id}/files/{file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/files/delete-file) instead. For a turn still `learning`, wait and retry. |
| `409` | `agent_not_ready` | Agent is still initializing. | Poll until `status` is `ready`. |

## Common workflows

* **Forget a whole thread:** list turns with [GET`/v2/agents/{agent_id}/memories?thread_id={thread_id}`](https://www.sapientpriors.com/docs/api-reference/v2/memories/list-memories), page until `next_cursor` is `null`, and forget each non-file turn (works before or after deleting the thread).
* **Forget a whole document:** call [DELETE`/v2/agents/{agent_id}/files/{file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/files/delete-file) and poll its `Location` header ([GET`.../memories?file_id={file_id}`](https://www.sapientpriors.com/docs/api-reference/v2/memories/list-memories)) until every turn is `forgotten`.
* **Forget everything on an agent:** call [DELETE`/v2/agents/{agent_id}`](https://www.sapientpriors.com/docs/api-reference/v2/agents/delete-agent). See [C3. A customer leaves](https://www.sapientpriors.com/docs/how-to-use/customer-leaves.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.