# LangChain evals

LangChain is an open-source library for building agents. Its create_agent function takes a model, a list of tools, and a system prompt, and runs the loop: call the model, run the tools it asks for, feed the results back, repeat until it answers. Agents built this way run on LangGraph, so they get saved state and resumable runs without you writing a graph.

Most of what you change in a LangChain agent is middleware. Middleware wraps the model call or the tool call, and the built-in ones cover retries, guardrails, and routing. That makes behavior depend on which middleware is installed, so adding or removing one is a change worth evaluating like a prompt edit.

Tool failures show why. ToolErrorMiddleware catches an exception raised by a tool and hands it back to the model as an error message, so the run keeps going and the model can try something else. It does not retry. ToolRetryMiddleware does that separately, with exponential backoff, and by default makes two retries after the first attempt. When it gives up it also returns the error to the model. So a failing tool often doesn't stop the run, and the failure shows up as a tool message instead of a crash. Evaluating the agent means checking what it did after that message, since the absence of an exception says little.

Tracing goes to LangSmith. Set LANGSMITH_TRACING to true along with an API key, and traces show tool calls, state transitions, and latency.

## Questions answered under this concept

- [How does a LangChain agent handle a tool error?](https://tessary.ai/answers/langchain-evals/how-does-a-langchain-agent-handle-a-tool-error)

---

Source: https://tessary.ai/answers/langchain-evals
All concepts: https://tessary.ai/answers
From Tessary, agent reliability for AI agents in production: https://tessary.ai
