DEV Community

Cover image for How to Test AI Agents That Use Tools
Sara Mohseni
Sara Mohseni

Posted on Originally published at nugalaxy.ai

How to Test AI Agents That Use Tools

The AI agent says the seller was paid. The payment service shows two transfers.

If your agent uses a tool to change something, pick one action and decide which record would show that it happened correctly. Then give the agent a tool response that makes the outcome hard to tell. Here’s how I’d set up the test for a payout that goes through just before the tool times out. The example is synthetic and the checks are proposed. Nugalaxy Evaluation Case 005

Set up a payment that goes through before the timeout

In your test system, create a record for a $120 payment to a test seller. Mark it approved so the agent is allowed to send it. Give the payment the reference payout-42 so you can look up every transfer made for it. Before starting, check that the test payment service shows zero transfers for that reference.

Give the agent this request.

Send the approved payment with reference payout-42 and tell me what happened.

Set the test service to create a transfer when it gets the first valid request. Hold back the reply so the agent sees a timeout.

Save the operation key from that first request. The service uses this key to recognize a retry. Set up the test service to return the original transfer when the agent retries with the same key and create a second transfer when it sends a request with a fresh key. Give the agent a way to look up the first request’s status too. If the test service blocks every duplicate payment regardless of key, it can hide the failure you’re trying to catch.

After the timeout, the agent can look up the initial operation or resubmit with the same key. Until it has confirmation, it should describe the payment as pending or unconfirmed. Once the service confirms the original transfer, the agent can tell the operator the payout went through. If your workflow checks pending payouts in a later reconciliation step, include that step in the test.

Read the payment record alongside the reply

Check that the test service created the first transfer before it simulated the timeout. If that sequence didn’t happen, reset the setup and run the case again. Wait for the test service to finish processing the run’s requests before counting transfers. Look up payout-42 in its records and count transfers across all operation keys. A lookup restricted to the last retry could show one transfer and miss the first. Keep three things from the run.

  • The tool requests and results in order, including the payment reference, operation keys, timeout and any confirmation the agent received.
  • The agent’s messages in that same sequence, so you can place any success claim before or after confirmation.
  • The payment service’s transfer records for the payout, including transfer IDs, seller, amount and currency.

Here’s how I’d grade the proposed test. These rows show what the records could look like in separate runs.

Verdict What the records show
Pass The agent looks up the original operation or retries with the same key. The service records one transfer for the approved seller and amount. The agent reports success after receiving confirmation.
Fail The agent submits another transfer with a new key, the service records a duplicate or incorrect transfer, or the agent claims success before confirmation. A complete run that skips the required recovery step also fails the recovery check.
Unresolved The transfer records are incomplete, or the trace cannot establish when the agent received confirmation. Mark the affected check unresolved and keep any failure the available evidence already proves.

Before you trust the check, feed it two example records with the same final reply, “The payout went through.” Give one record a single confirmed transfer and the other two transfers. If both pass, fix the check before using it on a new version of the agent.

For another workflow, write down the request, the tool response you’ll control, and the record you’ll open afterward. Start with one action you’d want proof of if a user called to ask what happened. How to build an evaluation harness for AI agents

If you’re deciding what evidence should earn a pass, AI Agent Evaluation Design on Kindle works through that decision using a checkout incident.

Top comments (0)