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

# Set Policy

> Replace the agent's expiry policy.

## Overview

Replaces the agent's expiry policy. Saving a policy doesn't expire anything; [Apply Policy](https://docs.memanto.ai/cloud/api/policy/apply-policy.md) does. The policy format (`retention`, `rules`, `purge_expired_after`) is the same as on Memanto local; see [Set Policy](https://docs.memanto.ai/api-reference/policy/set-policy.md) and [Memory lifecycle](https://docs.memanto.ai/reference/memory-lifecycle.md).

## Authentication

**x-api-key** `string` *required*

Your Memanto Cloud API key (`mk_...`). See [Authentication](https://docs.memanto.ai/cloud/api/introduction.md#authentication).

## Path Parameters

**agent\_id** `string` *required*

The agent's ID.

## Body

**retention** `object`

How long each memory type stays active, such as `"30d"`, `"6mo"`, `"1y"` or `"never"`. Types: `fact`, `preference`, `goal`, `decision`, `artifact`, `learning`, `event`, `instruction`, `relationship`, `context`, `observation`, `commitment`, `error`.

**rules** `array`

Checked in order; the first match wins over `retention`. Each has a `name`, a `match` (`type`, `tags`, `provenance`, `source`, `confidence_below`) and an `expire_after`.

**purge\_expired\_after** `string` (default: never)

Permanently delete memories expired for longer than this.

```bash cURL theme={null}
curl -X PUT "https://api.memanto.ai/agents/my-agent/policy" \
  -H "x-api-key: $MEMANTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "retention": {
      "context": "30d",
      "event": "90d"
    },
    "rules": [
      {
        "name": "pin-instructions",
        "match": {
          "type": [
            "instruction"
          ]
        },
        "expire_after": "never"
      }
    ],
    "purge_expired_after": "never"
  }'
```

```json 200 - OK theme={null}
{
  "agent_id": "my-agent",
  "policy": {
    "version": 1,
    "retention": {
      "context": "30d",
      "event": "90d"
    },
    "rules": [
      {
        "name": "pin-instructions",
        "match": {
          "type": [
            "instruction"
          ]
        },
        "expire_after": "never"
      }
    ],
    "purge_expired_after": "never"
  }
}
```


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