mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:18:26 +00:00
fix: update totalTokens after compaction using last-call usage (#15018)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 9214291bf7
Co-authored-by: shtse8 <8020099+shtse8@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
@@ -820,11 +820,18 @@ export async function runEmbeddedPiAgent(
|
||||
}
|
||||
|
||||
const usage = toNormalizedUsage(usageAccumulator);
|
||||
// Extract the last individual API call's usage for context-window
|
||||
// utilization display. The accumulated `usage` sums input tokens
|
||||
// across all calls (tool-use loops, compaction retries), which
|
||||
// overstates the actual context size. `lastCallUsage` reflects only
|
||||
// the final call, giving an accurate snapshot of current context.
|
||||
const lastCallUsage = normalizeUsage(lastAssistant?.usage as UsageLike);
|
||||
const agentMeta: EmbeddedPiAgentMeta = {
|
||||
sessionId: sessionIdUsed,
|
||||
provider: lastAssistant?.provider ?? provider,
|
||||
model: lastAssistant?.model ?? model.id,
|
||||
usage,
|
||||
lastCallUsage: lastCallUsage ?? undefined,
|
||||
compactionCount: autoCompactionCount > 0 ? autoCompactionCount : undefined,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user