Adapters Module
Adapters convert various LLM trace formats into a normalized format for evaluation.
Base Classes
- class toolscore.adapters.ToolCall(tool, args=None, result=None, timestamp=None, duration=None, cost=None, metadata=dict())[source]
Represents a single tool call in a trace.
- Variables:
tool (
str) – Name of the tool/function called.args (
dict[str,Any] |None) – Arguments provided to the tool.Nonecarries a specific meaning for gold/expected calls: “do not check arguments” — the tool name must match but its arguments are ignored. For actual/trace calls,Nonesimply means no arguments were recorded and is treated as an empty mapping. Adapters that parse real traces always set a concrete dict, soNonein practice only originates from gold specifications that omitargs.result (
Any) – Result returned by the tool (optional).timestamp (
float|None) – Unix timestamp of when the call was made (optional).duration (
float|None) – Duration of the call in seconds (optional).cost (
float|None) – Cost associated with this call in USD (optional).metadata (
dict[str,Any]) – Additional metadata about the call. Failures are recorded asmetadata["is_error"]and/ormetadata["error"](the message); seeis_error.
- Parameters:
- __post_init__()[source]
Validate tool call data after initialization.
argsis intentionally not coerced fromNoneto{}so that gold calls can express “do not check arguments” (args is None) distinctly from “expect exactly zero arguments” (args == {}). Consumers that need a concrete mapping usecall.args or {}.- Return type:
- property id: str | None
The call’s ID, if the trace has one (
metadata["id"], else the JSON-RPC ID).Provider traces carry a call ID (OpenAI
call_id, Anthropictool_useID); recorded MCP sessions the JSON-RPC request ID. It pairs a requested call with its result and is kept in every record.
- class toolscore.adapters.BaseAdapter[source]
Abstract base class for trace format adapters.
All trace format adapters must inherit from this class and implement the parse method to convert provider-specific formats into a normalized list of ToolCall objects.
Adapter Implementations
OpenAI Adapter
- class toolscore.adapters.OpenAIAdapter[source]
Bases:
BaseAdapterAdapter for OpenAI function call traces.
Parses OpenAI Chat Completion API conversation logs that include function/tool calls in the message history, and Responses API responses or item lists (
function_call,mcp_callandcustom_tool_callitems, with outputs paired bycall_id).In a Chat Completions history, each
role: "tool"message is attached to the call with itstool_call_idas the call’sresult(and a legacyrole: "function"message to the latest call of that name), so checks that read tool output, such as the honesty checks, see what the tool said.- parse(trace_data)[source]
Parse OpenAI trace into normalized tool calls.
Anthropic Adapter
- class toolscore.adapters.AnthropicAdapter[source]
Bases:
BaseAdapterAdapter for Anthropic Claude tool-use traces.
Parses Anthropic/Claude API conversation logs that include tool_use content blocks in assistant messages. A
tool_resultblock in a later user message is attached to the call with itstool_use_id: its text becomes the call’sresult, or, withis_error: true, itserror.- parse(trace_data)[source]
Parse Anthropic trace into normalized tool calls.
LangChain Adapter
- class toolscore.adapters.LangChainAdapter[source]
Bases:
BaseAdapterAdapter for LangChain agent traces.
Supports parsing of: - AgentAction objects (legacy format) - ToolCall objects (modern format) - Raw dictionaries with tool/action information
Example LangChain trace formats:
Legacy format (AgentAction):
[ { "tool": "search", "tool_input": {"query": "Python"}, "log": "Invoking search..." } ]
Modern format (ToolCall):
[ { "name": "search", "args": {"query": "Python"}, "id": "call_123" } ]
Supports both legacy (AgentAction) and modern (ToolCall) LangChain formats.
Gemini Adapter
- class toolscore.adapters.GeminiAdapter[source]
Bases:
BaseAdapterAdapter for Google Gemini function call traces.
Parses Google Gemini API conversation logs that include function calls in the candidate responses.
- parse(trace_data)[source]
Parse Gemini trace into normalized tool calls.
MCP Adapter
- class toolscore.adapters.MCPAdapter[source]
Bases:
BaseAdapterAdapter for Anthropic Model Context Protocol (MCP) traces.
MCP is an open standard for connecting AI assistants to data systems using JSON-RPC 2.0 messaging format.
Supports:
Tool call requests (JSON-RPC 2.0 method calls)
Tool call results (JSON-RPC 2.0 responses)
Error handling (JSON-RPC 2.0 errors)
Both single requests and batch requests
A recorded session (for example from
toolscore mcp record) holds each request followed by its response. A response whoseidmatches an earlier request in the same trace is merged into that request’s call (result, error,is_error), so one tool call stays oneToolCall. A response with no matching request is reported on its own, as before.Example MCP tool call request:
{ "jsonrpc": "2.0", "method": "tools/call", "params": { "name": "get_weather", "arguments": {"location": "San Francisco"} }, "id": 1 }
Example MCP tool call result:
{ "jsonrpc": "2.0", "id": 1, "result": { "content": [{"type": "text", "text": "Temperature: 72°F"}] } }
Reads JSON-RPC 2.0 message lists and sessions written by toolscore mcp record.
Each tools/call response is paired with its request by id, so the call keeps
its result, error and duration.
OpenTelemetry Adapter
- class toolscore.adapters.OTelAdapter[source]
Bases:
BaseAdapterAdapter for OpenTelemetry GenAI tool spans (OTLP JSON exports).
See
tool_calls_from_otel()for the accepted inputs and the mapping.
- toolscore.adapters.otel.tool_calls_from_otel(data)[source]
Extract tool calls from OpenTelemetry GenAI tool spans.
- Parameters:
data (
Any) – An OTLP JSON export, a list of span dicts, or a list of OpenTelemetry SDK span objects.- Return type:
- Returns:
One dict per tool span, in start-time order, with
tool,args,result,is_error,error,duration(seconds) andid. Arguments and results recorded as JSON strings are decoded; arguments that are not a JSON object are kept as{"value": ...}.
Custom Adapter
- class toolscore.adapters.CustomAdapter[source]
Bases:
BaseAdapterAdapter for custom/generic JSON trace formats.
Accepts a simplified trace format with a ‘calls’ array or directly as an array of tool call objects.
- parse(trace_data)[source]
Parse custom JSON trace into normalized tool calls.
- Parameters:
trace_data (
dict[str,Any] |list[Any]) – Custom trace format. Can be: - {“calls”: […]} with array of call objects - Direct array of call objects Each call object should have at minimum a ‘tool’ or ‘name’ field.- Return type:
- Returns:
List of ToolCall objects extracted from the trace.
- Raises:
ValueError – If trace format is invalid.
browser-use Adapter
- class toolscore.adapters.BrowserUseAdapter[source]
Bases:
BaseAdapterAdapter for browser-use
AgentHistoryListdumps (save_to_file/model_dump).
Coding-agent Session Adapters
- class toolscore.adapters.ClaudeCodeSessionAdapter(sidechains=False)[source]
Bases:
BaseAdapterReads a Claude Code session transcript (the parsed lines of its JSONL file).
- Parameters:
sidechains (bool)
- class toolscore.adapters.CodexSessionAdapter[source]
Bases:
BaseAdapterReads a Codex CLI rollout (the parsed lines of its JSONL file).