On this page
Anthropic released Claude Fable 5.2 today. It has a one-million-token context window, up to 128,000 output tokens, adaptive thinking that cannot be switched off, and list prices of $8 per million input tokens and $40 per million output tokens. Every task in this series so far finished in a handful of turns. This last part gives the agent a task that does not: auditing 144 repeat prescriptions against written rules, which takes 80 to 130 tool calls. It runs the task on Fable 5.2 and on Claude Opus 5.5 with the same loop, and scores both against an answer key.
The loop is the hand-written one from Part 1, which Part 4 recommended for narrow, regulated agents, rebuilt for length. It keeps the history append-only, compacts the conversation on demand when it passes a threshold, writes a checkpoint after every turn, enforces a budget and refuses to accept “done” until the back end agrees. Both models found all 151 expected findings with no false ones. The interesting results are in how they got there and what it cost, including one mistake of mine that made the first Fable run 19% more expensive than it needed to be.

What Fable 5.2 changes for an agent loop
| Fable 5.2 behaviour | What it means for the loop |
|---|---|
Adaptive thinking is always on; {"type": "enabled"} and {"type": "disabled"} return a 400 | Send {"type": "adaptive"} or omit thinking. Code written for budget-based thinking breaks. |
Effort runs from low to max; the default is high | Set effort explicitly. The same request on Opus 5.5 (default medium) and Fable 5.2 thinks differently unless you do. |
The thinking prefix check is enforced for every account: editing system, tools or earlier messages and then replaying a thinking block returns a 400 | The history must be append-only, from the first turn to the last. Compaction is the supported way to shorten it. |
tool_choice of type any or tool returns a 400 | As on Opus 5.5: use strict tool schemas and auto. |
| 30-day data retention is required; not available under zero data retention unless Anthropic authorises it | A decision for your data protection officer before any real patient data reaches the model. |
Anthropic’s documentation lists Fable 5.2 as a Covered Model that requires 30-day data retention and is not available under zero data retention without express authorisation. Server-side compaction is not HIPAA-eligible either. For a clinical deployment, the model choice is also a data-processing decision: confirm it against your agreement and your DPIA before switching models, and keep real identifiers out of anything you test with. Everything in this article is synthetic.
A long task with an answer key
The agent audits a practice’s repeat prescriptions against four rules written into its system prompt, as of an audit date of 9 November 2026. NO_REPEATS: no repeats left. OVERDUE: repeats left but more than 60 days since the last dispense. STALE: issued more than 180 days ago. DUPLICATE_CLASS: the same patient has two active prescriptions in the same therapeutic class, such as two statins. The last rule needs clinical knowledge the data does not contain; the model has to recognise that sertraline and citalopram are both SSRIs.
The data is generated from a fixed seed, and the same rules applied in code produce the answer key: 56 findings for 48 prescriptions, or 151 for 144. The agent never sees the key. It works through five strict tools: get_progress, list_prescriptions (eight a page), get_details (up to four records), record_findings and mark_reviewed. The findings register is append-only and idempotent, so a repeated call cannot create duplicates.
The loop, built for length
Three things change from the short loops earlier in the series. The first is compaction. When the previous response shows the context above a threshold we choose, the loop sends a compaction request (beta compact-2026-09-04) and replaces the whole history with the signed block that comes back:
def _compact(client, cfg: LongRunConfig, st: RunState) -> bool:
"""Replace the history with a signed summary. Returns False (history untouched) if none came back."""
resp = _request(client, cfg, st.messages, cache_control={"type": "ephemeral"},
compaction={"type": "summarize", "instructions": COMPACTION_INSTRUCTIONS})
used = billed_usage(resp.usage) # sums usage.iterations, which include the compaction
st.usage.add(used)
block = next((b for b in resp.content if b.type == "compaction"), None)
if resp.stop_reason != "compaction" or block is None or block.content is None:
st.events.append({"event": "compaction_skipped", "turn": st.turns, "stop_reason": resp.stop_reason})
return False
st.messages = [{"role": "assistant", "content": _as_dicts([block])}, # signed block first, unchanged
{"role": "user", "content": "Continue the audit from the summary. Call get_progress first."}]
st.compactions += 1
return TrueThe custom instructions tell the model what the next stretch of work needs, including the medicines already seen for any patient whose prescriptions are only partly reviewed, because the duplicate rule depends on them. They also forbid tool calls, which the documentation warns can otherwise replace the summary. If no summary comes back, the history is left alone and the loop carries on.
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#FBF1EB','primaryTextColor':'#3D3929','primaryBorderColor':'#CC785C','lineColor':'#3D3929','actorBkg':'#FBF1EB','actorBorder':'#CC785C','actorTextColor':'#3D3929','signalColor':'#CC785C','signalTextColor':'#1F1E1D','noteBkgColor':'#FFF8F3','noteBorderColor':'#CC785C','noteTextColor':'#3D3929'}}}%%
sequenceDiagram
participant L as Your loop
participant API as Claude API
participant R as Findings register
L->>API: turn n, context above 40k tokens
API-->>L: tool_use record_findings, mark_reviewed
L->>R: record and mark the batch
L->>API: same history plus compaction summarize
API-->>L: one signed compaction block
Note over L: history becomes the block and a continue message
L->>API: next turn from about 4.5k tokens
API-->>L: tool_use get_progress
L->>R: what is left?The second is that progress lives in the back end. A summary can drop something; the register cannot. The system prompt tells the model that its earlier conversation may be replaced, and that get_progress, not its memory, is the record. After every compaction in the live runs, the first call was get_progress.
The third is that the loop never takes the model’s word for being finished. Fable 5.2’s documentation notes that turns can end early on long multistep tasks. If a response ends while the register still shows work remaining, the loop says so and continues. A checkpoint after every turn, written atomically, holds the messages exactly as returned and the register’s state, so --resume continues with a history that passes the prefix check.
Live runs
All runs used the Claude API from Azure Cloud Shell, effort high on both models, a compaction threshold of 40,000 tokens and a $4 budget. The first started the 48-prescription audit on Fable 5.2 and stopped it after four turns to simulate an interruption. By then Fable had fetched every record, running many get_details calls in parallel, and recorded all 56 findings, but marked nothing reviewed. Resuming from the checkpoint finished the job in three more turns, with no prefix-check error:

