Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(trace): show tool call arguments on hover (#14565)

Hassieb Pakzadfbf3016b2552
diff --git a/web/src/components/trace/components/IOPreview/IOPreviewPretty.tsx b/web/src/components/trace/components/IOPreview/IOPreviewPretty.tsx
index 47810123dc..2a14b5e089 100644
--- a/web/src/components/trace/components/IOPreview/IOPreviewPretty.tsx
+++ b/web/src/components/trace/components/IOPreview/IOPreviewPretty.tsx
@@ -174,6 +174,7 @@ export function IOPreviewPretty({
additionalInput,
allTools,
toolCallCounts,
+ toolCallsByName,
messageToToolCallNumbers,
toolNameToDefinitionNumber,
inputMessageCount,
@@ -255,6 +256,7 @@ export function IOPreviewPretty({
<SectionToolDefinitions
tools={allTools}
toolCallCounts={toolCallCounts}
+ toolCallsByName={toolCallsByName}
toolNameToDefinitionNumber={toolNameToDefinitionNumber}
/>
diff --git a/web/src/components/trace/components/IOPreview/components/SectionToolDefinitions.tsx b/web/src/components/trace/components/IOPreview/components/SectionToolDefinitions.tsx
index bc71455db6..4d1937f0ef 100644
--- a/web/src/components/trace/components/IOPreview/components/SectionToolDefinitions.tsx
+++ b/web/src/components/trace/components/IOPreview/components/SectionToolDefinitions.tsx
@@ -2,11 +2,13 @@ import {
ToolCallDefinitionCard,
type ToolDefinition,
} from "./ToolCallDefinitionCard";
+import type { ToolCallInvocation } from "../hooks/useChatMLParser";
// SectionToolDefinitions props
export interface SectionToolDefinitionsProps {
tools: ToolDefinition[];
toolCallCounts: Map<string, number>;
+ toolCallsByName: Map<string, ToolCallInvocation[]>;
toolNameToDefinitionNumber: Map<string, number>;
}
@@ -18,6 +20,7 @@ export interface SectionToolDefinitionsProps {
export function SectionToolDefinitions({
tools,
toolCallCounts,
+ toolCallsByName,
toolNameToDefinitionNumber,
}: SectionToolDefinitionsProps) {
if (tools.length === 0) {
@@ -33,6 +36,7 @@ export function SectionToolDefinitions({
<ToolCallDefinitionCard
tools={tools}
toolCallCounts={toolCallCounts}
+ toolCallsByName={toolCallsByName}
toolNameToDefinitionNumber={toolNameToDefinitionNumber}
className="px-2"
/>
diff --git a/web/src/components/trace/components/IOPreview/components/ToolCallDefinitionCard.tsx b/web/src/components/trace/components/IOPreview/components/ToolCallDefinitionCard.tsx
index 9193ff0eb8..7deb8d51e5 100644
--- a/web/src/components/trace/components/IOPreview/components/ToolCallDefinitionCard.tsx
+++ b/web/src/components/trace/components/IOPreview/components/ToolCallDefinitionCard.tsx
@@ -5,6 +5,12 @@ import { PrettyJsonView } from "@/src/components/ui/PrettyJsonView";
import { Tabs, TabsList, TabsTrigger } from "@/src/components/ui/tabs";
import useLocalStorage from "@/src/components/useLocalStorage";
import { useState } from "react";
+import {
+ HoverCard,
+ HoverCardContent,
+ HoverCardTrigger,
+} from "@/src/components/ui/hover-card";
+import type { ToolCallInvocation } from "../hooks/useChatMLParser";
// Tool definition extracted from messages
export interface ToolDefinition {
@@ -17,10 +23,127 @@ export interface ToolDefinition {
export interface ToolCallDefinitionCardProps {
tools: ToolDefinition[];
toolCallCounts: Map<string, number>;
+ toolCallsByName?: Map<string, ToolCallInvocation[]>;
toolNameToDefinitionNumber?: Map<string, number>;
className?: string;
}
+function parseToolCallArguments(argumentsValue: unknown): unknown {
+ if (typeof argumentsValue !== "string") {
+ return argumentsValue;
+ }
+
+ try {
+ return JSON.parse(argumentsValue);
+ } catch {
+ return argumentsValue;
+ }
+}
+
+function hasToolCallArguments(argumentsValue: unknown): boolean {
+ return (
+ argumentsValue !== undefined &&
+ argumentsValue !== null &&
+ !(typeof argumentsValue === "string" && argumentsValue.trim() === "")
+ );
+}
+
+function ToolCallArgumentsList({
+ toolCalls,
+ className,
+}: {
+ toolCalls: ToolCallInvocation[];
+ className?: string;
+}) {
+ return (
+ <div className={cn("flex flex-col gap-3", className)}>
+ {toolCalls.map((toolCall) => {
+ const hasArguments = hasToolCallArguments(toolCall.arguments);
+
+ return (
+ <div
+ key={`${toolCall.name}-${toolCall.invocationNumber}-${toolCall.id ?? ""}`}
+ className="min-w-0"
+ >
+ <div className="mb-1.5 flex min-w-0 items-center justify-between gap-2">
+ <div className="text-foreground font-mono text-xs font-medium">
+ Call {toolCall.invocationNumber}
+ </div>
+ {toolCall.id && (
+ <div className="text-muted-foreground truncate font-mono text-xs">
+ {toolCall.id}
+ </div>
+ )}
+ </div>
+ {hasArguments ? (
+ <PrettyJsonView
+ json={parseToolCallArguments(toolCall.arguments)}
+ currentView="pretty"
+ codeClassName="text-xs"
+ />
+ ) : (
+ <div className="text-muted-foreground rounded-sm border px-2 py-1.5 text-xs">
+ No arguments
+ </div>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ );
+}
+
+function ToolCallStatusBadge({
+ isCalled,
+ statusText,
+ toolCalls,
+}: {
+ isCalled: boolean;
+ statusText: string;
+ toolCalls: ToolCallInvocation[];
+}) {
+ const badge = (
+ <Badge
+ variant={isCalled ? undefined : "secondary"}
+ className={cn(
+ "text-xs font-medium",
+ isCalled &&
+ "bg-light-green text-dark-green hover:bg-light-green border-transparent select-none",
+ )}
+ >
+ {statusText}
+ </Badge>
+ );
+
+ if (!isCalled || toolCalls.length === 0) {
+ return badge;
+ }
+
+ return (
+ <HoverCard openDelay={200} closeDelay={100}>
+ <HoverCardTrigger asChild>
+ <div className="inline-flex">{badge}</div>
+ </HoverCardTrigger>
+ <HoverCardContent
+ side="bottom"
+ align="end"
+ sideOffset={6}
+ className="max-h-96 w-96 max-w-[calc(100vw-2rem)] overflow-auto p-0"
+ >
+ <div className="border-border border-b px-3 py-2">
+ <div className="text-foreground text-xs font-semibold">
+ Tool call arguments
+ </div>
+ <div className="text-muted-foreground text-xs">
+ {toolCalls.length === 1 ? "1 call" : `${toolCalls.length} calls`}
+ </div>
+ </div>
+ <ToolCallArgumentsList toolCalls={toolCalls} className="p-3" />
+ </HoverCardContent>
+ </HoverCard>
+ );
+}
+
/**
* ToolCallDefinitionCard renders expandable cards for tool definitions.
*
@@ -33,6 +156,7 @@ export interface ToolCallDefinitionCardProps {
export function ToolCallDefinitionCard({
tools,
toolCallCounts,
+ toolCallsByName,
toolNameToDefinitionNumber,
className,
}: ToolCallDefinitionCardProps) {
@@ -52,6 +176,7 @@ export function ToolCallDefinitionCard({
const isExpanded = expandedIndex === index;
const callCount = toolCallCounts.get(tool.name) || 0;
const isCalled = callCount > 0;
+ const toolCalls = toolCallsByName?.get(tool.name) ?? [];
const toolDefinitionNumber = toolNameToDefinitionNumber?.get(tool.name);
const statusText =
callCount === 0
@@ -85,16 +210,11 @@ export function ToolCallDefinitionCard({
{/* Right: Status badge + chevron indicator */}
<div className="flex items-center gap-1.5">
- <Badge
- variant={isCalled ? undefined : "secondary"}
- className={cn(
- "text-xs font-medium",
- isCalled &&
- "bg-light-green text-dark-green hover:bg-light-green border-transparent select-none",
- )}
- >
- {statusText}
- </Badge>
+ <ToolCallStatusBadge
+ isCalled={isCalled}
+ statusText={statusText}
+ toolCalls={toolCalls}
+ />
{/* Chevron indicator */}
{isExpanded ? (
@@ -160,12 +280,24 @@ export function ToolCallDefinitionCard({
</div>
)}
- {/* Show message if no additional details */}
- {!tool.description && !tool.parameters && (
- <div className="text-muted-foreground text-sm">
- No additional details available
+ {/* Tool call arguments */}
+ {toolCalls.length > 0 && (
+ <div>
+ <div className="text-muted-foreground mb-1.5 text-xs font-medium">
+ Tool call arguments
+ </div>
+ <ToolCallArgumentsList toolCalls={toolCalls} />
</div>
)}
+
+ {/* Show message if no additional details */}
+ {!tool.description &&
+ !tool.parameters &&
+ toolCalls.length === 0 && (
+ <div className="text-muted-foreground text-sm">
+ No additional details available
+ </div>
+ )}
</div>
)}
diff --git a/web/src/components/trace/components/IOPreview/hooks/useChatMLParser.clienttest.ts b/web/src/components/trace/components/IOPreview/hooks/useChatMLParser.clienttest.ts
new file mode 100644
index 0000000000..058c85679f
--- /dev/null
+++ b/web/src/components/trace/components/IOPreview/hooks/useChatMLParser.clienttest.ts
@@ -0,0 +1,161 @@
+import { renderHook } from "@testing-library/react";
+import { useChatMLParser } from "./useChatMLParser";
+
+describe("useChatMLParser", () => {
+ it("groups output-side tool call arguments by tool name", () => {
+ const input = {
+ messages: [
+ {
+ role: "system",
+ content: "Use tools when needed.",
+ tools: [
+ {
+ name: "grep",
+ description: "Search files",
+ parameters: { type: "object" },
+ },
+ {
+ name: "write_file",
+ description: "Write a file",
+ parameters: { type: "object" },
+ },
+ ],
+ },
+ {
+ role: "assistant",
+ tool_calls: [
+ {
+ id: "historical-call",
+ name: "grep",
+ arguments: '{"query":"old"}',
+ },
+ ],
+ },
+ ],
+ };
+
+ const output = [
+ {
+ role: "assistant",
+ tool_calls: [
+ {
+ id: "call-grep-1",
+ name: "grep",
+ arguments: '{"query":"first"}',
+ },
+ {
+ id: "call-write-1",
+ name: "write_file",
+ arguments: '{"path":"todos.md"}',
+ },
+ {
+ id: "call-grep-2",
+ name: "grep",
+ arguments: '{"query":"second"}',
+ },
+ ],
+ },
+ ];
+
+ const { result } = renderHook(() =>
+ useChatMLParser(
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ input,
+ output,
+ ),
+ );
+
+ expect(result.current.toolCallCounts.get("grep")).toBe(2);
+ expect(result.current.toolCallCounts.get("write_file")).toBe(1);
+
+ expect(result.current.toolCallsByName.get("grep")).toEqual([
+ {
+ id: "call-grep-1",
+ name: "grep",
+ arguments: '{"query":"first"}',
+ invocationNumber: 1,
+ },
+ {
+ id: "call-grep-2",
+ name: "grep",
+ arguments: '{"query":"second"}',
+ invocationNumber: 3,
+ },
+ ]);
+ expect(result.current.toolCallsByName.get("write_file")).toEqual([
+ {
+ id: "call-write-1",
+ name: "write_file",
+ arguments: '{"path":"todos.md"}',
+ invocationNumber: 2,
+ },
+ ]);
+ });
+
+ it("extracts args and input from raw passthrough tool calls", () => {
+ const input = {
+ messages: [
+ {
+ role: "system",
+ content: "Use tools when needed.",
+ tools: [
+ {
+ name: "search",
+ parameters: { type: "object" },
+ },
+ {
+ name: "lookup",
+ parameters: { type: "object" },
+ },
+ ],
+ },
+ ],
+ };
+
+ const output = {
+ tool_calls: [
+ {
+ id: "call-search",
+ toolName: "search",
+ input: { query: "docs" },
+ },
+ {
+ id: "call-lookup",
+ toolName: "lookup",
+ args: { id: "trace-1" },
+ },
+ ],
+ };
+
+ const { result } = renderHook(() =>
+ useChatMLParser(
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ input,
+ output,
+ ),
+ );
+
+ expect(result.current.toolCallsByName.get("search")).toEqual([
+ {
+ id: "call-search",
+ name: "search",
+ arguments: { query: "docs" },
+ invocationNumber: 1,
+ },
+ ]);
+ expect(result.current.toolCallsByName.get("lookup")).toEqual([
+ {
+ id: "call-lookup",
+ name: "lookup",
+ arguments: { id: "trace-1" },
+ invocationNumber: 2,
+ },
+ ]);
+ });
+});
diff --git a/web/src/components/trace/components/IOPreview/hooks/useChatMLParser.ts b/web/src/components/trace/components/IOPreview/hooks/useChatMLParser.ts
index 21b01e90ae..e460a448c4 100644
--- a/web/src/components/trace/components/IOPreview/hooks/useChatMLParser.ts
+++ b/web/src/components/trace/components/IOPreview/hooks/useChatMLParser.ts
@@ -20,6 +20,13 @@ export interface ToolDefinition {
parameters?: Record<string, unknown>;
}
+export interface ToolCallInvocation {
+ id?: string;
+ name: string;
+ arguments?: unknown;
+ invocationNumber: number;
+}
+
// Result from ChatML parsing hook
export interface ChatMLParserResult {
canDisplayAsChat: boolean;
@@ -27,6 +34,7 @@ export interface ChatMLParserResult {
additionalInput: Record<string, unknown> | undefined;
allTools: ToolDefinition[];
toolCallCounts: Map<string, number>;
+ toolCallsByName: Map<string, ToolCallInvocation[]>;
messageToToolCallNumbers: Map<number, number[]>;
toolNameToDefinitionNumber: Map<string, number>;
inputMessageCount: number;
@@ -46,6 +54,34 @@ function parseToolCallsFromMessage(
: [];
}
+function getToolCallStringField(
+ toolCall: unknown,
+ field: string,
+): string | undefined {
+ if (!toolCall || typeof toolCall !== "object") return undefined;
+
+ const value = (toolCall as Record<string, unknown>)[field];
+
+ return typeof value === "string" ? value : undefined;
+}
+
+function getToolCallName(toolCall: unknown): string | undefined {
+ return (
+ getToolCallStringField(toolCall, "name") ??
+ getToolCallStringField(toolCall, "toolName")
+ );
+}
+
+function getToolCallArguments(toolCall: unknown): unknown {
+ if (!toolCall || typeof toolCall !== "object") return undefined;
+
+ const toolCallRecord = toolCall as Record<string, unknown>;
+
+ return (
+ toolCallRecord.arguments ?? toolCallRecord.args ?? toolCallRecord.input
+ );
+}
+
/**
* Hook to parse input/output into ChatML format and extract tool information.
*
@@ -120,6 +156,7 @@ export function useChatMLParser(
let toolCallCounter = 0;
const messageToToolCallNumbers = new Map<number, number[]>();
const toolCallCounts = new Map<string, number>();
+ const toolCallsByName = new Map<string, ToolCallInvocation[]>();
for (let i = 0; i < messages.length; i++) {
const message = messages[i];
@@ -131,13 +168,7 @@ export function useChatMLParser(
const messageToolNumbers: number[] = [];
for (const toolCall of toolCallList) {
- const calledToolName =
- toolCall.name && typeof toolCall.name === "string"
- ? toolCall.name
- : // AI SDK has 'toolName'
- toolCall.toolName && typeof toolCall.toolName === "string"
- ? toolCall.toolName
- : undefined;
+ const calledToolName = getToolCallName(toolCall);
if (calledToolName) {
// Count tool calls from OUTPUT messages only
@@ -148,6 +179,16 @@ export function useChatMLParser(
);
toolCallCounter++;
messageToolNumbers.push(toolCallCounter);
+
+ const toolCallsForName =
+ toolCallsByName.get(calledToolName) ?? [];
+ toolCallsForName.push({
+ id: getToolCallStringField(toolCall, "id"),
+ name: calledToolName,
+ arguments: getToolCallArguments(toolCall),
+ invocationNumber: toolCallCounter,
+ });
+ toolCallsByName.set(calledToolName, toolCallsForName);
}
}
}
@@ -180,6 +221,7 @@ export function useChatMLParser(
additionalInput: extractAdditionalInput(parsedInput),
allTools: sortedTools,
toolCallCounts,
+ toolCallsByName,
messageToToolCallNumbers,
toolNameToDefinitionNumber,
inputMessageCount,