Skip to content
29700bf85c0b2fcdecaf6e9437300ddf4fe8c96f

29700bf85c0b2fcdecaf6e9437300ddf4fe8c96f

github.com • November 28, 2026

Thoth SDK instruments your AI agents for governance, policy enforcement, and behavioral monitoring. Every tool call is evaluated against your organization's security policies in . under Settings → API Keys .

2. Set environment variables:

3. Supported agent frameworks: one call, no tool changes.

init() governs these frameworks, whichever are installed:

LangChain and LangGraph (including the tools LangGraph's ToolNode runs)

OpenAI Agents SDK function tools

Microsoft Agent Framework

Claude Agent SDK ( query() and ClaudeSDKClient , including tools in allowed_tools )

MCP tool calls made with mcp 's ClientSession.call_tool , directly or through a framework's MCP adapter (a call a framework already checked isn't checked twice)

The agent's observe or enforce mode is set in Thoth, not in code. Without approved_scope , keep the agent in observe until an admin confirms its tools: in enforce mode, a call with no approved scope and no risk score is held for approval. A refused LangChain tool raises ThothPolicyViolation ; in the other frameworks the model or agent gets "Thoth refused this call: ", as those frameworks report tool errors (the Claude Agent SDK denies the call with that reason). Either way the tool does not run. The OpenAI Agents SDK's local shell, computer and apply_patch tools don't run through function tools and are not covered by init() ; a result CrewAI serves from its tool cache doesn't run the tool and isn't checked again.

Other agents: instrument the agent object.

That's it. No AWS credentials, no infrastructure setup — the SDK sends events and enforcement requests over HTTPS to your tenant API URL.

What's New Since 0.1.15

If you're upgrading from 0.1.15 , these are the material integration changes:

Package publish target is now atensec-thoth (docs/examples updated accordingly).

Decision model expanded beyond ALLOW/BLOCK/STEP_UP : MODIFY : enforcer can sanitize/transform tool args before execution. DEFER : enforcer can defer execution with retry guidance.

MODIFY : enforcer can sanitize/transform tool args before execution.

DEFER : enforcer can defer execution with retry guidance.

Decision envelope context surfaced end-to-end : decision_reason_code , action_classification , authorization_decision risk_score , latency_ms , pack_id , pack_version , rule_version matched_rule_ids , matched_control_ids , regulatory_regimes , policy_references , model_signals fastml_features , score_components , top_contributors , decision_evidence , receipt

decision_reason_code , action_classification , authorization_decision

risk_score , latency_ms , pack_id , pack_version , rule_version

matched_rule_ids , matched_control_ids , regulatory_regimes , policy_references , model_signals

fastml_features , score_components , top_contributors , decision_evidence , receipt

Async tool wrappers use async enforcement path ( acheck ) and preserve sync/async behavior.

Structured tool metadata emission now includes normalized tool_call payload and result summaries.

Enforcer payload now includes richer context when provided: tool_args , environment , enforcement_trace_id session_intent , purpose , data_classification , task_context

tool_args , environment , enforcement_trace_id

session_intent , purpose , data_classification , task_context

Release automation moved to tag-driven public workflow in atensecurity/thoth-py , with release notes sourced from CHANGELOG.md .

Legacy Compatibility ( ThothClient )

thoth.instrument() , thoth.instrument_toolchain() , thoth.toolchain_function_map() , thoth.instrument_anthropic() , and thoth.instrument_openai() are the preferred APIs for new integrations.

ThothClient is still exported for backward compatibility with older examples and wrappers:

For new code, prefer the module-level APIs shown in Quick Start.

Events are batched and flushed to the Aten ingest API in a background daemon thread with at-most-10 per batch. If the enforcer is unreachable, Thoth fails closed (BLOCK) and logs a warning. Tool execution is prevented until policy checks are reachable again.

LangChain AgentExecutor

Thoth detects AgentExecutor automatically and wraps both tool.run and tool._run :

thoth.init() (see Quick Start) governs a LangGraph agent's tools with no other code. To govern one graph explicitly instead, use thoth.instrument_langgraph(graph, ...) . The low-level API below wraps each tool callable with Tracer.wrap_tool :

See examples/langgraph_example.py for the full working script.

Claude Agent SDK ( query )

For claude-agent-sdk , instrument ClaudeAgentOptions instead of a .tools list. Thoth adds a PreToolUse hook that checks every tool call before it runs, including tools in allowed_tools (which the SDK never passes to can_use_tool ), plus tool lifecycle hooks. When Thoth allows a call, the SDK's own permission rules and your can_use_tool still decide; a refused call is denied with Thoth's reason, and a call whose arguments Thoth would change is denied.

See examples/claude_agent_sdk_example.py for the full working script.

Use instrument_anthropic() to wrap tool functions for the Anthropic agentic loop:

See examples/anthropic_example.py for the full working script.

OpenAI Function Calling

Use instrument_openai() to wrap tool functions for the OpenAI tool-calling loop:

See examples/openai_example.py for the full working script.

thoth.instrument() detects CrewAI Agent objects automatically:

See examples/crewai_example.py for the full working script.

For AG2 1.x, call thoth.init() at startup: every function tool an AG2 Agent runs is checked with the arguments it runs with, after the tool's and the agent's tool middleware, and a refused call never runs.

For the AutoGen 0.2 API, which AG2 0.x kept ( pip install "ag2 , and logs the message once per process. fail_open does not apply: it covers outages, not billing.

Step-Up Authentication

When the enforcer returns STEP_UP , Thoth automatically:

Sends an approval request to the configured notification channel (Slack by default).

Polls /v1/enforce/hold/{hold_token} every step_up_poll_interval_seconds (default: 5s).

If approved within step_up_timeout_minutes (default: 15 minutes) → tool executes.

If timed out → raises ThothPolicyViolation with reason "step-up auth timeout" .

If the response has no hold token, or approval remains unresolved after polling, the SDK raises ThothPolicyViolation and does not execute the tool. This applies to both synchronous and asynchronous wrapped tools. The Claude Agent SDK adapter returns a permission denial for the same conditions.

The Claude adapter carries the provider's tool-use ID through authorization and tool lifecycle events, unless action_attestation_id is explicitly configured. These IDs correlate events; they do not establish authenticated workload identity. When a lifecycle hook has neither ID, it omits the action ID rather than guessing which concurrent call it belongs to.

Configure timeouts via ThothConfig :

Each instrument() call creates a SessionContext stored in a contextvars.ContextVar . Inspect it from anywhere in the same async context:

Withholding Values From Thoth

Or set the environment, which every entry point reads ( init() , instrument*() , ThothConfig ):

An invalid value raises when the client is created. The SDK never falls back to sending the raw value.

hash : keys and structure are kept, and each value (string, number, boolean) becomes hmac-sha256: , an HMAC-SHA256 keyed with your salt. null stays null .

redact : keys and structure are kept, and each value becomes " " .

drop : no arguments are sent.

Nested arguments are walked to depth 16 and 5,000 values. Anything beyond that becomes " " .

Prompts. The SDK has no prompt field of its own. The mode applies to the context you pass in task_context , auth_context , delegation_context , identity_binding and request_metadata :

Values under prompt-bearing key names ( prompt , message(s) , input , query , question , text , content , instruction(s) , task , goal , description , summary , note(s) , , conversation , history , transcript , completion , response , output , tool_result , tool_output , at any depth, ignoring case, _ and - ) are hashed or omitted.

Any other string longer than 512 characters in those dicts is treated as free text: hashed in hash mode, replaced by " " in drop mode.

Everything else (ids, initiated_by , task_id , delegation chains) is kept, because policy reads it.

session_intent , purpose and data_classification are labels you set, not user text, so they are sent as given. Do not put user text in them.

The salt. Hashing uses a salt that only your process holds; Thoth has no key to it. Equal values produce equal hashes only under the same salt. With the default random salt that means within one process, which is enough to see that a value repeated in a session but not across restarts or workers. Set the same THOTH_DATA_HANDLING_SALT on every process that should match values. Anyone who has the salt can confirm a guess at a low-entropy value (a short code, a name), so keep it secret.

Local scanning. So checks that need values can still run, the SDK scans the raw arguments in your process before withholding them (and the destination host in request_metadata ), and sends the result as client_findings to data_handling :

It reports counts and categories (credentials, email addresses, phone numbers, SSN-shaped numbers, confidentiality phrases), whether a path or paths value looks sensitive, a destination hostname, and recipient domains. It never reports values, paths, the local part of an address, display names or message text.

The detectors are heuristic regular expressions from a versioned spec ( thoth-detectors.v1 ). A finding is a signal, not proof that data is sensitive, and no finding is not proof that it is not.

The report names its ruleset hash. Thoth cannot verify a client scan: a workspace relies on it only after the owner sets accept_local_scan and lists the hash in accepted_scanner_ruleset_hashes (this release sends 9e7e25ec9d1f280b12f6006726cfc9efdaf5a0dc24585b08eb513e140ff3ae46 ; the changelog lists the hash for each release). Findings only ever raise a decision.

A check that cannot finish (an error, arguments deeper than 16 levels or beyond 5,000 values for dlp and recipient , non-ASCII text in recipient fields that engines read differently, a report over 4 KB) is left out of scanned , so Thoth sees it as missing, not clean.

A workspace with require_client_findings holds every call from a client that withholds arguments and sends no findings. If your workspace turns that on, keep local scanning on.

It is on whenever tool arguments are withheld. Set THOTH_DATA_HANDLING_LOCAL_SCAN=off (or data_handling_local_scan=False on ThothConfig ) to send no findings. With only data_handling_prompts set, arguments are sent as before and nothing is scanned.

What still reaches Thoth. Tool names, decisions, session and user ids, timing, and the tool-call sequence. Key names are sent in hash and redact mode, and not in drop . With local scanning on, also the findings above: counts, categories, a destination hostname and recipient domains. The SDK declares what it applied, and Thoth records that declaration with the decision.

What you give up. Rules that read argument values ( arg.path contains ... , regex, free-text keywords) and outbound data checks cannot run on values Thoth does not have. When such a rule exists, the call is held ( STEP_UP with reason code args_withheld ) instead of being decided on values it cannot see, and the ThothPolicyViolation message says so. With drop , some checks fall back on tool-name heuristics. A server never returns modified arguments for a call whose arguments were withheld; if one ever does, the SDK fails closed: the tool does not run and a ThothPolicyViolation says the server returned an argument rewrite although arguments were withheld, which points to a server or contract problem.

Configuration Reference

instrument() parameters

approved_scope clarifier:

This field is an allow-list, not a natural-language description field.

Entries must match emitted tool names exactly (for example search_docs or data_sources.cloudtrail ).

Tool meaning/context should be expressed through your tool schemas/prompts and policy context fields ( session_intent , purpose , data_classification , task_context ), which are sent to the enforcer.

instrument_toolchain() uses the same governance parameters plus:

Environment Variables

Resolution precedence:

THOTH_API_URL overrides api_url .

View sessions, violations, step-up requests, and policy decisions in your Thoth dashboard at https:// . .

Sessions — per-agent session timelines with all tool calls

Violations — blocked or escalated actions with full context

Approvals — step-up queue for human reviewers

Policies — view and edit the rules driving enforcement decisions

Behavioral Analytics — drift detection and anomaly scores over time

The full story

This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.