LangGraph Integration
Add trust verification to LangGraph StateGraphs. Gate agent execution on Nerq Trust Scores.
nerq-langgraph
v0.1.0
Python
Installation
pip install nerq-langgraph
Quick Start
Add a trust-check node to your LangGraph StateGraph. The node queries the Nerq API and blocks execution if the agent fails verification.
# 1. Import the trust check node from nerq_langgraph import create_trust_check_node # 2. Create the node with your threshold trust_check = create_trust_check_node( api_key="your-nerq-api-key", min_score=60, # minimum trust score (0-100) agent_field="agent_name" # state field containing the agent ID ) # 3. Add to your StateGraph from langgraph.graph import StateGraph graph = StateGraph(MyState) graph.add_node("trust_check", trust_check) graph.add_node("agent", my_agent_node) graph.add_node("fallback", fallback_node) # 4. Route based on trust result graph.add_edge("trust_check", "agent") # passes if score >= threshold graph.set_entry_point("trust_check") app = graph.compile()
Handling Trust Failures
from nerq_langgraph import TrustCheckFailed
try:
result = app.invoke({"agent_name": "untrusted-agent-123"})
except TrustCheckFailed as e:
print(f"Blocked: {e.agent_name} scored {e.score} (min: {e.threshold})")
# Route to fallback, log event, or alert team
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | env NERQ_API_KEY | Your Nerq API key |
min_score | int | 60 | Minimum trust score to pass (0-100) |
agent_field | str | "agent_name" | State field containing agent identifier |
cache_ttl | int | 300 | Cache duration in seconds |
FAQ
What is nerq-langgraph?
nerq-langgraph is a Python package that adds trust verification to LangGraph StateGraphs. It provides a trust-check node you insert into your graph that queries the Nerq API and blocks execution if an agent's trust score is below your threshold.
How does the trust check work?
The trust check node calls the Nerq API with the agent ID or name. Nerq returns a trust score (0-100) and grade. If the score is below your configured minimum (default: 60), the node raises a TrustCheckFailed exception, preventing downstream nodes from executing.
What happens if an agent fails the trust check?
When an agent fails the trust check, a TrustCheckFailed exception is raised with details including the agent name, score, and your threshold. You can catch this exception and route to a fallback agent, log the event, or alert your team.