Agent Framework
Integrations
Add API governance to your AI agents in minutes. Copy-paste ready examples for LangGraph, AutoGen, and CrewAI — powered by the CodeRifts 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
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.
LangGraph Guard Node
Add as a guard node before any API-calling node in your StateGraph.
from coderifts import guard
# Add to your StateGraph
builder.add_node('coderifts_guard', guard.langgraph_node)
builder.add_edge('coderifts_guard', 'your_api_node')
# If BLOCK → returns END automatically
AutoGen Wrap
Add as a pre-execution hook to your AssistantAgent.
from coderifts import guard
# Wrap your agent
agent = guard.autogen_wrap(
agent,
spec_url='https://your-api.com/openapi.json'
)
# Automatically blocks unsafe tool calls
One-line Integration
The absolute minimal code to add CodeRifts protection to each framework.
builder.add_node('coderifts_guard', guard.langgraph_node)
agent = guard.autogen_wrap(agent, spec_url='https://your-api.com/openapi.json')
tools = [guard.openai_preflight_tool()] + your_existing_tools
tools = [guard.anthropic_preflight_tool()] + your_existing_tools
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