Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-persistence): save usage on router-owned run records #2263

Mergedpcbeingused33(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/2263/headmerged by AlemTuzlak View on GitHub

Showing 10 changed files with 22 additions and 2 deletions (loading 7).

x
0 of 10 viewed, 10 left
6 additions and 0 deletions.changeset/persist-routed-subagent-usage.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/ai': patch
+'@tanstack/ai-persistence': patch
+---
+​
+`withPersistence` now saves `RunRecord.usage` for a run that `subagents.router` owns. The record gets what the children spent, and with `strategy: 'handoff'` main adds its own usage to it.
6 additions and 0 deletionspackages/ai/src/activities/chat/middleware/types.tsModified
View file
@@ -721,6 +721,8 @@
interruptIds?: ReadonlyArray<string>
/** Keep the parent run open because main chat() takes over from here. */
handoffToMain?: boolean
+ /** What the children of this call spent. */
+ usage?: TokenUsage
}) => Promise<void>
/** The run stopped because a child waits for outside input. */
suspend?: (input: {
@@ -729,11 +731,15 @@
interrupts: ReadonlyArray<Interrupt>
/** Commit only these interrupt ids instead of the whole run batch. */
interruptIds?: ReadonlyArray<string>
+ /** What the children of this call spent. */
+ usage?: TokenUsage
}) => Promise<void>
abort: (input: {
threadId: string
runId: string
error?: unknown