Skip to main content

🚀 Beta: All Pro and Team features are free. Install on GitHub →

Python SDK + Agent Frameworks

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

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