World’s largest virtual agentic engineering & quality conference

WHENAUG 19-21
WHEREVirtual · Global
Register Now
Agent TestingAI

How to Test a LangChain or LangGraph Agent

LangSmith and AgentEvals test your LangGraph agent's code and trajectories. Neither sweeps hundreds of real-user conversations at scale. Here's how to test one.

Author

Akarshi Aggarwal

Author

Author

Salman Khan

Reviewer

Last Updated on: July 24, 2026

Your LangGraph agent passes every eval in the notebook. The trajectory matches, the tools fire in order, the final answer looks right. Then a real user opens the chat, phrases the request three different ways in one message, gets impatient, and the agent loops on the wrong tool until it gives up.

That gap is the norm, not the exception. In LangChain's own State of AI Agents survey, performance quality was the top challenge respondents named for shipping agents, ahead of cost, even as teams at Uber, LinkedIn, Replit, and Elastic run LangGraph agents in production. The framework makes it fast to build a capable agent. It does not tell you whether that agent survives a real user.

This guide covers how a LangChain or LangGraph agent is actually built, why it passes tests and fails in production, the four dimensions worth testing, and a step-by-step approach, from the framework's own tools to automated evaluation at scale.

Overview

What Is a LangGraph Agent?

A stateful graph of nodes and tools, built in Python or JavaScript, that decides its own path through a conversation rather than following a fixed script, usually deployed behind an HTTP endpoint.

What Does the Framework Give You for Testing?

  • LangSmith runs evaluations at scale with pytest and Vitest integrations and tracks results across experiments.
  • AgentEvals checks the agent's trajectory against a reference or with an LLM judge.

What Do Those Tools Miss?

They run on inputs a developer wrote. They do not sweep hundreds of persona-varied, adversarial, real-user conversations against the deployed agent or grade it for hallucination, tone, and safety.

How Do You Close That Gap?

TestMu AI's Agent Testing platform hits the deployed agent endpoint with autonomous evaluators across 10 personas, scores every conversation on 9 quality metrics, and returns a Green, Yellow, or Red production-readiness verdict.

What Is a LangChain or LangGraph Agent?

LangChain is the framework for composing calls to a language model, tools, and data. LangGraph is its stateful sibling for agents: instead of a linear chain, you define a graph where the model decides which node or tool to visit next, keeping state across turns. That control is why teams reach for it, and why testing it is harder than testing a plain chain.

What a real LangGraph agent is made of:

  • Nodes that call the model, run a tool, or transform state, wired into a graph with conditional edges the agent traverses at runtime.
  • Tools and function calls that reach out to a database, an API, a retriever, or another agent mid-conversation.
  • A persisted state object that carries context, message history, and intermediate results across turns.
  • A deployment surface, often the LangGraph Platform server or a custom HTTP endpoint, that exposes the agent to a front end or another service.

Because the agent chooses its own path, two runs of the same input can take different routes. That non-determinism is the whole point of an agent, and it is exactly what a fixed input-output assertion cannot capture. For a hands-on build example, our guide to a Playwright LangChain agent walks through wiring one up end to end.

Why Do LangChain Agents Pass Tests but Fail in Production?

LangChain's own testing documentation splits agent testing into unit tests, integration tests, and evals. All three are valuable, and all three run on inputs you chose. Most production failures live in the inputs you did not.

Failure ModeWhere It Comes FromWhat Breaks with a Real User
Wrong tool selectionThe model routes to a tool based on phrasing it was never tested against, and conditional edges send it down a branch you did not exercise.The agent calls a search tool when it should have called the booking tool, and confidently returns a useless answer.
Context loss across turnsState that survived a two-turn eval gets truncated or overwritten across a longer, messier real conversation.The agent asks for information the user already gave, or contradicts an answer from three turns ago.
Hallucinated tool argumentsThe model fills a function argument with a plausible-looking value it invented rather than one grounded in the conversation.A tool fires with a made-up order ID or date, mutating real data against the wrong record.
Prompt injection through tool outputA retriever or web tool returns content containing instructions, and the agent follows them instead of its own system prompt.The agent leaks data or ignores a policy because a document told it to.
Silent regression after a model swapUpgrading the underlying model or editing a prompt changes routing and tone in ways the existing eval set never checks.Behavior that worked last release degrades, and nothing forces a re-test before merge.
Next-generation test execution with TestMu AI

