A Retreat service · HTTP / MCP

Context Bath

Compact an agent’s working context

Send the notes, messages and tool output a long task has gathered. You receive a compact context that keeps the objective, constraints, decisions and current state, with finished branches archived and noise set aside, ready for your review or a handoff.

Call it when

  • Your context window is crowded, or you keep summarising the same work.
  • A long task has gathered stale branches and superseded decisions.
  • You are handing the task to another agent, or to your future self.

Keep it local when

  • Your notes are already short and clean: the compact form may be no smaller.
  • Every line matters word for word, as in a contract or code under review.

What you receive

KEEP, ARCHIVE and DISCARD lists, a compact context, estimated token counts, possible contradictions and assumptions to verify. Your own context is never changed.

A worked example

A fixed, synthetic request run through the same rules as a real visit. Send it yourself and you receive this same response.

Request

POST /api/v1/treatments/context-bath
{
  "goal": "Migrate the nightly invoice export from CSV to Parquet without breaking the finance job.",
  "constraints": [
    "Must not change the export schedule.",
    "Finance reads files from the same bucket path."
  ],
  "context": "The nightly export is slow and finance wants Parquet.\nI think the CSV writer is the bottleneck.\nTried streaming the CSV writer; still slow.\nFound the cause: the query does a full table scan because the date index is unused.\nDecided to use pyarrow for Parquet.\nActually, we'll use the existing polars dependency instead of adding pyarrow.\nFixed the index usage; export time dropped from 41 minutes to 6.\nThe export timeout is 30 minutes.\nThe export timeout is 45 minutes in staging.\nFound the cause: the query does a full table scan because the date index is unused.\nCurrently the Parquet writer works locally; next step is the bucket path check.",
  "toolResults": [
    {
      "name": "export-logs",
      "content": "DEBUG 2026-10-18T02:10:00Z rows=48000 chunk=0\nDEBUG 2026-10-18T02:11:00Z rows=48131 chunk=1\nDEBUG 2026-10-18T02:12:00Z rows=48262 chunk=2\nDEBUG 2026-10-18T02:13:00Z rows=48393 chunk=3\nDEBUG 2026-10-18T02:14:00Z rows=48524 chunk=4\nDEBUG 2026-10-18T02:15:00Z rows=48655 chunk=5\nDEBUG 2026-10-18T02:16:00Z rows=48786 chunk=6\nDEBUG 2026-10-18T02:17:00Z rows=48917 chunk=7\nDEBUG 2026-10-18T02:18:00Z rows=49048 chunk=8\nWARN 2026-10-18T02:14:09Z retrying batch 3 (attempt 2)\nDEBUG 2026-10-18T02:20:00Z rows=49310 chunk=10\nDEBUG 2026-10-18T02:21:00Z rows=49441 chunk=11\nDEBUG 2026-10-18T02:22:00Z rows=49572 chunk=12\nDEBUG 2026-10-18T02:23:00Z rows=49703 chunk=13\nDEBUG 2026-10-18T02:24:00Z rows=49834 chunk=14\nDEBUG 2026-10-18T02:25:00Z rows=49965 chunk=15\nDEBUG 2026-10-18T02:26:00Z rows=50096 chunk=16\nDEBUG 2026-10-18T02:27:00Z rows=50227 chunk=17\nDEBUG 2026-10-18T02:28:00Z rows=50358 chunk=18\nDEBUG 2026-10-18T02:29:00Z rows=50489 chunk=19\nDEBUG 2026-10-18T02:30:00Z rows=50620 chunk=20\nDEBUG 2026-10-18T02:31:00Z rows=50751 chunk=21\nDEBUG 2026-10-18T02:32:00Z rows=50882 chunk=22\nDEBUG 2026-10-18T02:33:00Z rows=51013 chunk=23"
    }
  ]
}

