Volume I · Part II · Chapter 9
Orchestration and Agentic Topologies
A customer asks for a refund. Imagine the support assistant looking up the account, drafting a reply and checking the refund rule. It also updates its memory and writes a trace of the work. What the customer sees is one answer. What we pay for depends on all the systems it called to come up with it.
The first version may have a small memory store, a tool server and a gateway. As it grows, the history gets longer and the agent reads it again every turn. A retry may repeat work at several layers, while an agent waiting for a person can tie up a sandbox for hours. A failed memory write can leave the application running and answering badly. Each behavior has a different cost, and each leads to a different decision about what the team should change.
How to read this chapter
Start with the refund. Once the bill can be traced to a task someone recognizes, the examples on memory, parallel workers and retries show which changes can make that task cheaper or faster.
Follow one task through the layer
Before it drafts an answer, the assistant turns the customer’s question into an embedding and searches its memory. We pay for the embedding tokens and the vector query. When the draft suggests a refund, a tool server checks the order system, whose response time and limits now matter to the customer. It may charge for the request as well. After sending the reply, the assistant may call the model again to decide what to keep in memory. The trace ties that work together, with a bill of its own for ingestion and storage.
When one team owns the model deployment and another runs the memory cluster, it can take several invoices to find the cost of one refund. The task identifier from Chapter 8 has to travel with calls, tool requests and storage operations if we want to total them by agent, workflow or customer. We also have to agree how to divide the cost of shared services such as the memory cluster. OpenTelemetry context propagation can carry an identifier between services, and the Model Context Protocol revision discussed below can carry it into tool calls.12
If a memory write fails quietly, the assistant may return a worse draft the next time because a fact it needs is missing. The retry can repeat work at every system it calls. Changing the model may be an expensive response to a fault in the memory store.
The memory layer
Reading a whole conversation on every turn can get expensive. A memory store gives the model a shorter history to read, in exchange for the work of writing and searching it. On one long-conversation benchmark, Mem0’s paper reports about 1,800 tokens of retrieved memory against 26,000 for the full history, a 95th-percentile response time of 1.4 seconds against 17, and somewhat lower accuracy.3 Memory vendors dispute one another’s figures. I would use the result to decide what to measure on our conversations, and budget for the work of writing memories as well as reading them. Graphiti, the open-source framework at the core of Zep’s service, runs a language model over each new episode to extract entities and relationships, and by default limits ingestion to ten concurrent operations to avoid the provider’s rate-limit errors.4 Ingestion competes with the agent for any limits they share, unless it runs in the background, off the response path, during a quieter interval.5
Storage growth depends on what each design keeps and what, if anything, it removes. Mem0’s update step can delete a contradicted fact, though its memory decay feature changes only search ranking.67 Graphiti marks superseded facts invalid instead of deleting them.8 Letta, which grew out of the MemGPT research, now keeps memory as files in a git repository, a shift it announced in March 2026; files at the memory root load into the system prompt on every turn, and every edit is committed.910 Preserved history may be exactly what the application needs, but storage then grows with every change, and a deletion request has to reach the history.
Vector storage shows which choices matter. Qdrant’s capacity guide sizes dense vectors as points × replicas × dimensions × bytes per dimension, adds a term for the HNSW search graph, and keeps both in RAM by default.11 For illustration, one million new memories a month at 1,536 dimensions, stored as 32-bit floats with two replicas, need 12,000,000 × 2 × 1,536 × 4 bytes ≈ 147 GB a year; the graph, at the default of 16 links per point, adds 24,000,000 × 16 × 2 × 4 bytes × 1.2 ≈ 3.7 GB. That is about 151 GB of RAM per retained year before payloads and the headroom Qdrant recommends, and three years of retention triples it. Fewer dimensions, or a quantized copy in RAM with the originals on disk, shrink the vector term if search quality survives the test. Before comparing prices, agree with the workload owner and privacy specialists on what the store may keep and how deletion reaches indexes, derived memories, history and backups; a forecast that assumes indefinite retention should say so.
Tool servers and MCP
The Model Context Protocol connects AI applications to tools and data. Its current revision, dated July 28, 2026, made the protocol stateless: the initialization handshake and protocol-level sessions are gone, and a server that needs state across calls issues an explicit handle and keeps the state itself.12 With stdio, each client launches a subprocess, so the number to plan for depends on how the clients are deployed and how long they run. Even a local process can call remote APIs on credentials someone pays for. A Streamable HTTP server can serve many clients independently. Under the stateless revision it can sit behind an ordinary load balancer, with state kept in the store that backs its handles. That store and the downstream APIs belong on the bill beside the server.
The order of the tool list can reach the bill. The revision calls for a deterministic order, because tool definitions often sit in the prompt and a shuffled list can cost all the agents that use it a cache hit. It also leaves the client to send an in-flight request again when the response stream breaks. If the tool issues refunds, it needs a way to recognize the repeated request before it pays a customer twice. Calling tools in sequence adds waiting, while calling them in parallel shifts the load to the tools and the systems behind them. For a third-party server, find out who operates it, what data it sees, what limits it enforces and what happens if it goes away. The official registry, still in preview, is a place to find a server.13
The harnesses
The harness is the runtime that puts the system prompt, context, tools, memory and execution environment together. A design choice as small as putting another tool description in the system prompt charges for it on every turn. Pi advertises its minimal prompt as a saving and ships without subagents. Claude Code warns when custom subagent descriptions pass 15,000 tokens.1415 Its subagents have their own context and tools and can run cheaper models, though they draw on the same usage limits as the main conversation.16
Where the harness runs code also changes the bill. Hermes Agent can run locally, over SSH, in Docker or in hosted sandboxes, some of which hibernate when idle. What starts as a laptop process can end up as a fleet of metered containers.17 If a run fails after doing half the work, see how much can be recovered. Anthropic’s managed agent service keeps an append-only session log outside the harness so a replacement can continue from the last event. Pi’s experimental Durable package, released October 1, 2026, checkpoints every step.1819
I would also check what the managed service leaves us to run. Microsoft Foundry Agent Service’s basic setup keeps agent data in Microsoft-managed storage. Its standard setup puts files, conversation state and vector stores in our own Azure Storage, Azure Cosmos DB and Azure AI Search resources, and requires at least 3,000 RU/s of Cosmos DB throughput per project. Provisioned throughput bills by the hour even when no agent runs, while serverless mode bills for consumption in a single region.20 For the support assistant, I would ask the platform team who owns retention and throughput for each of those services. Its usage and charges should appear when we estimate what a month of replies costs.
Provider-held state also has a lifecycle, so whoever hosts the runtime, I would keep a copy of any conversation history the business needs; when OpenAI retired its Assistants API on August 26, 2026, developers had to rebuild earlier conversations from messages they had stored themselves.21
Topologies
An agent may work alone with tools, pass work through a pipeline, or delegate to parallel workers. Each arrangement changes context reuse, latency and coordination. None is reliably the cheapest: isolating a subtask can avoid replaying irrelevant context, while unnecessary delegation can duplicate it. Even a single agent can accumulate substantial input consumption by repeatedly sending its growing history.
Start with that single agent, because its cost is the easiest to underestimate. Each turn feeds the model the system prompt, the tool definitions and everything that has happened so far. With a prefix of tokens, tokens added per turn and turns, the task consumes
input tokens. With illustrative values of and , a 20-turn task consumes 200,000 + 380,000 = 580,000 input tokens and a 40-turn task 400,000 + 1,560,000 = 1,960,000. Twice the turns cost 3.4 times the input, so a forecast built on the average number of turns understates the average task.
Prompt caching changes both the price and the headroom of that loop. At Anthropic’s standard rates, a five-minute cache write costs 1.25 times the base input price, a read costs 0.1 times, and each read renews the lifetime.22 If each turn reads the history so far and writes only its new tokens, the 40-turn task reads 1,872,000 tokens and writes 88,000, for 1,872,000 × 0.1 + 88,000 × 1.25 = 297,200 base-rate tokens, about 15 percent of the uncached price. On most Claude models, cached reads also do not count toward the input-tokens-per-minute limit, so caching stretches the quota as well as the budget.23 A timestamp near the top of the system prompt is enough to break the identical prefix the discount depends on.
Anthropic reported that in its data, agents used about four times the tokens of chat interactions and its multi-agent research system about fifteen times; early versions spawned 50 subagents for simple queries until the prompts carried explicit scaling rules.24 I would use those figures to ask how our harness decides when to delegate, then measure what it does on our work.
For illustration, suppose four workers each receive a 10,000-token brief and produce 5,000 output tokens. Their calls consume 4 × 10,000 = 40,000 input tokens and 4 × 5,000 = 20,000 output tokens. If the orchestrator then reads all four results once, that adds 20,000 input tokens. The subtotal is 60,000 input plus 20,000 output tokens, before the orchestrator’s own brief, answer, reasoning and any further calls. To find the overhead, compare that subtotal with a single agent doing the same useful work. The extra briefings and the calls to read the workers’ answers can erase the saving on a cheaper model, as Chapter 8’s example showed. The workers also start together, so their 40,000 input tokens reach a per-minute rate limit as one burst, and an orchestrator that waits for all four is held up by the slowest.
Cognition, the company behind Devin, argues for a single-threaded agent that compresses its own history, because actions carry implicit decisions and parallel workers that cannot see one another’s choices produce conflicting work.25 The two accounts are closer than Cognition’s title suggests: Anthropic’s report also says most coding tasks have less to parallelize than research.26 I would compare the arrangements on the actual tasks, by cost per accepted task against the same baseline.
Concurrency, retries and held resources
Some costs accrue for as long as a resource is held, used or not. Little’s law, which Chapter 5 applied to load tests, gives the average number held: in a stable system, the average number present equals the arrival rate times the average time each one stays, .27 If a coding agent receives 120 tasks an hour through a sustained busy period and each holds a sandbox for 15 minutes of work, sandboxes are working on average. If one task in five then waits two hours for a reviewer with its sandbox still allocated, those 24 tasks an hour hold another . More sandboxes are waiting than working, and the pool needs headroom above the average because arrivals bunch.
Expiry decides what the waiting costs. Releasing a sandbox and recreating it on resume trades startup time for held capacity, and provisioning one only when a task first needs it, as Anthropic’s managed service does, spares the tasks that never run code.28 The prompt cache lapses during a pause too: resuming the 40-turn task at turn 30 after the five-minute cache has expired costs 68,000 × 1.25 = 85,000 base-rate tokens to rewrite the history, against 6,600 + 2,500 = 9,100 to read 66,000 and write 2,000, and the extra 75,900 is about a quarter of the cached task’s whole input price.
Retries multiply across layers. In the Google SRE book’s example, if the backend, frontend and browser code each make up to four attempts, one user action can become 4 × 4 × 4 = 64 attempts at an overloaded database; the book advises against retrying at several levels and recommends a retry budget with randomized exponential backoff.29 An agent stack adds the model itself, which may decide to try a failed tool call again, and each model-level retry resends the context. If the 40-turn task fails at turn 30 and starts over, it repeats 300,000 + 870,000 = 1,170,000 input tokens, about 60 percent of the task’s input, before doing anything new. A harness that resumes from a durable session log pays at most one cache rewrite. For the agent’s own loop, a step limit does the work of a retry budget.
The operating inventory
I would use an inventory like this when a workflow’s cost starts to rise. It helps trace each charge to the part of the application that can explain it.
| Component | What it is | Consumption scales with | Bill shape |
|---|---|---|---|
| Model gateway | Routing, retries and fallbacks | Traffic × retries at the gateway | Gateway tier, request charges or self-run compute; model charges remain separate |
| Prompt cache | Reuse of identical prompt prefixes | Repeated prefixes within the cache lifetime | Premium on writes, discount on reads; reads may not count toward rate limits30 |
| Session store | Conversation state with time-to-live expiry | Concurrent sessions × retention | Stored state and infrastructure; expiry is a policy choice |
| Memory service | Extracted facts, episodes and instructions | Writes × model calls per write; retained history | Extraction and embedding calls, retrieval queries, storage under the retention policy |
| Vector database | Similarity search over embeddings | Vectors × dimensions × replicas, plus query rate | RAM-heavy nodes or hosted tiers |
| Graph database | Entities and relationships, sometimes with validity intervals | Entities × traversal rate; superseded facts if kept | Licensing varies by engine; self-hosting is an operations obligation |
| Tool/MCP servers | Structured access to external systems | Agent activity × tools per step × retries | Per-seat or per-call hosted, or self-run processes; downstream charges separate |
| Sandbox runners | Isolated execution for generated code | Arrival rate × holding time, including waits | Compute time or session charges; startup and expiry affect cost |
| Observability | Traces of agent steps and tool calls | Agent activity × sampling rate | Ingestion plus storage; sampling is a cost decision |
Tracing needs its own retention and sampling policy, so consequential actions remain explainable without storing everything forever. OpenTelemetry’s generative-AI conventions, still in development, define spans for agent invocations, tool calls and memory operations, and token attributes that separate cache reads and writes from other input; check which of them a given tracing product captures.31
What the review inherits
A monthly review is a good place to ask why the assistant costs more to run. It is a poor place to discover that the tracing team and the team that runs the models count different work. Tie the events back to the same task and owner before bringing the figures to the people who know the workflow. Otherwise, the many small calls add up to a bill that nobody can explain, a familiar long-tail problem in Volume II, Chapter 15.
I would start with the tasks customers accepted and those the assistant abandoned. If an expensive run spent two hours waiting for approval, ask who can release the sandbox. If it repeatedly failed at the same tool call, find out which layer can stop the retries. Where the bill includes a growing memory store, ask the owner which history the work still needs and whether deletion reaches the indexes, history and backups. Chapter 22 of Volume II gives those owners a place to make the decisions together.
Failed tasks weigh heavily in that cost because an agent that never converges keeps going until a limit stops it. In the illustrative loop above, suppose 9,000 of 10,000 tasks succeed in 20 turns (580,000 input tokens each) and 1,000 fail at a 40-turn limit (1,960,000 each). The failures are a tenth of the tasks but 1.96 billion of 7.18 billion input tokens, or 27 percent, and input per accepted task is 7.18 billion ÷ 9,000 ≈ 798,000 tokens rather than 580,000. A 30-turn limit would cut that to 710,000, about 11 percent less, if no task that would have succeeded after turn 30 is lost. Only the distribution of turns to success can show whether that holds.
For economic viability, Anthropic wrote, multi-agent systems need tasks whose value is high enough to pay for the increased performance.32 The workflow owner can say what a resolved ticket or a merged change is worth. I would ask that person whether the parallel run solved enough harder cases, or shortened enough waits, to pay for itself. The answer may be different for an overnight research job and an ordinary refund. If the team decides to run the model on rented or owned hardware, it still needs that comparison. It will also have to measure how much of the work the hardware can deliver in time.
Notes and sources
OpenTelemetry, GenAI semantic conventions, checked October 3, 2026; formerly published under opentelemetry.io. Status: Development. Defines agent, tool and memory operations and token attributes for cache reads and writes; support varies by product.↩︎
Model Context Protocol, revision 2026-07-28: key changes, transports and tools; and the MCP Registry, in preview; all checked October 3, 2026. Source for the protocol behavior described in this chapter. Implementations adopt revisions at different speeds.↩︎
Prateek Chhikara and colleagues, “Mem0: Building Production-Ready AI Agents with Scalable Long-Term Memory”, arXiv, April 2025. LOCOMO results (full context: 26,031 tokens, 72.90 percent judged accuracy, 17.117 s at p95; Mem0: 1,764 tokens, 66.88 percent, 1.440 s) and the add, update and delete operations. Vendor-authored; Zep disputes the evaluation in “Is Mem0 Really SOTA in Agent Memory?”, May 6, 2025, updated June 3, 2026.↩︎
Zep, Graphiti, checked October 4, 2026. LLM extraction into a bi-temporal graph; superseded facts are invalidated, not deleted; ingestion concurrency defaults to 10 to avoid provider rate-limit errors; Zep’s managed service runs on its own proprietary graph database. Vendor documentation of an open-source framework.↩︎
LangChain, “Memory overview”, checked October 3, 2026. The memory taxonomy, following Theodore R. Sumers and colleagues’ “Cognitive Architectures for Language Agents” (2023), and the trade-off between writing memories in the hot path and in the background. Framework documentation, not a measurement.↩︎
Prateek Chhikara and colleagues, “Mem0: Building Production-Ready AI Agents with Scalable Long-Term Memory”, arXiv, April 2025. LOCOMO results (full context: 26,031 tokens, 72.90 percent judged accuracy, 17.117 s at p95; Mem0: 1,764 tokens, 66.88 percent, 1.440 s) and the add, update and delete operations. Vendor-authored; Zep disputes the evaluation in “Is Mem0 Really SOTA in Agent Memory?”, May 6, 2025, updated June 3, 2026.↩︎
Mem0, platform changelog, entry of May 4, 2026, checked October 3, 2026. Describes Memory Decay as a search-time ranking bias that “never filters a candidate out.” Vendor documentation.↩︎
Zep, Graphiti, checked October 4, 2026. LLM extraction into a bi-temporal graph; superseded facts are invalidated, not deleted; ingestion concurrency defaults to 10 to avoid provider rate-limit errors; Zep’s managed service runs on its own proprietary graph database. Vendor documentation of an open-source framework.↩︎
Charles Packer and colleagues, “MemGPT: Towards LLMs as Operating Systems”, arXiv, 2023. An agent-managed memory hierarchy modeled on virtual memory; the research origin of Letta, whose current design differs.↩︎
Letta, “Letta’s Next Phase”, March 16, 2026, and MemFS documentation, checked October 4, 2026. Git-backed memory files; root files load into the system prompt every turn, and every edit is committed. Vendor documentation.↩︎
Qdrant, “Capacity Planning”, checked October 4, 2026. Source of the dense-vector and HNSW sizing formulas (m = 16 by default), the default RAM tier, and the advice to quantize “only if the resulting search quality is acceptable.” The guide also adds an ID-tracker term and recommends spare headroom, both left out of the illustration. One engine’s formulas.↩︎
Model Context Protocol, revision 2026-07-28: key changes, transports and tools; and the MCP Registry, in preview; all checked October 3, 2026. Source for the protocol behavior described in this chapter. Implementations adopt revisions at different speeds.↩︎
Model Context Protocol, revision 2026-07-28: key changes, transports and tools; and the MCP Registry, in preview; all checked October 3, 2026. Source for the protocol behavior described in this chapter. Implementations adopt revisions at different speeds.↩︎
Earendil, Pi, checked October 3, 2026, and “Pi Durable”, October 1, 2026. A minimal harness without subagents, described as token-efficient because of its small system prompt (vendor claim); the experimental Pi Durable package checkpoints each step and resumes after a crash.↩︎
Anthropic, “Create custom subagents”, Claude Code documentation, checked October 4, 2026. Separate context windows and tool access, shared usage limits, routing to cheaper models, and the 15,000-token description warning. Vendor documentation; limits change between releases.↩︎
Anthropic, “Create custom subagents”, Claude Code documentation, checked October 4, 2026. Separate context windows and tool access, shared usage limits, routing to cheaper models, and the 15,000-token description warning. Vendor documentation; limits change between releases.↩︎
Nous Research, Hermes Agent, checked October 4, 2026. Open-source harness with local, Docker, SSH and hosted terminal backends; the Daytona and Modal backends hibernate when idle (vendor description). The description is documented capability, not an endorsement of fitness for another organization.↩︎
Lance Martin, Gabe Cemaj and Michael Cohen, “Scaling Managed Agents: Decoupling the brain from the hands”, Anthropic, April 8, 2026. The session log sits outside the harness, so a replacement resumes from the last event, and containers are provisioned only when a task needs one. Vendor description of its own service; the Claude Managed Agents overview, checked October 4, 2026, lists the service as in beta.↩︎
Earendil, Pi, checked October 3, 2026, and “Pi Durable”, October 1, 2026. A minimal harness without subagents, described as token-efficient because of its small system prompt (vendor claim); the experimental Pi Durable package checkpoints each step and resumes after a crash.↩︎
Microsoft, “Set up standard agent resources”, updated July 9, 2026, and “Foundry Agent Service frequently asked questions”, checked October 3, 2026; and “Compare Provisioned Throughput and Serverless”, Azure Cosmos DB documentation, updated April 27, 2026. Basic and standard setups place agent data in different resource arrangements; the standard setup needs at least 3,000 RU/s, multiplied by the number of projects; provisioned throughput is billed hourly regardless of use, serverless by consumption in one region. Classic and new runtimes use different containers; inventory the deployed version rather than copying a fixed resource count.↩︎
OpenAI, “Assistants migration guide”, checked October 4, 2026. The Assistants API was sunset on August 26, 2026; earlier history is to be rebuilt from messages the application stored. Vendor documentation.↩︎
Anthropic, “Prompt caching” and “Rate limits”, checked October 4, 2026. Five-minute writes at 1.25 times the base input price, one-hour writes at 2 times, reads at 0.1 times (less on some newer models); hits need identical prefixes; on most models, cached reads do not count toward input-tokens-per-minute limits. Provider-specific and subject to change.↩︎
Anthropic, “Prompt caching” and “Rate limits”, checked October 4, 2026. Five-minute writes at 1.25 times the base input price, one-hour writes at 2 times, reads at 0.1 times (less on some newer models); hits need identical prefixes; on most models, cached reads do not count toward input-tokens-per-minute limits. Provider-specific and subject to change.↩︎
Jeremy Hadfield and colleagues, “How we built our multi-agent research system”, Anthropic, June 13, 2025. Source of the 4× and 15× comparisons with chat in Anthropic’s data, the 50-subagent failure and its scaling rules, the remark on coding tasks, and the value condition. Vendor-published account of one system, not a universal constant.↩︎
Walden Yan, “Don’t Build Multi-Agents”, Cognition, June 12, 2025. The case for sharing full context and running a single-threaded agent with history compression; a practitioner’s position, not a controlled result.↩︎
Jeremy Hadfield and colleagues, “How we built our multi-agent research system”, Anthropic, June 13, 2025. Source of the 4× and 15× comparisons with chat in Anthropic’s data, the 50-subagent failure and its scaling rules, the remark on coding tasks, and the value condition. Vendor-published account of one system, not a universal constant.↩︎
John D. C. Little, “A Proof for the Queuing Formula: ,” Operations Research 9, no. 3 (1961): 383–387, doi:10.1287/opre.9.3.383. Holds for long-run averages in a stable system; it says nothing about peaks.↩︎
Lance Martin, Gabe Cemaj and Michael Cohen, “Scaling Managed Agents: Decoupling the brain from the hands”, Anthropic, April 8, 2026. The session log sits outside the harness, so a replacement resumes from the last event, and containers are provisioned only when a task needs one. Vendor description of its own service; the Claude Managed Agents overview, checked October 4, 2026, lists the service as in beta.↩︎
Mike Ulrich, in Betsy Beyer, Chris Jones, Jennifer Petoff, and Niall Richard Murphy, eds., Site Reliability Engineering (O’Reilly, 2016), Chapter 22, “Addressing Cascading Failures”, checked October 3, 2026. Source of the 4³ = 64 example, the advice against retrying at multiple levels, and the retry budget. Written about serving systems; applying it to agent loops is the author’s reasoning.↩︎
Anthropic, “Prompt caching” and “Rate limits”, checked October 4, 2026. Five-minute writes at 1.25 times the base input price, one-hour writes at 2 times, reads at 0.1 times (less on some newer models); hits need identical prefixes; on most models, cached reads do not count toward input-tokens-per-minute limits. Provider-specific and subject to change.↩︎
OpenTelemetry, GenAI semantic conventions, checked October 3, 2026; formerly published under opentelemetry.io. Status: Development. Defines agent, tool and memory operations and token attributes for cache reads and writes; support varies by product.↩︎
Jeremy Hadfield and colleagues, “How we built our multi-agent research system”, Anthropic, June 13, 2025. Source of the 4× and 15× comparisons with chat in Anthropic’s data, the 50-subagent failure and its scaling rules, the remark on coding tasks, and the value condition. Vendor-published account of one system, not a universal constant.↩︎