What Should You Test in a LangChain Agent?

Whether the agent is a support copilot, a research assistant, or a data agent, the same four dimensions decide whether it is ready for real users. Each needs a different kind of scenario, not just more curated dataset rows.

DimensionWhat It ChecksExample on a LangGraph Agent
Task SuccessWhether the agent completed the job, including the tool calls and state updates it took to get there.The right tool fires with correct arguments, and the final answer reflects the tool's actual result.
Conversation QualityCoherence across turns, context retention, and whether the agent recovers when a user changes direction.The agent remembers a constraint from turn one and applies it when the user asks a follow-up five turns later.
SafetyNo invented facts or arguments, no PII leakage, and refusals where policy requires them.The agent refuses to act on injected instructions in a retrieved document and never fabricates a value for a tool call.
ResilienceBehavior under adversarial input, ambiguous phrasing, and tool or API failures.The agent degrades gracefully when a tool times out, instead of hallucinating a result to fill the gap.

How Do You Test a LangChain or LangGraph Agent, Step by Step?

Testing happens in three layers: what you assert in code, how you evaluate the trajectory the agent took, and how you score the deployed agent against the messy real-user traffic none of the first two simulate.

1. Start With LangSmith, Pytest, and Evals

LangSmith runs evaluations at scale, tracks results over time, and compares experiments, and its pytest and Vitest integrations let you drop agent evals straight into the test suite you already run. Unit tests exercise deterministic pieces of the agent with in-memory fakes; integration tests confirm the real components work together; evals score the output with a rubric or an LLM judge.

This is the right foundation for correctness on inputs you can enumerate. Its blind spot is the input you cannot: the angry user, the ambiguous phrasing, the prompt-injection payload buried in a retrieved document. Those are not dataset rows you happen to have written.

2. Evaluate Trajectories With AgentEvals

For agents, the answer alone is not enough; the path matters. LangChain's AgentEvals package evaluates the trajectory, the list of messages and tool calls the agent produced. Its create_trajectory_match_evaluator compares that trajectory to a reference in strict, unordered, subset, or superset mode, and tool_args_match_mode controls how strictly tool arguments must match.

When you do not have a reference trajectory, create_trajectory_llm_as_judge grades the path with an LLM instead. This catches wrong-tool and wrong-order bugs precisely. What it does not do is generate the hundreds of adversarial, persona-varied conversations that surface those bugs in the first place.

3. Score the Deployed Agent at Scale, Automatically

This is where TestMu AI's Agent Testing plugs in, at the endpoint your agent actually serves. Instead of dataset rows you authored, autonomous evaluators hold full multi-turn conversations with the deployed agent the way real users would, across 10 pre-built personas including confused, impatient, angry, and off-script users, and score every conversation on the same 9 quality metrics each time.

Connecting a LangGraph agent takes only its endpoint plus a prompt describing what it should and should not do. The platform generates 60-100+ scenarios from that prompt automatically, distributed across happy-path flows, edge cases, and adversarial input, so coverage stops depending on which failure cases a developer thought to write down.

Testing a LangGraph Agent With TestMu AI's Agent Testing

Connecting Agent Testing to a LangGraph agent does not require an SDK or a change to the graph. It calls the agent's HTTP endpoint directly, adapting to a non-standard request shape with a body template and a response path, then layers three inputs on top before generating a full scenario set.

