The log is the ledger.
August 16, 2026
Ask a platform team how they track agent cost and you usually get the same answer: a wrapper around the provider SDK that emits a metric. It works until someone adds a second call path, a subagent, or a retry loop that does not go through the wrapper. Then the numbers quietly stop adding up and nobody notices for a quarter. DeepSeek's open-source harness takes the opposite approach, and it is worth understanding why.
The session is the primary artefact
In deepseek-harness, a session is an append-only log of typed events, and the documentation calls it the single source of truth for an agent's whole interaction history. Message history is not stored separately — it is derived from the log by projection. There is one record, and reading it cannot disagree with what the model actually saw.
The governing principle is stated as "model-visible means logged": anything the model could see must appear in the log, because the log has to be able to reconstitute the run. That constraint exists for replay and debugging, but it has a useful side effect. A log complete enough to replay a session is complete enough to cost it.
The events that matter to finance
| Event | What it tells you |
|---|---|
| Turn start / end | The user-facing unit of work, and why it ended |
| Step start / end | One model call plus its tools - the billing unit |
| Assistant output | The response, carrying the step's token usage |
| Tool call / result | What the agent invoked and what came back |
| Request context | Provider, model, and context window for the step |
| Request header | Config, system prompt, and tool set as sent |
Those last two are the ones homegrown telemetry almost always omits, and they are the ones that let you price a step from the record alone rather than from an assumption about which model was serving.
Steps per turn is the number to watch
A turn contains zero or more steps, and a step is one model request plus the tool calls it produces. The naive cost model in most business cases assumes something close to one model call per user request. Real agents run several, sometimes many, and the ratio is what separates a forecast from the invoice.
Because turn and step boundaries are explicit events, that ratio is directly measurable rather than inferred. So is the distribution of turn-end reasons: turns that ended for reasons other than completion are work you paid for that produced nothing, and they are usually the cheapest thing to fix.
Four questions this record answers
- What did a completed task actually cost? Sum step usage within the turn, priced by the model each step actually used.
- How much of the bill is orchestration? Steps per turn, tracked over time. Rising means the agent is working harder for the same output.
- How much is waste? The share of turns ending without completion, and the tool calls inside them.
- Where is the tool fan-out? Tool calls per step, including internally dispatched sub-calls, which are recorded separately rather than hidden inside a parent call.
The takeaway for a finance function
You do not need to adopt this harness to use the lesson. The requirement to put to your platform team is architectural, not vendor-specific: agent cost data should be a byproduct of how the system records its own work, not a parallel instrumentation effort that depends on nobody forgetting. Ask whether your current setup could reconstruct last Tuesday's expensive session from its own logs. If the answer is no, the cost numbers you are being shown are an estimate wearing a dashboard.
Related
- OpenTelemetry GenAI cost tracking
- Reasoning token cost allocation
- Your agent harness decides how much lock-in you buy
- Budget enforcement that sits inside the agent loop
FAQ
Why is agent cost attribution usually incomplete?
Because it is retrofitted. Teams wrap the provider SDK and emit metrics from that wrapper, then later add a second call path, a subagent, or a retry loop that bypasses it. The record is complete only as long as instrumentation discipline holds.
How does DeepSeek Harness record agent activity?
Every session is an append-only log of typed events, described as the single source of truth for the agent's whole interaction history. Turn boundaries, step boundaries, messages, tool calls, and tool results are all events, and message history is derived from the log rather than stored separately.
Where does token usage appear in that log?
Usage travels with model output. Per-step usage records ride alongside the assistant output that incurred them, with the assistant message usage field as a fallback, so accounting cannot become detached from the step it describes.
What is the unit of AI cost inside an agent?
The step, meaning one model call plus its tool calls. A turn contains zero or more steps. Steps per turn is the orchestration multiplier, and it is the number that most often explains why an agent bill exceeds the naive per-request estimate.