Observation
providerAsSandboxClient(provider).create() returns an instance whose prompt() folds every streamed event with mergeTokenUsage, which adds the counters (src/runtime/environment-provider.ts:1538 and :2501-2532 on origin/main 3b33fe9f).
It never reads AgentEnvironmentEvent.usageMode.
The interface defines cumulative as "the total so far for this turn" (agent-interface environment-runtime.ts:274-278), so each cumulative event restates earlier usage.
Reproduction against agent-runtime 0.219.0, with a stub provider whose stream is a cumulative step total, then result and done carrying the same cumulative receipt:
events: raw {60,6} cumulative, result {100,10} cumulative, done {100,10} cumulative
prompt().usage: { inputTokens: 260, outputTokens: 26 } // receipt is { 100, 10 }
The executor path is correct: streamProviderExecutor credits the same events through createSandboxUsageLedger, which honors usageMode and marks a falling cumulative total unknown.
Reach today
@tangle-network/agent-provider-tangle cannot reach this path yet, because providerAsSandboxClient always sends providerOptions.sandboxCreateOptions and that provider refuses non-empty create providerOptions.
It becomes reachable for Tangle as soon as that composition works.
The Tangle provider already marks both result and done cumulative, and agent-sdk#327 adds cumulative step totals for OpenCode executions (agent-sdk#324).
Ask
Fold prompt() usage by mode: replace the running total with a cumulative event's usage, add a delta event's usage, and treat usage with no declared mode as it is treated in the ledger.
Observation
providerAsSandboxClient(provider).create()returns an instance whoseprompt()folds every streamed event withmergeTokenUsage, which adds the counters (src/runtime/environment-provider.ts:1538and:2501-2532onorigin/main3b33fe9f).It never reads
AgentEnvironmentEvent.usageMode.The interface defines
cumulativeas "the total so far for this turn" (agent-interfaceenvironment-runtime.ts:274-278), so each cumulative event restates earlier usage.Reproduction against agent-runtime 0.219.0, with a stub provider whose stream is a cumulative step total, then
resultanddonecarrying the same cumulative receipt:The executor path is correct:
streamProviderExecutorcredits the same events throughcreateSandboxUsageLedger, which honorsusageModeand marks a falling cumulative total unknown.Reach today
@tangle-network/agent-provider-tanglecannot reach this path yet, becauseproviderAsSandboxClientalways sendsproviderOptions.sandboxCreateOptionsand that provider refuses non-empty createproviderOptions.It becomes reachable for Tangle as soon as that composition works.
The Tangle provider already marks both
resultanddonecumulative, and agent-sdk#327 adds cumulative step totals for OpenCode executions (agent-sdk#324).Ask
Fold
prompt()usage by mode: replace the running total with acumulativeevent's usage, add adeltaevent's usage, and treat usage with no declared mode as it is treated in the ledger.