Skip to content

Commit 911410f

Browse files
committed
Fix tool name extraction from ToolUseBlock messages
- Extract tool name, parameters, and ID directly from ToolUseBlock attributes instead of parsing from string - Extract tool_use_id from ToolResultBlock to link results to tool calls - Keeps fallback to regex-based extraction for edge cases - Fixes issue where many tool calls showed as 'unknown' in dashboard
1 parent 5a7b984 commit 911410f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

scripts/agent_tracer.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,29 @@ async def capture_agent_stream(
278278
"content": content if content else str(message),
279279
}
280280

281-
# Extract tool info if applicable
282-
tool_info = self.extract_tool_info(
283-
content if content else str(message), event_type
284-
)
285-
if tool_info:
286-
event.update(tool_info)
281+
# Extract tool info for ToolUseBlock messages
282+
if msg_class == "ToolUseBlock":
283+
# Extract directly from message attributes
284+
tool_name = getattr(message, "name", None)
285+
tool_input = getattr(message, "input", {})
286+
tool_id = getattr(message, "id", None)
287+
if tool_name:
288+
event["tool"] = tool_name
289+
event["parameters"] = tool_input
290+
if tool_id:
291+
event["tool_use_id"] = tool_id
292+
elif msg_class == "ToolResultBlock":
293+
# Extract tool_use_id to link result to tool call
294+
tool_use_id = getattr(message, "tool_use_id", None)
295+
if tool_use_id:
296+
event["tool_use_id"] = tool_use_id
297+
elif event_type == "TOOL_CALL":
298+
# Fallback: try to extract from content string
299+
tool_info = self.extract_tool_info(
300+
content if content else str(message), event_type
301+
)
302+
if tool_info:
303+
event.update(tool_info)
287304

288305
self.trace["events"].append(event)
289306

0 commit comments

Comments
 (0)