An agent test fails in three different places: the model's reasoning, your orchestration code, and the external API. If all three run in the same test, a red build tells you almost nothing about which one broke. Mocking the tool boundary removes the third variable, and it also removes the two things that make agent tests unpleasant to run: waiting on the network and the risk of changing real data.
The classic integration-testing argument applies directly. When code under test depends on another system, you substitute a controlled stand-in so the test runs predictably without side effects as described in this discussion of external API tests. That conversation also flags the awkward case agent developers hit constantly: a POST endpoint with side effects and no sandbox. Mocking is often the only honest option.
There is a second, agent-specific reason. Tool design, not model capability, drives most agent failures, and vague schemas or weak error handling produce failures that are predictable rather than accidental per this analysis of agent tool design. Deterministic mocks let you assert on exactly what the agent sent: the tool name, the arguments, the argument types. That is how you catch a schema problem before a user does.
Mocks also let you test the unhappy paths that are hardest to trigger live. You cannot wait for a real rate limit to fire in CI, but you can serve a recorded 429 in milliseconds. Error responses need to tell the agent what to do next, because a bare "Bad Request" leaves a reasoning model with no way to self-correct argued here in detail. Mocks are how you prove your error payloads actually contain that guidance.