# Point the evaluator at a custom LangGraph endpoint
testmu-a2a test \
  --agent https://your-langgraph-app/invoke \
  --body-template '{"input": {"messages": [{"role": "user", "content": "{{message}}"}]}}' \
  --response-path "output.messages[-1].content" \
  --spec "Support agent that answers billing questions and calls the refund tool" \
  --count 30
  • Upload the same PRD, tool spec, or system prompt the agent was built from, and the platform parses it for behavioral requirements and scenario seeds.
  • Paste in the agent's system prompt, so the evaluation baseline matches what the agent is actually instructed to do.
  • Add focus areas that weight scenario generation toward what matters most this run, such as tool-selection accuracy and refusal behavior.

From there, autonomous evaluators run the generated scenarios against the endpoint and score each on the 9 quality metrics. A tool call is checked against what it actually should have done, not just whether it returned a response, and every run rolls up into a Green, Yellow, or Red verdict, the same model our overview of AI agent testing walks through in depth.

Note

Note: Point TestMu AI's Agent Testing at your LangGraph endpoint and get a Green, Yellow, or Red production-readiness verdict before your first real user does. Start testing free

Which Metrics Matter for a LangChain Agent?

A trajectory match tells you the agent took the expected steps. It does not tell you whether the final answer was honest, complete, or safe. Agent Testing scores each conversation on 9 quality metrics that apply to any chat agent, tuned for exactly the ways a tool-using agent goes wrong.

  • Hallucination detection catches invented facts and, critically for agents, invented tool arguments the model filled in rather than grounded.
  • Context awareness checks whether the agent's persisted state actually held across a long conversation, not just a two-turn eval.
  • Completeness and root-cause understanding checks whether the agent solved the real problem or a related one that looked close.
  • Tone consistency and bias detection checks for the same response quality regardless of how the user phrased the request.

Every score also carries a confidence level, High, Medium, or Low, based on how many scenarios actually ran, so a Green built on ten scenarios is never mistaken for a Green built on three hundred. That distinction is what separates a demo that passed from an agent that is ready.

How Do You Red-Team a LangChain Agent?

The four dimensions cover a user trying to get help. Red-teaming covers a user, or a poisoned document, trying to break the agent on purpose: override the system prompt, exfiltrate data through a tool, or coax out PII. Agents are especially exposed here because they call real tools and read untrusted content. The testmu-a2a-cli runs adversarial probes against the endpoint, scoring categories including prompt injection, jailbreak, data exfiltration, and PII leakage at basic, intermediate, or advanced intensity.

testmu-a2a redteam \
  --agent https://your-langgraph-app/invoke \
  --intensity advanced \
  --spec "LangGraph support agent with refund and account tools"

# Target specific attack categories only
testmu-a2a redteam \
  --agent https://your-langgraph-app/invoke \
  --categories prompt-injection,jailbreak,pii-leakage

The output is a letter grade, A+ to F, per category rather than one pass or fail, because an agent can resist a direct jailbreak and still follow instructions injected through a retrieved document. For any agent wired to tools that mutate data, that per-category grade is the gap between a vulnerability you found and one an attacker finds.

Austin Siewert

Austin Siewert

Co-Founder, Steadfast Systems

Discovered @TestMu AI yesterday. Best browser testing tool I've found for my use case. Great pricing model for the limited testing I do 👏

2M+ Devs and QAs rely on TestMu AI

Deliver immersive digital experiences with Next-Generation Mobile Apps and Cross Browser Testing Cloud

How Do You Run LangGraph Agent Tests in CI/CD?

A prompt edit, a new tool, or a model upgrade merges the moment the PR does. LangSmith's pytest and Vitest integrations run your evals in the same pipeline, and the testmu-a2a-cli adds the endpoint-level sweep: it installs with pip, authenticates from CI secrets instead of an interactive login, and writes JUnit XML that GitHub Actions, GitLab CI, and Jenkins read natively.

