[KongchangAI]
· 1 min read· 962 words

MockAgent: A Tool Mock Gateway Built for Testing LangChain Agents

MockAgent: A Tool Mock Gateway Built for Testing LangChain Agents

MockAgent is a local testing gateway for LangChain agents that uses Schema validation and mock isolation to simplify Agent debugging.

MockAgent is a lightweight developer tool that sits as a testing gateway between LangChain agents and external services, addressing two common pain points in multi-step Agent workflows: Schema drift and crashes caused by non-deterministic LLM output, and API quota burn and staging environment pollution from repeated live calls. Its core mechanism uses AJV to validate every tool call payload in real time, returning structured 400 errors with precise field paths when validation fails — enabling agents to self-correct. A visual dashboard tracks call history and Schema violation rates, making prompt tuning observable and reproducible. Built on Next.js 14 and Supabase, it is currently free and open for community feedback.

Building multi-step AI agent workflows is often trickier to test locally than you'd expect. One developer shared their solution on Reddit: MockAgent — a lightweight tool mock and Schema validation gateway designed specifically for LangChain agents, aimed at solving two of the most frustrating pain points in Agent development.

MockAgent reddit original post

Two Major Pain Points in Agent Development

While building agent pipelines with LangGraph and custom tool functions, developers frequently run into two recurring problems.

The first is Schema drift and broken payloads. A classic scenario: the first four steps execute smoothly, but on step five, the LLM suddenly hallucinates a nonexistent field, or passes an integer 50 as the string "50". The real API responds with a generic 400 Bad Request, and the agent either crashes outright or falls into an infinite retry loop. For workflows that depend on the non-deterministic output of LLMs, these errors are both hard to spot and surprisingly frequent.

The second is quota burn and staging environment pollution. During prompt tuning, every iteration triggers real calls to live services like Stripe, GitHub, or a database. Each time the LLM retries a failed call, it burns precious API quota and potentially writes dirty data to your staging environment, making it unreliable for further testing.

The author points out that traditional mock tools like Postman and WireMock aren't well-suited for the non-deterministic nature of LLM tool calls — which is why a purpose-built middleware layer for Agent scenarios is needed.

How MockAgent Works

MockAgent's role is clear: during development, it sits as a gateway between your LangChain agent and external services, intercepting and handling all tool calls.

Virtual Mock Tools

Developers simply provide an expected JSON Schema, and a mock endpoint can be configured in seconds. Point the HTTP requests from your agent's tools at MockAgent, and you can run the entire pipeline in complete isolation from real services.

Real-Time Schema Validation

This is the core feature that sets MockAgent apart from ordinary mock services. It uses AJV (Another JSON Schema Validator) to validate every incoming payload in real time, only returning the preset mock JSON response after confirming the payload is valid. This means the agent must satisfy the Schema constraints before it receives a "success" response.

AJV (Another JSON Validator) is currently the highest-performance and most widely used JSON Schema validation library in the JavaScript ecosystem. It supports JSON Schema Draft-04 through Draft-2020-12 as well as JSON Type Definition. By pre-compiling schemas into optimized JavaScript functions, it achieves extremely low validation latency — making it especially well-suited for gateway scenarios that require synchronous validation on every request. In the context of MockAgent, AJV acts like a runtime type guard: even if the LLM's output is syntactically valid JSON, any mismatch in field types, enum values, or required fields will be precisely reported by AJV, rather than returning a generic error that leaves developers with nothing to debug.

Self-Correction Feedback

When the LLM passes an invalid payload, MockAgent doesn't return a vague error — it responds with a structured 400 that includes a precise validation error path, such as Expected int at root.amount, got string. This accurate error targeting serves a key purpose: it lets you test whether your agent's prompt can actually read the error and self-correct. For anyone building robust agents, this is exactly the capability most worth validating.

Trajectory Logging

An accompanying visual dashboard tracks tool call history, Schema violation rates, latency metrics, and more — giving developers a clear view of behavior patterns and weak spots across the entire agent pipeline.

Tech Stack and Openness

According to the author, MockAgent is built on Next.js 14 and Supabase, and is currently free to try. At the end of the post, the author actively solicited feedback from the LangChain community — particularly around which edge cases or custom assertions would make the tool more practical in real Agent testing pipelines.

Why This Kind of Tool Is Starting to Matter

As agent workflows evolve from simple single-shot calls to complex multi-step, multi-tool orchestrations, test determinism has become an unavoidable challenge. The unpredictability of LLM outputs breaks the traditional software testing assumption that "given the same input, you get the same output."

MockAgent's approach — using Schema validation to enforce constraints on tool call inputs, and feeding error information back to the agent to drive self-correction — essentially introduces the concept of contract testing into Agent development. It protects live API quotas and test data, while turning prompt tuning into an observable, reproducible process.

Of course, as an early-stage tool still soliciting feedback, its real-world performance remains to be validated by more LangChain developers. But the problem it targets — isolation and reliability in local Agent testing — is a genuinely widespread gap in the current ecosystem. For teams building production-grade agent workflows, this category of gateway tooling is worth keeping an eye on.

Contract Testing originated in the microservices world. The core idea is that a service's consumer and provider decouple through a mutually agreed-upon "contract" — the consumer only needs to verify that its requests conform to the contract, while the provider only needs to verify it can handle the requests described in the contract. Neither side needs to be online simultaneously for independent testing. Pact is the most well-known open-source framework in this space. Applying this concept to Agent development is highly meaningful: the LLM plays the role of the "consumer," external tool APIs are the "providers," and JSON Schema serves as the contract between them. What MockAgent does, in essence, is automatically execute consumer-side contract verification on every tool call — catching interface incompatibilities between the LLM and the API during development, rather than waiting for them to surface in production.

#MockAgent#LangChain agent testing#JSON Schema validation#AJV#tool mock gateway#LLM agent development#contract testing#LangGraph
Share:

Related articles