AgentWatch SDK — AI agent governance, audit, and policy enforcement
Project description
AgentWatch SDK
The official Python SDK for AgentWatch — AI agent governance, audit logging, and real-time policy enforcement.
Every tool call your AI agent makes is recorded, checked against your policies, and visible in the AgentWatch dashboard. If a policy blocks an action, the SDK stops execution before it happens.
Installation
pip install agentwatch
With framework integrations:
pip install agentwatch[langchain] # LangChain
pip install agentwatch[openai] # OpenAI
Quickstart
1. Register your agent
Log into the AgentWatch dashboard → Agents → Register Agent. Copy the agent UUID that gets generated.
2. Pick your integration style
Option A — Decorator (recommended)
Set up once at startup. Every decorated function is automatically logged and policy-checked before it runs.
import agentwatch
agentwatch.configure(
agent_id="your-agent-uuid",
human_owner="alice@yourcompany.com",
api_url="https://your-agentwatch.com/api/v1",
)
@agentwatch.monitor(target_system="crm")
def read_customer(customer_id: str) -> dict:
return crm.get(customer_id)
@agentwatch.monitor(target_system="email")
def send_followup(to: str, body: str):
email.send(to=to, body=body)
If a policy blocks the action, BlockedByPolicy is raised before the function body executes.
Option B — Explicit client
Full control over every event. Useful when you need to inspect the policy result before deciding what to do.
from agentwatch import AgentWatch, BlockedByPolicy
with AgentWatch(
agent_id="your-agent-uuid",
human_owner="alice@yourcompany.com",
api_url="https://your-agentwatch.com/api/v1",
) as sdk:
result = sdk.record_event(
action_type="read_crm",
target_system="crm",
input_summary=f"read record {customer_id}",
output_summary=str(record),
)
if sdk.is_blocked(result):
raise RuntimeError(f"Blocked: {result['violations']}")
Option C — LangChain
Pass the callback handler once. Every tool call in your agent loop is captured automatically.
from langchain_anthropic import ChatAnthropic
from agentwatch.integrations.langchain import AgentWatchCallbackHandler
handler = AgentWatchCallbackHandler(
agent_id="your-agent-uuid",
human_owner="alice@yourcompany.com",
api_url="https://your-agentwatch.com/api/v1",
)
llm = ChatAnthropic(model="claude-sonnet-4-6", callbacks=[handler])
# Nothing else changes in your agent code.
Option D — OpenAI
Wrap the client once. All tool calls in model responses are recorded before your code acts on them.
import openai
from agentwatch.integrations.openai import wrap_openai
client = wrap_openai(
openai.OpenAI(),
agent_id="your-agent-uuid",
human_owner="alice@yourcompany.com",
api_url="https://your-agentwatch.com/api/v1",
)
# Use client exactly as before.
response = client.chat.completions.create(
model="gpt-4o",
tools=[...],
messages=[...],
)
Configuration
agentwatch.configure()
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
agent_id |
str | Yes | — | UUID from the AgentWatch dashboard |
human_owner |
str | Yes | — | Email of the person responsible for this agent |
api_url |
str | No | http://localhost:8000/api/v1 |
URL of your AgentWatch backend |
agent_name |
str | No | None | Display name (overrides dashboard name) |
silent |
bool | No | False | Suppress console output |
AgentWatch()
Same parameters as configure(), plus:
| Parameter | Type | Default | Description |
|---|---|---|---|
session_id |
str | auto-generated UUID | Group related events into a session |
raise_on_block |
bool | False | Raise BlockedByPolicy automatically instead of returning a dict |
@agentwatch.monitor()
| Parameter | Type | Default | Description |
|---|---|---|---|
action_type |
str | function name | Override the logged action name |
target_system |
str | "unknown" |
The system being accessed (e.g. "crm", "email") |
permission_scope |
list[str] | None | Permission tags to attach to the event |
Handling blocked actions
from agentwatch import AgentWatch, BlockedByPolicy
sdk = AgentWatch(agent_id="...", human_owner="...", raise_on_block=True)
try:
sdk.record_event("delete_record", "crm", "delete C-1001", "")
except BlockedByPolicy as e:
print(f"Blocked by: {e.violations}") # ['tool_denylist']
Or check manually:
sdk = AgentWatch(agent_id="...", human_owner="...")
result = sdk.record_event(...)
if sdk.is_blocked(result):
# result["violations"] contains the list of matched policy names
return {"error": "Action not permitted"}
Session management
Each AgentWatch instance holds a session ID that groups events together in the audit log. To start a new session for a new task run without creating a whole new client:
sdk = AgentWatch(agent_id="...", human_owner="...")
# First task
run_task(sdk, task="Look up account C-1001")
# New session for next task
sdk = sdk.new_session()
run_task(sdk, task="Send follow-up emails")
Fault tolerance
AgentWatch is designed to never be a point of failure. If the AgentWatch backend is unreachable, record_event logs a warning and returns {"policy_status": "compliant"} so your agent continues uninterrupted.
# This will never raise even if AgentWatch is down
result = sdk.record_event(...) # returns safe default if server unreachable
What shows up in the dashboard
Every record_event call creates one row in the audit log with:
- Agent name and session ID
- Action type and target system
- Input and output summaries
- Policy status (compliant / flagged / blocked)
- Which policies were violated (if any)
- Timestamp
Flagged and blocked events generate alerts. Unusual patterns trigger anomaly detection with AI-generated explanations.
Requirements
- Python 3.9+
httpx >= 0.27- LangChain integration:
langchain-core >= 0.1 - OpenAI integration:
openai >= 1.0
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cogniify_agentwatch-0.1.1.tar.gz.
File metadata
- Download URL: cogniify_agentwatch-0.1.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a5c0cb8f56343e0fcc7d3498c7b9c8418bce97247aa4edb9909770f4adfc4e
|
|
| MD5 |
572325cefdf77cef63dc7f9cc6e351c9
|
|
| BLAKE2b-256 |
d143f2bc0d6d4e6c348ad22ced5c0c71c24b9dcc675ddb3c37f7d2630493d6b1
|
File details
Details for the file cogniify_agentwatch-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cogniify_agentwatch-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30aa03fbe9dba002c15d593e32315b76d0f8aec97fa7668d8670228bc0d3f9d1
|
|
| MD5 |
3c8da1f55ddd606d7603ef9d5ce9a236
|
|
| BLAKE2b-256 |
b58dd027af26b1132ee1e1e4e298bef2b72972c7ae613a521a47e9c0fe571551
|