Skip to content

Commit 1462a24

Browse files
authored
fix(ui): show all tool calls and results when loading session data (#1227)
When multiple tool calls are made the UI correctly reflects the calls: <img width="1677" height="1198" alt="image" src="https://github.com/user-attachments/assets/53e49634-7e6d-4952-ae9b-7c624603bc12" /> However, when the chat is refreshed only 1 of the tool calls will be displayed. <img width="1684" height="795" alt="image" src="https://github.com/user-attachments/assets/d2436ca1-2406-4a60-9453-f556d2b6824f" /> This PR fixes this issue ensuring that all tool calls are correctly displayed when loading an existing session. Signed-off-by: Brian Fox <[email protected]>
1 parent 2ad96e1 commit 1462a24

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

ui/src/components/chat/ToolCallDisplay.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,27 @@ const extractToolCallRequests = (message: Message): FunctionCall[] => {
7272

7373
// Check for stored task format first (data parts)
7474
const dataParts = message.parts?.filter(part => part.kind === "data") || [];
75+
const functionCalls: FunctionCall[] = [];
76+
7577
for (const part of dataParts) {
7678
if (part.metadata) {
7779
const partMetadata = part.metadata as ADKMetadata;
7880
if (partMetadata?.kagent_type === "function_call") {
7981
const data = part.data as unknown as FunctionCall;
80-
return [{
82+
functionCalls.push({
8183
id: data.id,
8284
name: data.name,
8385
args: data.args
84-
}];
86+
});
8587
}
8688
}
8789
}
8890

91+
// If we found function calls in data parts, return them
92+
if (functionCalls.length > 0) {
93+
return functionCalls;
94+
}
95+
8996
// Try streaming format (metadata or text content)
9097
const textParts = message.parts?.filter(part => part.kind === "text") || [];
9198
const content = textParts.map(part => (part as TextPart).text).join("");
@@ -105,6 +112,8 @@ const extractToolCallResults = (message: Message): ProcessedToolResultData[] =>
105112

106113
// Check for stored task format first (data parts)
107114
const dataParts = message.parts?.filter(part => part.kind === "data") || [];
115+
const toolResults: ProcessedToolResultData[] = [];
116+
108117
for (const part of dataParts) {
109118
if (part.metadata) {
110119
const partMetadata = part.metadata as ADKMetadata;
@@ -113,16 +122,21 @@ const extractToolCallResults = (message: Message): ProcessedToolResultData[] =>
113122
// Extract normalized content from the result (supports string/object/array)
114123
const textContent = normalizeToolResultToText(data);
115124

116-
return [{
125+
toolResults.push({
117126
call_id: data.id,
118127
name: data.name,
119128
content: textContent,
120129
is_error: data.response?.isError || false
121-
}];
130+
});
122131
}
123132
}
124133
}
125134

135+
// If we found tool results in data parts, return them
136+
if (toolResults.length > 0) {
137+
return toolResults;
138+
}
139+
126140
// Try streaming format (metadata or text content)
127141
const textParts = message.parts?.filter(part => part.kind === "text") || [];
128142
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)