Skip to content

LearnTutorials

Improve agent memory with dreaming in Claude Managed Agents

Use dreaming in Claude Managed Agents to turn past agent sessions into a cleaner memory store, so your agent learns from its own work over time.

By Recaply EditorsAdvanced21 min6 stepsUpdated

A hand files a loose index card into an open box of cards under a crescent moon

What you need

Dreams run on the Claude API only while they're in research preview. Managed Agents sessions aren't eligible for zero data retention.

  1. Step 1: Install the CLI and sign in

    3 min

    The CLI handles sign-in and beta headers for you, so every later command stays short.

    1. Request dreaming access on Anthropic's form and wait for approval.
    2. On a Mac, run the commands below. On Linux, get the binary from the anthropic-cli releases page.
    3. Sign in to your Claude Console account when ant auth login asks.
    Run this
    brew install anthropics/tap/ant
    ant auth login

    You should see a finished sign-in in the terminal, with no error.

    Dream commands fail with an access error?

    Access to Managed Agents doesn't include dreams. Request the research preview on the form, then use the CLI or an SDK so the dreaming-2026-04-21 header is sent for you.

    If you use an API key instead, keep it in the ANTHROPIC_API_KEY variable. Never put it in YAML files you share or commit.

  2. Step 2: Create a memory store

    3 min

    The store is where your agent keeps what it learns, and it's the input a dream later cleans up.

    1. Save the text below as memory_store.yaml. Change the name and description to fit your agent.
    2. Run ant apply memory_store.yaml.
    3. Copy the store ID, which starts with memstore_.
    Your memory_store.yaml
    name: Support notes
    description: What the support agent has learned about [YOUR PRODUCT]: fixes that worked, customer preferences and mistakes to avoid.

    You should see a new memory store ID that starts with memstore_.

    The request comes back with a 400 error?

    Memory store calls use the agent-memory-2026-07-22 beta header. Sending it together with managed-agents-2026-04-01 fails, so swap one for the other if you set headers yourself.

    The agent reads the description, so say what belongs in the store. Each memory holds up to 100 kB, and a store holds up to 10,000 memories.

  3. Step 3: Give each session the store

    5 min

    A store attaches only when a session starts, and each session that writes to it gives the dream more to work with.

    1. Start a session with the command below, with your IDs and task filled in.
    2. Send the session its task from your app or the SDK, as you do now.
    3. Run at least 3 sessions on the same kind of task, and note each session ID.
    Run this
    ant beta:sessions create <<YAML
    agent: [YOUR AGENT ID]
    environment_id: [YOUR ENVIRONMENT ID]
    resources:
      - type: memory_store
        memory_store_id: [YOUR MEMSTORE ID]
        access: read_write
        instructions: Check these notes before you start. Save what you learn about [YOUR TASK].
    YAML

    You should see a session ID that starts with sesn_, and new memories in the store after each run.

    The agent never reads or writes its notes?

    Check that the agent has the agent_toolset_20260401 tools. The store is mounted under /mnt/memory/, and the session's mount_path field shows the exact folder.

    With read_write access, a prompt injection in untrusted input can plant false notes. Attach a store read_only when the agent only needs to read it.

  4. Step 4: Start a dream

    3 min

    A dream reads the store and the transcripts, then writes a new store with duplicates merged and stale notes replaced.

    1. Fill in the store ID and 3 or more session IDs. A dream takes up to 100 sessions.
    2. In instructions, say what the agent should get better at.
    3. Run the command, then copy the dream ID, which starts with drm_.
    Run this
    ant beta:dreams create <<YAML
    inputs:
      - type: memory_store
        memory_store_id: [YOUR MEMSTORE ID]
      - type: sessions
        session_ids:
          - [SESSION ID 1]
          - [SESSION ID 2]
          - [SESSION ID 3]
    model: claude-opus-5-5
    instructions: Focus on [WHAT THE AGENT SHOULD GET BETTER AT]. Ignore one-off notes.
    YAML

    You should see a dream with the status pending, which moves to running once the work starts.

    The dream fails with input_session_unavailable?

    An input session was deleted after the dream started. Leave the input store and sessions alone until the dream ends, then start a new dream.

    Only some models run dreams, such as Claude Opus 5.5, Claude Sonnet 5.5 and Claude Fable 5.1. Your input store is never changed.

  5. Step 5: Review the new store

    5 min

    The dream writes a separate store, so you decide if its version of memory is better.

    1. Run the first command until the status reads completed. A dream takes minutes to a few hours.
    2. Copy the memory_store_id listed under outputs.
    3. Run the second command to list the new store's memories, then read a few of them.
    Run this
    ant beta:dreams retrieve --dream-id [YOUR DREAM ID]
    
    ant beta:memory-stores:memories list --memory-store-id [OUTPUT MEMSTORE ID] --path-prefix "/"

    You should see fewer, tidier memories, with duplicates merged and old facts replaced by the latest ones.

    The output store looks half finished?

    A failed or canceled dream leaves a partial store behind. Read the dream's error field, delete that store, and try again with fewer sessions.

    To fix a single memory by hand, use ant beta:memory-stores:memories update on the output store. Dream instructions steer the whole pass, not single lines.

  6. Step 6: Switch to the curated store

    2 min

    New sessions only benefit from the cleaner memory once you attach it.

    1. Start new sessions with the output store's ID in place of the old one.
    2. Once you trust the new store, archive the old one with the command below.
    Run this
    ant beta:memory-stores archive --memory-store-id [OLD MEMSTORE ID]

    You should see new sessions working from the curated store, and the old store marked as archived.

    Archiving can't be undone. An archived store becomes read-only and can't be attached to new sessions.

You get

An agent that starts each session from a cleaned-up memory, built from its own past work

Did this guide work for you?

Sources