Skip to content

Tool-call debugging

How to Debug AI Agent Tool Calls

A failed tool call can originate in the arguments, the tool implementation, external state, or an earlier agent decision. Debug it by preserving the original evidence, changing one boundary at a time, and verifying the production change separately.

Recognize the tool-call failure you actually have

AI agent tool failures are not limited to exceptions. A call can complete successfully at the transport layer and still return the wrong data, use malformed arguments, time out, or send the agent down an unproductive path. Start by naming the observed failure rather than guessing at its cause.

  • Wrong arguments: the agent selected the tool but violated its input contract.
  • Bad result: the tool returned empty, stale, malformed, or semantically incorrect data.
  • Execution error: the tool raised an exception, timed out, or lost its dependency.
  • Downstream misuse: the result was valid, but a later model or agent step interpreted it incorrectly.

A final answer alone cannot distinguish these cases. Preserve the call arguments, result or error, surrounding messages, and downstream events from the same run.

Capture the agent and tool boundaries

Debrix uses explicit, framework-agnostic Python instrumentation. Keep your existing runtime and wrap the root agent plus the tools you need to inspect. The desktop app receives the trace locally over OTLP.

from debrix import configure, force_flush, trace_agent, trace_tool

configure(batch=False, service_name="travel-agent")

@trace_tool(name="search_places")
def search_places(country_code: str) -> list[str]:
    return places_api.search(country_code=country_code)

@trace_agent(name="travel_planner")
def run_agent(request: str) -> str:
    destinations = search_places(country_code="FR")
    return plan_trip(request, destinations)

run_agent("Plan a weekend in France")
force_flush()

The @trace_tool decorator records replay input and output for the call. @trace_agent records the agent boundary and its JSON-safe bound arguments. Call force_flush() before a short-lived script exits so spans and complete payloads arrive together.

For MCP tools, use the public MockableClient wrapper around the real MCP client. For model calls, record messages and responses on an LLM span or use the supported Debrix LLM helper. Native LangGraph and OpenAI adapters are not implied by this instrumentation.

Inspect the failed boundary in context

Open the failed run in the Debrix UI, or let a coding agent inspect it over MCP. If the trace completed with an application-level wrong answer, mark it failed before promoting it into a durable Failure investigation.

Read the evidence in execution order

  1. Confirm the original user request and the outcome that was expected.
  2. Inspect the exact tool name and arguments that the agent produced.
  3. Compare the returned value or error with the tool’s real contract.
  4. Follow later model, tool, and agent events to see where the bad value propagated.
  5. Define or approve the outcome contract that will label experiments passed, failed, or inconclusive.

Keep observations separate from hypotheses. “The tool returned an empty list” is evidence. “The tool implementation is broken” is only one possible explanation until an experiment distinguishes it from bad arguments or external state.

Change one captured boundary at a time

A controlled Failure experiment reconstructs the recorded prefix, pauses at the selected boundary, and lets you keep, edit, or skip the captured value before the existing agent continues. Every later event retains explicit provenance:

  • Recorded evidence was replayed from the original run.
  • Edited evidence was deliberately changed for the experiment.
  • Live evidence came from the real runtime after the intervention.

Use two experiments to separate common causes

First, replace only the bad tool result with a valid recorded value. If the downstream outcome passes, you have evidence that later behavior can work with valid data—but not that the tool implementation is the cause.

Next, edit only the tool arguments and let the real tool execute live. If corrected arguments repeatedly produce valid results, the fault boundary narrows toward the input contract or the code, prompt, or state that formed the call.

One edited boundary supports bounded single-variable language. Multiple edits form a compound experiment and show only the combined effect.

Verify the production change without the diagnostic override

A passing branch is a diagnostic result, not the fix. Apply the real change to the code, prompt, schema, model, policy, or tool implementation. Then create a verification attempt in Debrix and invoke the original scenario through the existing project with the one-time launch environment supplied by the UI or MCP.

Managed verification bypasses Tool Mocker, controlled branches, and replay for supported boundaries. Debrix does not launch the project or invent the success criterion. Your approved deterministic test, state or trace predicate, human verdict, or explicitly labelled probabilistic judge supplies the result.

Once the current production change passes the original scenario with no exploratory overrides, save the case as a regression. The historical diagnostic evidence remains separate from the verified fix.

AI agent tool-call debugging checklist

  1. Capture the root agent, tool arguments, tool result or error, and downstream events.
  2. Promote the representative failed run into a durable Failure.
  3. Define the expected outcome and its validation source.
  4. Inspect evidence before writing a root-cause claim.
  5. Run one controlled intervention per causal hypothesis.
  6. Apply the actual production change outside the diagnostic branch.
  7. Rerun the original scenario with overrides removed.
  8. Save the passing verified case as a regression.

FAQ

Common questions

Can Debrix tell me the root cause automatically?

No. Debrix records the intervention, what stayed fixed, how the trajectory changed, and how the outcome was validated. That evidence can narrow the fault boundary without pretending that one passing override proves the complete root cause.

Does a mocked tool result prove the tool is broken?

No. It proves that downstream behavior can succeed with different data. The original arguments, tool implementation, external state, and earlier prompt or code may still be possible causes.

Do I need to replace my agent framework?

No. Instrument the existing Python runtime with the public Debrix SDK. Native framework adapters are not currently shipped, so framework-specific boundaries should be instrumented explicitly.

Can a coding agent drive the investigation?

Yes. Cursor, Claude Code, or Codex can use the Debrix MCP workflow to inspect evidence and guide experiments while you or the coding agent still invoke the existing project.

Bring the next failure to Debrix.

Join the waitlist for controlled early access to the complete local Failure → Fix loop.