Skip to main content

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


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

Metadata

Release files for cogniify-agentwatch 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cogniify-agentwatch 0.1.1
File Size Uploaded Provenance Actions
cogniify_agentwatch-0.1.1.tar.gz 8.4 kB Without provenance Details for cogniify_agentwatch-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cogniify-agentwatch 0.1.1
File Interpreter ABI Platform Actions
cogniify_agentwatch-0.1.1-py3-none-any.whl Python 3 none any Details for cogniify_agentwatch-0.1.1-py3-none-any.whl

Total release size: 19.7 kB

Release files / cogniify_agentwatch-0.1.1.tar.gz

Download URL cogniify_agentwatch-0.1.1.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e8a5c0cb8f56343e0fcc7d3498c7b9c8418bce97247aa4edb9909770f4adfc4e
BLAKE2b-256 checksum
How to use checksums
d143f2bc0d6d4e6c348ad22ced5c0c71c24b9dcc675ddb3c37f7d2630493d6b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / cogniify_agentwatch-0.1.1-py3-none-any.whl

Download URL cogniify_agentwatch-0.1.1-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30aa03fbe9dba002c15d593e32315b76d0f8aec97fa7668d8670228bc0d3f9d1
BLAKE2b-256 checksum
How to use checksums
b58dd027af26b1132ee1e1e4e298bef2b72972c7ae613a521a47e9c0fe571551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for cogniify-agentwatch 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page