Skip to main content

The pattern

Before your agent compresses its context, call /flush. This re-encodes all facts from the server-side .mem file and injects a fresh [MEM] block. Compression operates on the fresh signal. Facts survive.
import httpx

def compress_with_memory(agent, user_id: str, api_key: str):
    # 1. Flush memory before compression
    httpx.post(
        "https://api.spectralmemory.com/flush",
        json={"user_id": user_id},
        headers={"Authorization": f"Bearer {api_key}"},
    )
    # 2. Now compress — memory is safe
    agent.compress()

Why this works

The .mem file on disk is the ground truth for all encoded facts. /flush always reconstructs a valid FDM signal from it. Even if the compressor drops the old [MEM] block entirely, the fresh block injected by /flush contains all facts intact.

When to call /flush

  • Before any operation that truncates the agent’s context window
  • Before ending a session if the agent will resume with a compressed context
  • Proactively every N turns if your agent has automatic compression

Response

{
  "status": "ok",
  "channel_count": 3,
  "lossless": true
}
lossless: true means the re-encoded block contains the same facts as the previous block. This is always the case — /flush reads from the source .mem file, not from the current prompt state. If no facts have been encoded, status is "empty" and channel_count is 0.