add usage info to branch summary, compaction and tool result entries (#6671)

* add usage info to branch summary entries

* add usage to compaction entries

* allow custom tools to report llm usage in tool results

* allow observing and patching usage in tool_result hooks

* agent-harness: save usage in entries

for compaction, branch summaries and tool results
This commit is contained in:
David Brailovsky
2026-07-20 16:41:43 +02:00
committed by GitHub
parent c179395218
commit 2fd3868401
29 changed files with 844 additions and 122 deletions
@@ -883,6 +883,10 @@ export class ExtensionRunner {
currentEvent.isError = handlerResult.isError;
modified = true;
}
if (handlerResult.usage !== undefined) {
currentEvent.usage = handlerResult.usage;
modified = true;
}
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const stack = err instanceof Error ? err.stack : undefined;
@@ -904,6 +908,7 @@ export class ExtensionRunner {
content: currentEvent.content,
details: currentEvent.details,
isError: currentEvent.isError,
usage: currentEvent.usage,
};
}
@@ -30,6 +30,7 @@ import type {
SimpleStreamOptions,
TextContent,
ToolResultMessage,
Usage,
} from "@earendil-works/pi-ai";
import type {
AutocompleteItem,
@@ -905,6 +906,8 @@ interface ToolResultEventBase {
input: Record<string, unknown>;
content: (TextContent | ImageContent)[];
isError: boolean;
/** Usage from the tool execution itself, if available. */
usage?: Usage;
}
export interface BashToolResultEvent extends ToolResultEventBase {
@@ -1072,6 +1075,7 @@ export interface ToolResultEventResult {
content?: (TextContent | ImageContent)[];
details?: unknown;
isError?: boolean;
usage?: Usage;
}
export interface MessageEndEventResult {
@@ -1104,6 +1108,7 @@ export interface SessionBeforeTreeResult {
summary?: {
summary: string;
details?: unknown;
usage?: Usage;
};
/** Override custom instructions for summarization */
customInstructions?: string;