Skip to content

Commit 874f6bb

Browse files
committed
render tool output summarization to UI post summarization call (non-streaming)
1 parent e948c24 commit 874f6bb

7 files changed

Lines changed: 55 additions & 3 deletions

File tree

packages/cli/src/ui/components/messages/SubagentHistoryDisplay.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
SubagentToolCallHistoryItem,
1212
SubagentToolResponseHistoryItem,
1313
SubagentThoughtHistoryItem,
14+
SubagentToolSummaryHistoryItem,
1415
} from '../../types.js';
1516
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
1617
import { SubagentToolCallDisplay } from './SubagentToolCallDisplay.js';
@@ -25,6 +26,7 @@ type SubagentTurn = {
2526
thought?: SubagentThoughtHistoryItem;
2627
toolCall?: SubagentToolCallHistoryItem;
2728
toolResponse?: SubagentToolResponseHistoryItem;
29+
toolSummary?: SubagentToolSummaryHistoryItem;
2830
subagentHistory?: SubagentHistoryItem[];
2931
};
3032

@@ -77,9 +79,17 @@ export const SubagentHistoryDisplay: React.FC<SubagentHistoryDisplayProps> = ({
7779

7880
switch (item.type) {
7981
case 'thought':
80-
if (lastTurn.thought) {
82+
// If the current turn already contains any tool-related activity,
83+
// this new thought must start a new turn.
84+
if (
85+
lastTurn.toolCall ||
86+
lastTurn.toolResponse ||
87+
lastTurn.toolSummary
88+
) {
8189
acc.push({ thought: item });
8290
} else {
91+
// Otherwise, it's either the first thought of a turn or a
92+
// streaming update to the existing thought.
8393
lastTurn.thought = item;
8494
}
8595
break;
@@ -90,6 +100,13 @@ export const SubagentHistoryDisplay: React.FC<SubagentHistoryDisplayProps> = ({
90100
lastTurn.toolCall = item;
91101
}
92102
break;
103+
case 'tool_summary':
104+
if (lastTurn.toolSummary) {
105+
acc.push({ toolSummary: item });
106+
} else {
107+
lastTurn.toolSummary = item;
108+
}
109+
break;
93110
// TODO: Shell tool output is very glitchy.
94111
// TODO: there's a bug when multiple shell tool calls are made in succession (for tool_output_chunk), they get merged into one response.
95112
case 'tool_response':
@@ -180,6 +197,24 @@ export const SubagentHistoryDisplay: React.FC<SubagentHistoryDisplayProps> = ({
180197
/>
181198
</Box>
182199
)}
200+
{turn.toolSummary && (
201+
<Box
202+
flexDirection="column"
203+
marginBottom={1}
204+
width={availableWidth}
205+
borderStyle="single"
206+
borderColor="cyan"
207+
paddingX={1}
208+
paddingY={0}
209+
>
210+
<Text color="cyan">Summarized Tool Output:</Text>
211+
<MarkdownDisplay
212+
text={turn.toolSummary.data.summary}
213+
isPending={false}
214+
terminalWidth={availableWidth - 2} // Adjust width for padding
215+
/>
216+
</Box>
217+
)}
183218
</Box>
184219
);
185220
}

packages/cli/src/ui/hooks/useReactToolScheduler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export function useReactToolScheduler(
111111
'GEMINI_SUBAGENT_THOUGHT::': 'thought',
112112
'GEMINI_SUBAGENT_TOOL_CALL::': 'tool_call',
113113
'GEMINI_SUBAGENT_TOOL_RESPONSE::': 'tool_response',
114+
'GEMINI_SUBAGENT_TOOL_SUMMARY::': 'tool_summary',
114115
'GEMINI_SUBAGENT_TOOL_OUTPUT_CHUNK::': 'tool_output_chunk',
115116
'GEMINI_SUBAGENT_ERROR::': 'error',
116117
};

packages/cli/src/ui/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,13 @@ export type SubagentHistoryItem =
404404
data: { error: string; context?: string; name?: string };
405405
}
406406
| { type: 'interrupted'; data: { message: string } }
407-
| { type: 'user_message'; data: { message: string } };
407+
| { type: 'user_message'; data: { message: string } }
408+
| SubagentToolSummaryHistoryItem;
409+
410+
export type SubagentToolSummaryHistoryItem = {
411+
type: 'tool_summary';
412+
data: { summary: string };
413+
};
408414

409415
export type SubagentThoughtHistoryItem = Extract<
410416
SubagentHistoryItem,

packages/core/src/agents/executor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,9 @@ export class AgentExecutor<TOutput extends z.ZodTypeAny> {
13621362
goal,
13631363
);
13641364
if (summary) {
1365+
this.emitActivity('TOOL_SUMMARY', {
1366+
summary,
1367+
});
13651368
debugLogger.log(
13661369
`[AgentExecutor] Summarized output for tool: ${functionCall.name} (ID: ${callId})`,
13671370
);

packages/core/src/agents/invocation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ export class SubagentInvocation<
124124
)}`,
125125
);
126126
break;
127+
case 'TOOL_SUMMARY':
128+
updateOutput(
129+
`GEMINI_SUBAGENT_TOOL_SUMMARY::${JSON.stringify(activity.data)}`,
130+
);
131+
break;
127132
case 'ERROR':
128133
updateOutput(
129134
`GEMINI_SUBAGENT_ERROR::${JSON.stringify(activity.data)}`,

packages/core/src/agents/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export interface SubagentActivityEvent {
4949
| 'TOOL_CALL_END'
5050
| 'THOUGHT_CHUNK'
5151
| 'ERROR'
52-
| 'TOOL_OUTPUT_CHUNK';
52+
| 'TOOL_OUTPUT_CHUNK'
53+
| 'TOOL_SUMMARY';
5354
data: Record<string, unknown>;
5455
}
5556

understand.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ Using the codebase investigator: tell me how the ollama inference works.
225225

226226
- `use the build and test tool: run npm test -- src/tools/glob.test.ts`
227227
- `use the build and test tool: test src/tools/glob.test.ts`
228+
- `use the build and test tool: run npm test -- src/tools/glob.test.ts in the core workspace`
228229

229230
# TODO:
230231

0 commit comments

Comments
 (0)