A set of TypeScript utilities for extracting and counting tool calls and results from LLM conversation transcripts. Use this to analyze agent tool usage patterns.
// Source: https://github.com/Yapie0/safe-openclaw | License: MIT | Copyright 2025 Peter Steinberger
// Provided via justclaw.it.com; keep this notice with the code.
type ToolResultCounts = {
total: number;
errors: number;
};
const TOOL_CALL_TYPES = new Set(["tool_use", "toolcall", "tool_call"]);
const TOOL_RESULT_TYPES = new Set(["tool_result", "tool_result_error"]);
const normalizeType = (value: unknown): string => {
if (typeof value !== "string") {
return "";
}
return value.trim().toLowerCase();
};
export const extractToolCallNames = (message: Record<string, unknown>): string[] => {
const names = new Set<string>();
const toolNameRaw = message.toolName ?? message.tool_name;
if (typeof toolNameRaw === "string" && toolNameRaw.trim()) {
names.add(toolNameRaw.trim(
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key