From 9b839655a73157a7dd96b1d3debc98322da0880b Mon Sep 17 00:00:00 2001 From: Siddhant Rai Date: Wed, 11 Jun 2025 19:28:15 +0530 Subject: [PATCH] refactor: improve tool call result handling and display in conversation components --- application/agents/base.py | 5 +++- .../src/conversation/ConversationBubble.tsx | 26 ++++++++++++------- .../src/conversation/ConversationMessages.tsx | 2 +- .../src/conversation/conversationSlice.ts | 9 ++++--- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/application/agents/base.py b/application/agents/base.py index adebc125..c9cc579d 100644 --- a/application/agents/base.py +++ b/application/agents/base.py @@ -197,7 +197,9 @@ class BaseAgent(ABC): else: print(f"Executing tool: {action_name} with args: {call_args}") result = tool.execute_action(action_name, **parameters) - tool_call_data["result"] = result + tool_call_data["result"] = ( + f"{str(result)[:50]}..." if len(str(result)) > 50 else result + ) yield {"type": "tool_call", "data": {**tool_call_data, "status": "completed"}} self.tool_calls.append(tool_call_data) @@ -213,6 +215,7 @@ class BaseAgent(ABC): if len(str(tool_call["result"])) > 50 else tool_call["result"] ), + "status": "completed", } for tool_call in self.tool_calls ] diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx index 920005e3..c1c1f553 100644 --- a/frontend/src/conversation/ConversationBubble.tsx +++ b/frontend/src/conversation/ConversationBubble.tsx @@ -26,7 +26,9 @@ import UserIcon from '../assets/user.svg'; import Accordion from '../components/Accordion'; import Avatar from '../components/Avatar'; import CopyButton from '../components/CopyButton'; +import MermaidRenderer from '../components/MermaidRenderer'; import Sidebar from '../components/Sidebar'; +import Spinner from '../components/Spinner'; import SpeakButton from '../components/TextToSpeechButton'; import { useDarkTheme, useOutsideAlerter } from '../hooks'; import { @@ -36,7 +38,6 @@ import { import classes from './ConversationBubble.module.css'; import { FEEDBACK, MESSAGE_TYPE } from './conversationModels'; import { ToolCallsType } from './types'; -import MermaidRenderer from '../components/MermaidRenderer'; const DisableSourceFE = import.meta.env.VITE_DISABLE_SOURCE_FE || false; @@ -741,7 +742,7 @@ function ToolCalls({ toolCalls }: { toolCalls: ToolCallsType[] }) { {isToolCallsOpen && ( -
+
{toolCalls.map((toolCall, index) => (

-

- - {JSON.stringify(toolCall.result, null, 2)} + {toolCall.status === 'pending' && ( + + -

+ )} + {toolCall.status === 'completed' && ( +

+ + {JSON.stringify(toolCall.result, null, 2)} + +

+ )}
diff --git a/frontend/src/conversation/ConversationMessages.tsx b/frontend/src/conversation/ConversationMessages.tsx index 5c2150a6..ac40bf7b 100644 --- a/frontend/src/conversation/ConversationMessages.tsx +++ b/frontend/src/conversation/ConversationMessages.tsx @@ -131,7 +131,7 @@ export default function ConversationMessages({ ? LAST_BUBBLE_MARGIN : DEFAULT_BUBBLE_MARGIN; - if (query.thought || query.response) { + if (query.thought || query.response || query.tool_calls) { const isCurrentlyStreaming = status === 'loading' && index === queries.length - 1; return ( diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts index 03532792..2e15a2ea 100644 --- a/frontend/src/conversation/conversationSlice.ts +++ b/frontend/src/conversation/conversationSlice.ts @@ -293,10 +293,11 @@ export const conversationSlice = createSlice({ ); if (existingIndex !== -1) { - Object.assign( - state.queries[index].tool_calls[existingIndex], - tool_call, - ); + const existingCall = state.queries[index].tool_calls[existingIndex]; + state.queries[index].tool_calls[existingIndex] = { + ...existingCall, + ...tool_call, + }; } else state.queries[index].tool_calls.push(tool_call); }, updateQuery(