Fable also found a flaw in the register. One of its notes started with a stray fragment; it re-submitted a clean note, and the register refused it as already recorded, because idempotency was keyed on prescription and rule. It reported this rather than claiming the fix had worked. An idempotent write that silently drops a correction is a real design problem in an audit trail: the register needs a separate amend operation that keeps the original and records who changed it and why.
Forty-eight prescriptions never reached the compaction threshold, so the next runs used 144. The first Fable run compacted once at turn 11, taking the context from 42,034 tokens to 4,572, and scored 151 of 151. It also showed 44,690 uncached input tokens. The compaction request had gone out without a cache breakpoint, so it could not read the history the previous turn had cached, and about 42,000 tokens were billed at the full $8 per million.

With cache_control on the compaction request, the same compaction read 40,904 tokens from the cache with 127 uncached, and cost $0.19 instead of roughly $0.60. Fable 5.2 then audited the 144 prescriptions in 18 turns and 81 tool calls, for $1.7653. Opus 5.5, run once with the same loop, took 46 turns and 129 tool calls, compacted at turn 28 for $0.06, and cost $1.0423.


| Run | Turns | Tool calls | Compaction | Time | Cost | Score |
|---|---|---|---|---|---|---|
| Fable 5.2, 48 (stopped at 4, resumed) | 7 | 23 | none | 94 s | $0.6959 | 56 / 56 |
| Fable 5.2, 144, compaction uncached | 19 | 79 | turn 11, about $0.60 | 215 s | $2.1058 | 151 / 151 |
| Fable 5.2, 144 | 18 | 81 | turn 11, $0.19 | 213 s | $1.7653 | 151 / 151 |
| Opus 5.5, 144 | 46 | 129 | turn 28, $0.06 | 239 s | $1.0423 | 151 / 151 |
What the results say
- Both models were exact. Every expected finding was recorded and nothing else, across a task with date arithmetic, boundary cases (one prescription was stale by a single day) and a rule that needed pharmacology the data did not contain. With rules this clear, correctness did not separate the models.
- Fable 5.2 worked in larger steps. It asked for many records per turn and finished in 18 turns to Opus 5.5’s 46. End to end the two took a similar time, 213 and 239 seconds, because Fable’s turns were longer.
- Opus 5.5 was cheaper here. At half the list price per token it cost $1.04 against $1.77. On a well-specified task like this, Fable’s capability does not show up in the score, so the cheaper model wins. Fable’s documentation recommends starting at effort
highand sweeping; a harder task, with judgement the rules do not settle, is where that sweep would be worth running. - The context window was never the constraint. Fable 5.2 can hold a million tokens. The loop compacted at 40,000 because every turn re-reads the context, cached or not, and a smaller context is cheaper and faster on every one of them. Compaction is a cost control first.
- Compaction is a request like any other. It is billed, it reads the history, and it needs a cache breakpoint to read it cheaply. Count its usage from
usage.iterations, where the documentation puts it, not from the top-level fields.

Five parts, one agent
This series built the same prescription assistant five times. Part 1 wrote the tool-use loop by hand: stop reasons, parallel calls, an approval gate, errors the model can act on. Part 2 moved it onto the Claude Agent SDK and found the configuration that a domain agent needs. Part 3 moved to API version 2026-10-21 and added server tools, whose calls you can only audit after they have run. Part 4 measured the two designs side by side and found that the model’s habits differ between harnesses. This part made the loop survive length. The lesson that runs through all five is the same: put the controls that matter, approvals, preconditions, progress, budgets, retention, in code and configuration you own and can test without the model, and let the model do the reasoning.
The sample was tested with Python 3.12, anthropic 2.6.0 and pytest 8.3.3: 9 offline tests cover the append-only history, compaction and its usage, a compaction that returns no summary, stop and resume, the early-finish nudge, the budget, the register and the scoring. Five live runs used Claude Fable 5.2 and Claude Opus 5.5 on the Claude API from Azure Cloud Shell; the screenshots and the results file in the repository are from those runs. Costs are calculated from the API’s usage fields, including usage.iterations, at list prices. Scores compare the findings register with an answer key computed from the same generated data. Model behaviour and limits are from Anthropic’s documentation for Claude Fable 5.2 and for compaction. Each comparison is one run per model. All data is synthetic.
Key takeaways
- Fable 5.2 enforces the thinking prefix check for every account: keep the history append-only from the first turn and shorten it only with compaction.
- Keep progress in the back end and make the agent read it, so neither a summary nor a restart can lose work.
- Put a cache breakpoint on the compaction request; without one, the first live compaction cost about three times as much.
- Both models scored 151 of 151; Opus 5.5 cost $1.04 and Fable 5.2 $1.77, so measure before paying for capability a task does not need.
- Fable 5.2 requires 30-day data retention and is not available under zero data retention: settle that before any real patient data.
What is the longest task you have trusted an agent to finish on its own, and what made you trust it? Tell me in the comments.
The complete sample for this article is on GitHub: nithinmohantk/blog-samples-working-repo/claude-agent-series/part5-long-horizon. Clone it with git clone https://github.com/nithinmohantk/blog-samples-working-repo.git and open the claude-agent-series/part5-long-horizon folder. Its README says how to run it and what has been verified.
Glossary
- Claude Fable 5.2
- Anthropic’s model released on 9 November 2026, with a one-million-token context window and always-on adaptive thinking.
- Long-horizon agent
- An agent whose task takes many turns and tool calls, so it must manage context and survive interruptions.
- Prefix check
- The API’s check that everything before a thinking block is unchanged; a mismatch on Fable 5.2 is a 400.
- Append-only history
- A conversation in which earlier messages are never edited, reordered or removed.
- Compaction
- Replacing older turns with a summary the model writes, returned as a signed block.
- On-demand compaction
- Compaction you request explicitly with the
compactionparameter, under betacompact-2026-09-04. - usage.iterations
- The per-step usage of a request, including any compaction; sum it to get billed tokens.
- Checkpoint
- A saved copy of the conversation and back-end state after a turn, used to resume.
- Findings register
- The back-end record of audit findings; idempotent and append-only in the sample.
- Answer key
- The expected findings computed in code from the generated data, used to score each run.
- Precision and recall
- The share of recorded findings that were correct, and the share of expected findings that were recorded.
- Effort
- The setting that controls how much Claude thinks; Fable 5.2 defaults to
high. - Zero data retention (ZDR)
- An arrangement under which request data is not retained; Fable 5.2 is not available under it without authorisation.
References & Further Reading
- → What’s new in Claude Fable 5.2— Specifications, thinking, the prefix check and data retention
- → Compaction— Server-side compaction modes
- → Compaction on demand— The compaction request, its block and missing summaries
- → Threshold compaction— Automatic compaction, usage.iterations and caching
- → Claude API release notes— The 9 November release of Claude Fable 5.2
- → Part 1: Writing the tool-use loop yourself— The loop this part extends
- → Part 4: Hand-written loop or Agent SDK?— Why this part uses the hand-written loop
- → Sample code for this article— Tests, live runs and screenshots
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.