Principle:Truera Trulens LangGraph Agent Wrapping
| Knowledge Sources | |
|---|---|
| Domains | Observability, Agent_Evaluation |
| Last Updated | 2026-02-14 08:00 GMT |
Overview
An instrumentation pattern that wraps compiled LangGraph agents with automatic node, task, and Pregel-level tracing for evaluation with agent-specific metrics.
Description
LangGraph Agent Wrapping provides specialized instrumentation for LangGraph compiled graphs (Pregel objects). LangGraph agents are stateful, multi-step workflows with conditional branching, tool calls, and iterative loops. The wrapper understands LangGraph's internal execution model and instruments:
- Graph nodes: Individual steps in the agent workflow
- Task functions: Parallel task execution within nodes
- Pregel methods: The core invoke/ainvoke entry points
This specialized instrumentation captures the full agent execution trace, enabling agent-specific evaluation metrics like tool selection quality, step efficiency, and reasoning coherence.
TruGraph inherits from TruChain and combines LangChain and LangGraph instrumentation.
Usage
Use this principle when evaluating LangGraph compiled agents. Wrap the compiled graph (not the StateGraph builder) after defining agent evaluation metrics. The wrapper requires the graph to be compiled before wrapping.
Theoretical Basis
Agent wrapping extends the standard instrumentation pattern with graph-aware tracing. Unlike linear chains, agents have:
- Conditional edges: Different execution paths per invocation
- State management: Shared state modified by each node
- Tool loops: Iterative tool invocations until completion
Pseudo-code Logic:
# Abstract agent wrapping pattern
graph = StateGraph(AgentState)
graph.add_node("agent", agent_node)
graph.add_node("tools", tool_node)
graph.add_conditional_edges("agent", should_continue, ...)
compiled = graph.compile()
# Wrap compiled graph for agent evaluation
wrapped = TruGraph(
compiled,
app_name="Agent_v1",
feedbacks=[f_tool_selection, f_relevance, f_groundedness]
)