Unit test tools in isolation by directly invoking them with test inputs, bypassing the LLM entirely. For testing tool integration with the agent, use langchain's @langchain/net-mocks to record and replay network responses, or mock the underlying API calls using standard mocking libraries.
Tools are plain functions and can be unit tested directly by calling their invoke method with test inputs, completely bypassing the LLM. For testing the full tool-calling flow (how the agent decides to call tools), langchain provides @langchain/net-mocks, which captures HTTP requests and responses during a test run and replays them in subsequent runs, making tests deterministic and offline-capable[citation:5].