Accumulated cost in USD of the work run on this context, including spend restored from a checkpoint
billedCost
number
USD this context's calls actually paid during this attempt. Replayed steps and rounds add nothing and a restored context starts at 0, so cost - billedCost is what replay saved
heldCost
number
USD held for this execution's paid calls that were cut off and have no settled bill yet, each at its ceiling until reconciled. A bound, never part of cost or billedCost; nonzero only on a root context. See Paid Calls
context
TContext
Typed context object. Access layer data via ctx.context['layerId'].prop. Defaults to ContextData when no ContextConfig is provided.
state
TState
Mutable user state
parent
Context | null
Parent context (for spawned agents)
depth
number
Nesting depth (0 for root)
span
Span
Observability span
threadId
string
Thread identifier for context scoping
resourceId
string
Resource identifier for context scoping (optional)
harness
AgentHarness
Reference to the owning agent harness. Access params via ctx.harness.config.params.
fs
FsAdapter
Filesystem adapter delegated from ctx.harness.fs. Use for all filesystem operations inside steps and tools.
itemLog
ItemLog
Conversation history
lastStepMeta
StepMeta | null
Metadata from the last executed step
lastLayerUsage
LastLayerUsage | undefined
Per-context-layer breakdown of the context window from the most recent callModel. Undefined until the first LLM call completes.
Send to a channel. Parks when a queue channel is at capacity (back-pressure: channel_timeout after 30s, cancelled on abort)
tryRecv
<T>(channel) => T | null
Non-blocking receive
checkpoint
() => Promise<void>
Persist current state
complete
<T>(value) => void
Signal completion with a value
abort
(reason?) => void
Signal abort. Cascades to every live inParallel path and spawn child of this context (never to the parent); first call wins. Does not run context-layer teardown — see harness.cancel
Token usage for the step. The two cache fields are undefined when the provider reports no cache figures, which is not the same as a reported zero (optional)
cost
number
Step cost in USD (optional)
billedCost
number
USD the step's call actually paid — see LLMResponse.billedCost (optional)
Model id from the step that triggered the snapshot
layers
ReadonlyArray<LayerUsageEntry>
Per-context-layer contributions, sorted by layerId
systemPromptTokens
number
Estimated tokens from step.instructions
toolsTokens
number
Estimated tokens from the tool definitions sent to the model
historyTokens
number
Estimated tokens for itemLog items not owned by a layer
totalUsedTokens
number
Sum of all four buckets
epoch
EpochUsage | undefined
Anchoring state behind this assembly. Absent when contextCache.enabled is false
LastLayerUsage is captured by the runtime after each successful callModel and surfaced on Context.lastLayerUsage and HarnessResponse.lastLayerUsage. Use it for context-window introspection (e.g., the CLI /context command). The snapshot is overwritten on the next call; export to your observability span if you need historical retention.