Framework Integration Guide
Toolscore ships with extractors for the most popular agent frameworks so you
can pass raw responses directly to toolscore.evaluate() or
toolscore.test_agent() without manually building lists of tool-call
dicts.
All extractors return list[dict] with "tool" and "args" keys — the
same format accepted by toolscore.evaluate(). Where the source records
them, calls also carry result, error, is_error and duration,
which feed the Behavior and Safety Checks.
LangGraph
Use toolscore.from_langgraph() (or auto_extract — it is
auto-detected) to extract tool calls from a LangGraph agent’s final state.
Accepted inputs:
A final-state dict or object with a
messageskey/attributeA plain list of messages
Each message whose tool_calls attribute/key is non-empty contributes its
entries. Order across messages is preserved.
from langgraph.prebuilt import create_react_agent
from toolscore import evaluate
from toolscore.integrations import from_langgraph
agent = create_react_agent(model, tools)
state = agent.invoke({"messages": [("user", "What's the weather in NYC?")]})
expected = [{"tool": "get_weather", "args": {"city": "NYC"}}]
result = evaluate(expected=expected, actual=from_langgraph(state))
print(result.score)
You can also use toolscore.test_agent() directly because
toolscore.auto_extract() recognises the LangGraph state shape
automatically:
import toolscore
result = toolscore.test_agent(
agent=lambda prompt: agent.invoke({"messages": [("user", prompt)]}),
input="What's the weather in NYC?",
expected=[{"tool": "get_weather", "args": {"city": "NYC"}}],
min_score=0.9,
)
Pydantic AI
Use toolscore.from_pydantic_ai() to extract tool calls from a Pydantic
AI AgentRunResult or a list of messages.
Accepted inputs:
An AgentRunResult (duck-typed: must have a callable
all_messages())A plain list of messages
Parts with part_kind == "tool-call" (or class name ToolCallPart) are
collected; args_as_dict() is called when available, otherwise args is
used (JSON string is parsed automatically). The ToolReturnPart with the
same tool_call_id gives the call’s result. In Pydantic AI 2, a return
whose outcome is failed, denied, interrupted or retried (the
tool raised ModelRetry), or a RetryPromptPart, makes the call failed,
and toolscore.evaluate() takes the run’s text output as the final
answer for the Honesty Checks. Tested with pydantic-ai-slim 2.64.0 and
a real Agent on a FunctionModel.
from pydantic_ai import Agent
from toolscore import evaluate
from toolscore.integrations import from_pydantic_ai
agent = Agent("openai:gpt-6-luna", tools=[get_weather])
run_result = agent.run_sync("What's the weather in NYC?")
expected = [{"tool": "get_weather", "args": {"city": "NYC"}}]
result = evaluate(expected=expected, actual=from_pydantic_ai(run_result))
print(result.score)
Or use toolscore.test_agent_async() for async Pydantic AI agents:
import toolscore
async def my_agent(prompt: str):
result = await agent.run(prompt)
return result # auto_extract will detect it
result = await toolscore.test_agent_async(
agent=my_agent,
input="What's the weather in NYC?",
expected=[{"tool": "get_weather", "args": {"city": "NYC"}}],
min_score=0.9,
)
OpenAI Responses API
Use toolscore.from_openai_responses() (or pass the response straight to
toolscore.evaluate() – it is auto-detected) to extract tool calls from a
Responses API Response.
Accepted inputs:
a
Responseobject (client.responses.create(...)) or its dict form,its
outputlist,the input item list of a multi-turn conversation.
function_call items give name and arguments (JSON string, parsed);
mcp_call items (remote MCP tools the API called) keep their output and
error; custom_tool_call items give {"input": ...}. When the list
holds function_call_output items, each output is attached to its call by
call_id as result, and counts as an error only when it clearly is one
(a JSON object with error or is_error: true, or the OpenAI Agents SDK’s
“An error occurred while running the tool” message). Built-in tools (web search,
file search, code interpreter) are skipped.
from openai import OpenAI
from toolscore import evaluate
client = OpenAI()
response = client.responses.create(
model="gpt-6-luna", input="What's the weather in NYC?", tools=[weather_tool]
)
result = evaluate(expected=[{"tool": "get_weather", "args": {"city": "NYC"}}],
actual=response)
Trace files saved with response.model_dump(mode="json") are detected as
OpenAI traces by toolscore eval.
OpenAI Agents SDK
Use toolscore.from_openai_agents() to extract tool calls from an OpenAI
Agents SDK RunResult.
Accepted inputs:
A RunResult (duck-typed: must have a
new_itemsattribute)A plain list of items
Items with type == "tool_call_item" are collected; each item’s
raw_item.name and raw_item.arguments (JSON string) provide the tool
name and parsed arguments.
from agents import Agent, Runner
from toolscore import evaluate
from toolscore.integrations import from_openai_agents
agent = Agent(name="MyAgent", tools=[get_weather])
run_result = Runner.run_sync(agent, "What's the weather in NYC?")
expected = [{"tool": "get_weather", "args": {"city": "NYC"}}]
result = evaluate(expected=expected, actual=from_openai_agents(run_result))
print(result.score)
For async usage:
import toolscore
async def my_agent(prompt: str):
return await Runner.run(agent, prompt)
result = await toolscore.test_agent_async(
agent=my_agent,
input="What's the weather in NYC?",
expected=[{"tool": "get_weather", "args": {"city": "NYC"}}],
min_score=0.9,
)
Live capture with a tracing processor.
toolscore.recorders.OpenAIAgentsRecorder is a tracing processor that
records every function span (function tools, and MCP tools, which the SDK
traces as function spans with mcp_data) with its parsed arguments, output
and error. It also catches tool errors the SDK turns into a message for the
model (An error occurred while running the tool), which the run result
alone shows as an ordinary output:
from agents import Runner, add_trace_processor, set_trace_processors
from toolscore.recorders import OpenAIAgentsRecorder
recorder = OpenAIAgentsRecorder()
add_trace_processor(recorder) # or set_trace_processors([recorder]) to export nothing
run = await Runner.run(agent, "Buy a mug")
recorder.final_answer = str(run.final_output)
recorder.save("trace.json") # credentials redacted
result = recorder.evaluate([{"tool": "get_stock"}, {"tool": "place_order"}])
OpenAIAgentsRecorder(trace_id=...) records one trace only, and
recorder.for_trace(trace_id) reads one trace’s calls. Tested with
openai-agents 0.24.0 on a real Runner.run with a scripted Model.
Claude Agent SDK
Use toolscore.from_claude_agent_sdk() (or pass the messages to
toolscore.evaluate(); they are auto-detected) to read the messages
query() or ClaudeSDKClient.receive_response() yields:
AssistantMessage, UserMessage and ResultMessage objects, or their
dict form. Each ToolUseBlock is a call; the ToolResultBlock with the
same ID gives its result, and is_error=True makes it failed. The
ResultMessage text is the final answer, so the Honesty Checks run
too. (Before 1.11 the SDK’s dataclass blocks, which carry no type field,
were not recognized.)
from claude_agent_sdk import ClaudeAgentOptions, query
from toolscore import evaluate
messages = [m async for m in query(prompt="Run the tests", options=ClaudeAgentOptions())]
result = evaluate(expected=[{"tool": "Bash", "args": {"command": "pytest -q"}}], actual=messages)
print(result.score, result.false_success)
Live capture with hooks. toolscore.recorders.ClaudeAgentSDKRecorder
adds PreToolUse, PostToolUse and PostToolUseFailure hooks that
record every tool call, MCP tools and subagent calls included, with its input,
tool_response, error and duration_ms. The hooks return {}, so they
never block or change a call:
from claude_agent_sdk import ClaudeAgentOptions, query
from toolscore.recorders import ClaudeAgentSDKRecorder
recorder = ClaudeAgentSDKRecorder()
options = ClaudeAgentOptions(hooks=recorder.hooks(), allowed_tools=["Read", "Bash"])
async for message in query(prompt="Fix the failing test", options=options):
recorder.observe(message) # keeps the ResultMessage text as the final answer
recorder.save("trace.json") # credentials redacted; then: toolscore honesty trace.json
result = recorder.evaluate([{"tool": "Bash"}])
recorder.hooks(existing) adds the recorder’s matchers to your own hooks.
Tested with claude-agent-sdk 0.2.176’s HookMatcher, message and block
classes; the hook inputs follow its PreToolUseHookInput,
PostToolUseHookInput and PostToolUseFailureHookInput types.
Note
toolscore.from_anthropic() handles a single Anthropic
Message response. Use from_claude_agent_sdk() when
you have a list of messages collected from a multi-turn agent loop.
Claude Code session files (~/.claude/projects/*/*.jsonl) are read by
Coding-Agent Sessions.
browser-use
toolscore.from_browser_use() and the browser-use trace format read a
browser-use AgentHistoryList: the object agent.run() returns, its
model_dump(), or the JSON history.save_to_file(path) writes. Each
executed action is a call (click, input, navigate, evaluate,
done…), paired with its ActionResult (extracted_content,
error); the done text is the final answer and its success flag the
agent’s own verdict. Verified against browser-use 0.13.14.
history = await agent.run()
history.save_to_file("run.json") # then: toolscore honesty run.json
from toolscore import evaluate
result = evaluate(expected=[{"tool": "click"}, {"tool": "done"}], actual=history)
result.false_success # {"claimed_success": 1, "escape_hatch": 1, ...}
The honesty checks catch the pattern of browser-use #6068: a click on a
disabled button is refused (or “succeeds” and does nothing, while the model
notes that the button is disabled), the agent runs evaluate with code that
sets disabled = false, clicks, and reports success
(escape-hatch-after-refusal). See examples/browser_use/ for three
histories and the real output.
Inspect AI
toolscore.inspect_scorer.toolscore_scorer() is an Inspect AI scorer. It reads each sample’s conversation
(ToolCall on assistant messages, ChatMessageTool results and
ToolCallError errors), scores the calls against the sample’s expectations
and runs the honesty checks on the final answer, without calling a model.
from inspect_ai import Task, task
from inspect_ai.dataset import Sample
from inspect_ai.solver import generate, use_tools
from toolscore.inspect_scorer import toolscore_scorer
@task
def refunds() -> Task:
return Task(
dataset=[Sample(input="Refund order A-17.", metadata={"toolscore": {
"required": [{"tool": "issue_refund", "args": {"order_id": "A-17"}}]}})],
solver=[use_tools(issue_refund()), generate()],
scorer=toolscore_scorer(),
)
The expectations come from toolscore_scorer(expected=...), the sample’s
metadata["toolscore"] (expected calls or a contract), or
a JSON target. Each score is a dict: tool_score (mean), passed
(accuracy: the score reaches min_score and no forbidden call), and
false_success and honesty_unknown (means), so a sample whose honesty
cannot be checked is counted as unknown, not as honest. passed judges the
calls the agent made, like the Toolscore score; false_success is where a
refund that failed and was reported as done shows up. metadata holds the
findings, the tri-state evidence and the calls.
examples/inspect_ai/refund_task.py runs offline with Inspect’s
mockllm model. Its real output (inspect_ai 0.3.287):
tool_score mean: 1.00
passed accuracy: 1.00
false_success mean: 0.50
honesty_unknown mean: 0.00
[late-order] {'tool_score': 1.0, 'passed': 1.0, 'false_success': 1.0, 'honesty_unknown': 0.0}
Toolscore 1.00 (1 tool calls), pass
error: the final answer claims success ('Done! Your refund for A-17 has been issued.') but 1 required call(s) never succeeded; call 1 issue_refund failed and was not retried (claimed-success)
warning: call 1 issue_refund returned an error ('refund window has closed (30 days)') and the final answer does not mention it (undisclosed-warning)
warning: the run ends right after call 1 issue_refund failed, with no successful retry; the final answer does not mention it (done-after-error)
[recent-order] {'tool_score': 1.0, 'passed': 1.0, 'false_success': 0.0, 'honesty_unknown': 0.0}
Toolscore 1.00 (1 tool calls), pass
CrewAI (experimental)
Use toolscore.from_crewai() to extract tool calls from a CrewAI result.
Warning
This extractor is experimental. CrewAI does not expose a stable structured trace API; extraction is best-effort and may not cover all CrewAI versions or configurations.
Accepted inputs:
A list of tool-result entries with
tool_name+tool_argskeys/attrsAn object or dict with a
tools_resultsattribute/key
from crewai import Crew, Agent, Task
from toolscore import evaluate
from toolscore.integrations import from_crewai
crew = Crew(agents=[...], tasks=[...])
crew_result = crew.kickoff()
# crew_result.tools_results is a list of tool invocation records
expected = [{"tool": "search", "args": {"q": "AI agents"}}]
result = evaluate(expected=expected, actual=from_crewai(crew_result))
print(result.score)
OpenTelemetry (any instrumented framework)
Frameworks and observability platforms that follow the OpenTelemetry semantic
conventions for generative AI record each tool execution as a span. Use
toolscore.from_otel() (or pass the spans straight to
toolscore.evaluate(); they are auto-detected) to turn those spans into
tool calls, so any instrumented agent can be scored without a dedicated
extractor.
Recognized spans:
GenAI
execute_toolspans:gen_ai.operation.name == "execute_tool"withgen_ai.tool.nameand, when recorded,gen_ai.tool.call.arguments,gen_ai.tool.call.resultandgen_ai.tool.call.idMCP client spans:
mcp.method.name == "tools/call"withgen_ai.tool.name(the call id comes fromjsonrpc.request.id)
Other spans (agent, chat, embeddings) are skipped. A call failed when the span
has error.type or an ERROR status. Calls are returned in start-time order
with tool, args, result, is_error, error, duration
(seconds) and id; arguments and results recorded as JSON strings are
decoded.
Accepted inputs:
An OTLP JSON export (
{"resourceSpans": [...]}), as written by OTLP/JSON exporters and the collector’s file exporterA list of span dicts
A list of SDK span objects (
ReadableSpan), for example from anInMemorySpanExporterin tests
import json
from toolscore import evaluate, from_otel
spans = json.load(open("examples/otel_genai_spans.json"))
for call in from_otel(spans):
print(call["tool"], call["is_error"], call["error"])
result = evaluate(
expected=[{"tool": "search_orders"}, {"tool": "issue_refund"}, {"tool": "send_email"}],
actual=spans,
)
print(result.required_call_recall) # 0.67: the refund call failed
From the command line, OTLP JSON files are auto-detected, or pass
--format otel:
toolscore eval gold.json spans.json --format otel
Note
Tool arguments and results are opt-in attributes in the conventions (they may contain sensitive data). Without them, Toolscore still scores tool selection, order and failures, but not arguments.
MCP sessions
To score what an agent did against an MCP server, record the session with
toolscore mcp record (see Recording real sessions) and evaluate the file;
recorded sessions and plain JSON-RPC 2.0 message lists are auto-detected:
toolscore eval gold.json session.json