# .github/workflows/langgraph-agent-tests.yml
name: LangGraph Agent Tests
on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Install TestMu A2A CLI
        run: pip install testmu-a2a-cli
      - name: Run LangGraph agent regression suite
        env:
          TESTMU_USERNAME: ${{ secrets.TESTMU_USERNAME }}
          TESTMU_ACCESS_KEY: ${{ secrets.TESTMU_ACCESS_KEY }}
        run: |
          testmu-a2a test \
            --agent https://your-langgraph-app/invoke \
            --spec "LangGraph support agent with refund and account tools" \
            --format junit --output results.xml
      - name: Publish results
        uses: dorny/test-reporter@v1
        if: always()
        with:
          name: LangGraph Agent Test Results
          path: results.xml
          reporter: java-junit

Gate on exit code: 0 for all scenarios passed, 1 for any failure. Run the full evaluation for prompt, tool, or model changes, and a smaller smoke set for a refactor that does not touch agent behavior, so every commit is not blocked on a full regression pass. The discipline is the same one covered in our guide to AI agent regression testing.

What Won't Automated Testing Catch?

A Green verdict means the agent passed on the scenarios you ran, with the personas you tested, on the metrics you configured. Here is what it does not cover:

  • A low-confidence Green is not a cleared launch. It means too few scenarios ran to trust the score yet, so run more, especially on hallucination and injection resistance, before you ship.
  • Cross-session memory is not evaluated end to end. If your agent is supposed to recall a user across sessions, test that persistence path separately.
  • Non-determinism means one clean run is not proof. Run the scenario set enough times to see the distribution of paths the agent actually takes.
  • Highly specialized domains need custom rules. The default 9 metrics cover general quality well, but an agent giving medical, legal, or financial guidance needs custom validation criteria on top.
  • A stale spec gives you a stale verdict. If the agent's behavior changed and the prompt describing "correct" did not, some regressions slip through and some good new behavior gets flagged as failure.

None of this is a reason to skip testing. It is a reason to keep testing after launch, not just before it.

Conclusion

Take the LangGraph agent you already have passing its evals. Point it at a harder question than the notebook ever asked: what happens when a user is angry, phrases the request three ways at once, or feeds it a document that tells the agent to ignore its instructions. LangSmith and AgentEvals catch the trajectory bugs. TestMu AI's Agent Testing catches the rest, running the deployed agent through hundreds of personas and adversarial probes and handing back a go-live verdict before a real user finds the gap first.

Point the evaluator at your endpoint, check the setup docs, and run your first evaluation before the next prompt or model change merges.

Author

...

Akarshi Aggarwal

Blogs: 27

  • Linkedin

Akarshi Aggarwal is a community contributor with 2+ years of experience in marketing and growth. She specializes in automation testing and frameworks like Cypress, Playwright, Selenium, and Appium. Akarshi has written numerous technical articles, contributing valuable insights into automation testing practices. She actively engages with the tech community, sharing expertise on test automation and quality engineering. On LinkedIn, she is followed by over 7,000 QA professionals, software testers, DevOps engineers, developers, and tech enthusiasts.

Reviewer

...

Salman Khan

Reviewer

  • Linkedin

Salman is a Test Automation Evangelist and Community Contributor at TestMu AI, with over 6 years of hands-on experience in software testing and automation. He has completed his Master of Technology in Computer Science and Engineering, demonstrating strong technical expertise in software development, testing, AI agents and LLMs. He is certified in KaneAI, Automation Testing, Selenium, Cypress, Playwright, and Appium, with deep experience in CI/CD pipelines, cross-browser testing, AI in testing, and mobile automation. Salman works closely with engineering teams to convert complex testing concepts into actionable, developer-first content. Salman has authored 120+ technical tutorials, guides, and documentation on test automation, web development, and related domains, making him a strong voice in the QA and testing community.

Open in ChatGPT Icon

Open in ChatGPT

Open in Claude Icon

Open in Claude

Open in Perplexity Icon

Open in Perplexity

Open in Grok Icon

Open in Grok

Open in Gemini AI Icon

Open in Gemini AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free
...
TestMu Conf 2026

World's largest virtual agentic engineering & quality conference

...

AUG 19-21, 2026

REGISTER NOW

LangChain Agent Testing FAQs

Did you find this page helpful?

More Related Blogs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests