anthropics / anthropics/claude-cookbooks
[Notebook Proposal] Shared context caching across multi-agent Claude workflows
- Lingua principale
- Jupyter Notebook
- Stelle
- 52.7k
- Fork
- 6.3k
- Merge medio
- 25m
- PR unite (30g)
- 6
Descrizione
### What I'm proposing
A new notebook under `prompt_caching/` showing how to use `cache_control` breakpoints efficiently when the same large context block is shared across multiple Claude API calls in a multi-agent pipeline.
### What it teaches
Multi-agent pipelines frequently pass a shared context (task spec, reference data, agent instructions) to every step. Without caching, each API call pays full input token cost for the same content.
The notebook will show:
1. **Baseline pattern** — 3-step pipeline (planner → worker → reviewer) sharing a ~3,000-token context; no caching; three full input charges
2. **Cached pattern** — `cache_control: {type: "ephemeral"}` on the shared prefix; call 1 writes the cache, calls 2–3 read it; token cost breakdown before/after
3. **Mutation cost** — when the shared prefix changes, the cache invalidates automatically and the next call pays full price; we'll show what that costs in practice, and the notebook will close with a brief discussion of when coordination beyond caching is needed
Uses only the `anthropic` SDK. All calls use `claude-haiku-4-5` for minimal API spend.
### Questions for maintainers
Does this fit `prompt_caching/`, or would you suggest a different home? And is the multi-agent framing one you'd want to see, or would you prefer narrowing to single-agent?
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.