Scope: this page is the practices layer — how to design an agent that is both cheap and correct. For the philosophy see Agentic AI; for the technical wiring (agent definitions, orchestration, MCP) see Agentic AI Architecture; for the tool call shapes see MeshPlugin Tools.

The patterns here were distilled from tuning a real document-extraction agent — one that reads a 60–80-page financial report from a content collection and writes 60 typed fact nodes into a dimensional model. Iterating the same task from **$14 down to under $2 per run**, with correctness improving at the same time, came down to a handful of framework behaviours that are easy to get wrong. They generalise well beyond extraction.

1. The cost model: turns × context

Every tool call is a model turn, and every turn re-sends the entire conversation so far — the instructions, all prior tool results, and all intermediate text. Cost is therefore multiplicative:

cost ≈ (number of turns) × (context carried per turn)

The two levers fall straight out of that product:

Worked example: ~60 Create calls issued one per turn, on top of a context that still holds a full document, re-bills that document ~60 times. The identical work with the document absent and the creates batched costs roughly a tenth as much. The next two sections are how you make the document "absent" without losing the information in it.

2. Round semantics: what survives a round boundary

When a new user message starts a round, MeshWeaver rebuilds the conversation the model sees from the thread's stored message texts only — the ordered user and assistant cell bodies (ThreadMessage.Text). Tool calls and tool results from the previous round are not replayed. (This is LoadFullConversationHistoryFromMesh in ThreadExecution: it walks the thread's Messages, reads each cell, and reconstructs ChatMessage(role, text) — nothing else.)

Two consequences drive the whole design:

Also worth knowing when you reason about cost: token usage is stamped when a round terminates. A round that dies mid-flight (an infrastructure error, a cancellation) may record no usage at all, so thread-level cost figures are a floor, not an exact total.

3. The two-phase extract-then-write protocol

For any extraction-shaped task, split the work across a round boundary:

  1. Phase 1 — read. The agent reads the source(s) and ends by emitting a complete, self-sufficient worksheet as its answer text. The user reviews it and replies to continue.
  2. Phase 2 — write. A fresh round creates all nodes strictly from the worksheet.

This buys three things at once:

Corollary — the worksheet must be genuinely self-sufficient. The source is unreachable in phase 2, so anything phase 2 needs (including any master data required to create new dimension nodes) has to be in the worksheet.

4. Hard vs. soft enforcement — affordance beats instruction

The AgentConfiguration surface gives you real, hard levers — use them instead of arguing with the model in the prompt:

The design rule, learned the hard way:

When an agent repeatedly takes a forbidden action, remove or restrict the enabling tool — do not escalate the prompt wording.

In the extraction case the model ignored three successive prompt-level prohibitions of a tool-usage pattern, each stronger and closer to the action; removing the enabling plugin from the whitelist ended it instantly. Prompt text competes with tool affordances and loses. And keep the two consistent: a prompt that describes a tool surface the agent doesn't actually have (or omits one it does) invites unpredictable behaviour.

5. Writing instructions that survive rounds and failures

6. Write-phase patterns for fact/dimension models

See also the typed-content discipline in MeshPlugin → Create: content field names must match the registered type exactly, or the unknown fields are silently dropped and the node renders empty.

7. Operational notes

Measured effect

The same task shape and model class, tuned across the patterns above:

Configuration Cost per report
Naive: single-phase, per-value reads, per-node creates $14–23, frequent failures
Two-phase protocol, but document re-read in phase 2 + sequential creates ~$13.5
+ full-text read via one Get (transformers) + chunk tools removed + batched creates $1.9–2.0 per clean run (~$4 when a round was interrupted and redone)

The numbers are illustrative of one task, not a benchmark — but the shape is the point: the big wins came from cutting turns and evicting the document from the write phase (§1–§3), and the last mile from hard enforcement and typed-write discipline (§4, §6).

Reconnecting…
The server was updated. Reloading the page to pick up the latest version.