Integrations

LangGraph Integration

AgentTrustNode for LangGraph state machine governance.

LangGraph Integration

Overview

The LangGraph adapter provides AgentTrustNode — a governance node you add to your LangGraph state graph. It validates agent output at a defined point in the graph execution.

Tier: Team+

Why It Matters

LangGraph agents need in-graph governance checkpoints, not just post-hoc validation. AgentTrustNode integrates natively with graph state and routing.

Prerequisites

pip install "agentrust-sdk[langgraph]"
# Team+ API key required

Step-by-Step Guide

1. Import adapter

from agentrust_sdk.adapters.langgraph import AgentTrustNode

2. Add node to graph

from langgraph.graph import StateGraph

governance = AgentTrustNode(agent_id="langgraph-agent")

graph = StateGraph(AgentState)
graph.add_node("agent", agent_node)
graph.add_node("governance", governance)
graph.add_edge("agent", "governance")
graph.add_conditional_edges("governance", route_on_decision)

3. Route on decision

def route_on_decision(state):
  if state.get("decision") == "block":
    return "error_handler"
  return "END"

4. Handle blocked outputs

The node sets governance fields in graph state. Check decision outcome before continuing.

Examples

See examples/langgraph_agent.py for a complete runnable graph.

from agentrust_sdk.adapters.langgraph import AgentTrustNode
from agentrust_sdk import embed_gateway

embed_gateway()
governance_node = AgentTrustNode(agent_id="research-graph")

Best Practices

  • Place governance node after LLM/tool nodes, before output delivery
  • Use conditional edges to route block and escalate outcomes
  • Pass parent_envelope_id for multi-node agent chains (Enterprise)
  • Set meaningful agent_id per graph deployment

Common Mistakes

  • Using without Team API key (TierGateError)
  • Placing governance node before agent produces output
  • Using auto_instrument() instead of AgentTrustNode for graph-level control

Troubleshooting

IssueFix
TierGateErrorUpgrade to Team tier
Node not in graph pathVerify edges connect through governance node
State missing outputEnsure upstream node writes output to state