Agent Framework
Integrations
Add API governance to your AI agents in minutes. Copy-paste ready examples for LangGraph, AutoGen, CrewAI, and LangChain — powered by the zero-config CodeRifts guard decorator and Python SDK.
Installation
Python SDK
pip3 install coderifts-sdk
TypeScript SDK
npm install @coderifts/sdk
For MCP-based integration (Claude Desktop, Cursor, Windsurf), see coderifts.com/mcp.
Framework Examples
LangGraph — Preflight Node
Add a governance preflight node to your LangGraph state graph. The node checks tool safety before execution and blocks unsafe invocations.
Install dependencies
pip3 install coderifts-sdk langgraph
Full working example
from langgraph.graph import StateGraph
from coderifts import CodeRifts
coderifts = CodeRifts(api_key="cr_live_...")
def preflight_node(state):
result = coderifts.preflight_check(
tool_name=state["tool_name"],
old_spec=state["old_spec"],
new_spec=state["new_spec"]
)
if not result.safe:
return {**state, "blocked": True, "reason": result.reflex_triggers}
return {**state, "blocked": False}
def tool_node(state):
if state.get("blocked"):
return state # skip execution
# ... execute tool
return state
builder = StateGraph(dict)
builder.add_node("preflight", preflight_node)
builder.add_node("execute", tool_node)
builder.add_edge("preflight", "execute")
graph = builder.compile()
AutoGen — Safe Tool Wrapper
Wrap any AutoGen tool function with a CodeRifts preflight check. If the API change is unsafe, the tool returns a BLOCKED message instead of executing.
Install dependencies
pip3 install coderifts-sdk pyautogen
Full working example
import autogen
from coderifts import CodeRifts
coderifts = CodeRifts(api_key="cr_live_...")
def safe_tool_call(tool_name, old_spec, new_spec, tool_fn, *args, **kwargs):
result = coderifts.preflight_check(
tool_name=tool_name,
old_spec=old_spec,
new_spec=new_spec
)
if not result.safe:
return f"BLOCKED: {result.decision}. Triggers: {result.reflex_triggers}"
return tool_fn(*args, **kwargs)
# Wrap any AutoGen tool with CodeRifts preflight
CrewAI — Safe API Tool
Create a CrewAI tool class that runs a preflight check on initialization. If the API change is blocked, the tool raises a RuntimeError to prevent execution.
Install dependencies
pip3 install coderifts-sdk crewai
Full working example
from crewai import Agent, Task, Crew
from coderifts import CodeRifts
coderifts = CodeRifts(api_key="cr_live_...")
class SafeAPITool:
def __init__(self, tool_name, old_spec, new_spec):
self.tool_name = tool_name
self.preflight = coderifts.preflight_check(
tool_name=tool_name,
old_spec=old_spec,
new_spec=new_spec
)
def run(self, *args, **kwargs):
if not self.preflight.safe:
raise RuntimeError(f"CodeRifts BLOCK: {self.preflight.decision}")
# ... execute tool
LangChain — Preflight Tool
Run a preflight check inside a LangChain tool. If the API change is blocked, the tool raises an exception so the agent cannot call the unsafe endpoint.
Install dependencies
pip3 install coderifts-sdk langchain-core
Full working example
from langchain_core.tools import tool
from coderifts import CodeRifts
coderifts = CodeRifts(api_key="cr_live_...")
@tool
def get_order_status(order_id: str) -> str:
"""Look up an order status before calling the API."""
result = coderifts.preflight_check(
tool_name="get_order_status",
old_spec=OLD_SPEC,
new_spec=NEW_SPEC,
)
if not result.safe:
raise RuntimeError(f"CodeRifts {result.decision}")
# ... call the API and return the status
return status
All SDK Methods
| Method | Description | Returns |
|---|---|---|
| diff(before, after) | Full OpenAPI spec diff analysis | omega_decision, risk_score |
| preflight_check(...) | Agent tool invocation safety check | decision, safe, reflex_triggers |
| explain_decision(...) | Human-readable explanation | explanation, summary |
| how_to_unblock(...) | Actionable steps to resolve BLOCK | steps, summary |
| score_mcp(manifest) | MCP manifest agent safety score | overall_score, band |
| get_ledger(...) | Query compliance ledger | entries, total |
| simulate_policy(...) | Test YAML policy against specs | effective_action, matched_rules |
Default Policy
CodeRifts provides a recommended default policy for all agent frameworks. Fetch it programmatically from the GET /api/v1/policy/default endpoint.
The default policy blocks every breaking change — field or endpoint removal, type changes, enum narrowing, and newly required fields — and flags everything else for review. Each endpoint returns the same decision shape, so one check works across every framework.
Zero-config guard decorator
One framework-agnostic decorator wraps any tool function — a LangGraph node, an AutoGen tool, a CrewAI tool, or a LangChain @tool. It calls the public preflight endpoint (no API key) and halts the call when the decision is BLOCK. It ships as a single zero-dependency file, coderifts_decorator.py, that you copy from the example repo.
Wrap any tool function
from coderifts_decorator import coderifts_guard
@coderifts_guard(old_spec, new_spec) # halts on BLOCK
def call_order_api(order_id):
# runs only if the change is safe for agents
return requests.get(f"https://your-api.com/orders/{order_id}").json()
Human-in-the-loop: also halt on REQUIRE_APPROVAL
@coderifts_guard(old_spec, new_spec, strict=True)
def call_order_api(order_id):
...
Runnable LangGraph and LangChain examples, verified end-to-end, live in the example-langgraph-guard repo.
MCP Integration
For agents that support the Model Context Protocol (Claude Desktop, Cursor, Windsurf), CodeRifts exposes governance tools directly via MCP — no SDK required.
View MCP Integration