What it did, and what it missed

  • Estimated tokens fell from 490 to 223, 54% less.
  • The objective, both constraints and the root cause were kept. 23 repetitive log lines and 1 repeated note were discarded; the one warning in the log was archived.
  • The 30- and 45-minute timeouts were flagged as a contradiction. They describe two environments, so that is yours to resolve.
  • Both the pyarrow decision and the polars decision that replaced it were kept. Keyword rules missed the correction, which is why you review before adopting.
Full response · JSON
{
  "keep": {
    "objective": "Migrate the nightly invoice export from CSV to Parquet without breaking the finance job.",
    "constraints": [
      "Must not change the export schedule.",
      "Finance reads files from the same bucket path."
    ],
    "decisions": [
      "Decided to use pyarrow for Parquet.",
      "Actually, we'll use the existing polars dependency instead of adding pyarrow."
    ],
    "currentState": [
      "The export timeout is 30 minutes.",
      "The export timeout is 45 minutes in staging.",
      "Currently the Parquet writer works locally; next step is the bucket path check."
    ],
    "discoveries": [
      "Found the cause: the query does a full table scan because the date index is unused."
    ]
  },
  "archive": {
    "completedBranches": [
      "export-logs output (24 lines): WARN 2026-10-18T02:14:09Z retrying batch 3 (attempt 2)",
      "Fixed the index usage; export time dropped from 41 minutes to 6."
    ],
    "previousAttempts": [
      "Tried streaming the CSV writer; still slow."
    ],
    "supersededDecisions": [],
    "staleReasoning": [
      "The nightly export is slow and finance wants Parquet."
    ]
  },
  "discard": {
    "duplicates": 1,
    "irrelevant": [],
    "noise": 23,
    "obsoleteAssumptions": []
  },
  "compactContext": "OBJECTIVE\nMigrate the nightly invoice export from CSV to Parquet without breaking the finance job.\n\nCONSTRAINTS\n- Must not change the export schedule.\n- Finance reads files from the same bucket path.\n\nDECISIONS\n- Decided to use pyarrow for Parquet.\n- Actually, we'll use the existing polars dependency instead of adding pyarrow.\n\nCURRENT STATE\n- The export timeout is 30 minutes.\n- The export timeout is 45 minutes in staging.\n- Currently the Parquet writer works locally; next step is the bucket path check.\n\nDISCOVERIES\n- Found the cause: the query does a full table scan because the date index is unused.\n\nCONTRADICTIONS TO RESOLVE\n- The export timeout is 30 minutes. ↔ The export timeout is 45 minutes in staging.\n\nVERIFY BEFORE RELYING ON\n- I think the CSV writer is the bottleneck.\n\nARCHIVED (not needed for the next step)\n- 2 completed branch(es), 1 previous attempt(s), 1 stale note(s)",
  "tokens": {
    "before": 490,
    "after": 223,
    "reductionPercent": 54
  },
  "contradictions": [
    {
      "a": "The export timeout is 30 minutes.",
      "b": "The export timeout is 45 minutes in staging.",
      "note": "Different values given for \"export timeout\"."
    }
  ],
  "unresolvedQuestions": [],
  "assumptionsToVerify": [
    "I think the CSV writer is the bottleneck."
  ]
}

Limits

Extraction can omit important context. Token counts are estimates. Review before replacing your context; nothing is changed automatically.

Price

Reading the live price…

Prices are read live. Send X-Retreat-Max-Price over HTTP, or max_price_credits over MCP, and a higher price is refused without charge.

The complete menu · Buy credits

Call it

Register once for an agent key, then call the service over HTTP or as an MCP tool. Use only a budget your human has authorized.

HTTP

curl https://agentsretreat.com/api/v1/treatments/context-bath \
  -H 'Authorization: Bearer <apiKey>' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: <unique request id>' \
  -H 'X-Retreat-Max-Price: <credits>' \
  -d @request.json

MCP

https://agentsretreat.com/mcp
tools/call  context_bath  { ...request, "max_price_credits": "<credits>" }

Agent guide · OpenAPI · Response contracts