Skip to main content

A plug-and-play SDK to capture and audit tool calls in Agentic AI applications

Project description

Governance SDK

A lightweight, non-blocking, plug-and-play Python SDK to automatically intercept, evaluate, and authorize tool calls in LangChain, LangGraph, and CrewAI agentic applications.


Features

  • Multi-Framework Auto-Interception: Automatically intercepts tool calls in LangChain, LangGraph, and CrewAI (by hooking base tool run/arun methods) with zero configuration.
  • Zero-Touch Automatic Context Capture: Walks up the Python execution stack frames to auto-resolve active context details such as session_id, agent_name, purpose, and trace_id by inspecting local variables. No manual wrapping required!
  • Three-Tier Governance Workflow: Evaluates risk and routes tool execution decisions:
    • allow: Automatically executes the tool.
    • preview_and_confirmation: Triggers an interactive CLI prompt to confirm execution.
    • needs_full_review: Triggers an interactive CLI prompt indicating full review is required.
  • Local Policy Fallback Engine: If the remote governance server is unreachable, the SDK falls back to a deterministic rules-based local safety scanner (detecting destructive commands, SQL injections, credentials, and sensitive file paths) to dynamically decide whether to allow, preview, or block the action.
  • Exception-Based Control: If a developer/user denies an execution prompt, the SDK raises PermissionDeniedError or ReviewRequiredError, letting the calling application abort or handle it gracefully.
  • Non-Blocking Asynchronous Auditing: Completed tool logs are queued in-memory and batch-shipped to the Governance Server asynchronously by a background worker thread.

Installation

Install the package via pip:

pip install governance-sdk

Quickstart

Initialize the SDK at the entry point of your agentic application.

1. SDK Initialization

api_key is the only required parameter to be passed to init(). All other settings (including the server URL) are pre-configured with secure autonomous defaults.

import governance_sdk

# Only api_key is required
governance_sdk.init(
    api_key="your_api_key",
    project_name="my-agent-project"  # Optional
)

Alternatively, you can load the key from the environment variable:

export GOVERNANCE_API_KEY="your_api_key"

And initialize by passing the environment value:

import os
import governance_sdk

governance_sdk.init(api_key=os.environ.get("GOVERNANCE_API_KEY"))

2. Auto-Interception & Context Capture

Once init() is called, any tool executed by your agent in LangChain, LangGraph, or CrewAI will be automatically intercepted:

from langchain_core.tools import tool

@tool
def delete_user_data(user_id: str) -> str:
    """Deletes sensitive user information."""
    return f"User {user_id} deleted."

# In your agent logic:
# When this tool is called, the SDK automatically walks the stack to extract:
# - session_id (resolves from variables named session_id, sid, session, etc.)
# - agent_name (resolves from class name or variable agent_name)
# - purpose (resolves from variables named purpose, intent, reason, etc.)
# Then it verifies the risk score on the server side.
delete_user_data.run({"user_id": "usr_992"})

3. Explicit Context Override (Optional)

If you want to manually specify context instead of relying on the auto-captured stack frames, use the agent_context manager:

import governance_sdk

with governance_sdk.agent_context(agent_name="Supervisor-Agent", session_id="session_override_123", purpose="cleanup"):
    # All tool calls executed inside this block will prioritize these values
    agent.run("delete temporary files")

Captured Payload Format

The JSON payload sent to the governance logging server has the following structure:

{
  "project_name": "customer-support-agent",
  "tool_calls": [
    {
      "tool_name": "delete_user_data",
      "tool_description": "Deletes sensitive user information.",
      "arguments": { "user_id": "usr_992" },
      "output": "User usr_992 deleted.",
      "error": null,
      "status": "success",
      "timestamp_start": "2026-07-30T13:30:00Z",
      "timestamp_end": "2026-07-30T13:30:00.045Z",
      "duration_ms": 45,
      "context": {
        "agent_name": "Supervisor-Agent",
        "session_id": "session_override_123",
        "purpose": "cleanup",
        "caller_filename": "main.py",
        "caller_line_number": 42,
        "caller_function": "execute_task"
      },
      "risk_score": 0.90,
      "risk_category": "high_risk",
      "governance_decision": "allow"
    }
  ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

governance_sdk-0.1.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

governance_sdk-0.1.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file governance_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: governance_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.7

File hashes

Hashes for governance_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7a7600d0608b6517141f6b68aef4e49ff49171ab223d63ef76d3568f775f8fed
MD5 63c83d24683c2ab56f7581dd19d24e12
BLAKE2b-256 efbe6b09bebd8b3dd9043dd842c5341b244a77b5544df254bf4d842e537f0f0e

See more details on using hashes here.

File details

Details for the file governance_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: governance_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.7

File hashes

Hashes for governance_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a51d80b88d1d8bc6c6579694c0788ae52218bea5351c1514112a0c38d56ba32
MD5 0a726a12aa717243392d6901dcd5bed4
BLAKE2b-256 0cdfd9cc382de22de0a67b9e3c2805ba2b6001624ac8e071f56e3fca3866c79c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page