govern()
Thegovern() function is the universal one-liner entry point. Pass any supported framework object and it returns a compliance-wrapped version. It never raises — if no config is found or the framework is unrecognised, the original object is returned unchanged with a warning.
Signature
Parameters
A CrewAI
Crew, LangGraph compiled graph, or AutoGen GroupChat instance.Explicit path to a
.drako.yaml file. When omitted, govern() walks up from the current working directory looking for the file.Override automatic framework detection. Accepted values:
"crewai", "langgraph", "autogen".Returns
The compliance-wrapped object. For CrewAI this is aCrewAIComplianceMiddleware that proxies all attributes to the underlying crew. For LangGraph it is a _LangGraphProxy. For AutoGen it is a _AutoGenGroupChatProxy. In all cases the public interface of the original object is preserved.
If no .drako.yaml is found and DRAKO_API_KEY is not set in the environment, the original obj is returned unchanged.
Framework auto-detection
govern() inspects the object to determine the framework:
| Condition | Detected framework |
|---|---|
hasattr(obj, "kickoff") | crewai |
hasattr(obj, "invoke") or hasattr(obj, "stream") | langgraph |
hasattr(obj, "groupchat") | autogen |
framework is not supplied, the object is returned ungoverned.
govern() is safe to call multiple times on the same object. Each tool’s _run method carries a _drako_wrapped flag that prevents double-wrapping.Examples
- CrewAI
- LangGraph
- AutoGen
DrakoClient
DrakoClient is the async-first HTTP client that communicates with the Drako backend. All middleware wrappers create one internally, but you can instantiate it directly for programmatic access.
Constructor
Your Drako API key. Keys follow the format
am_live_<tenant>_<secret> or am_test_<tenant>_<secret>. The tenant ID is extracted automatically from the key prefix when tenant_id is not provided.Base URL of the Drako API.
Tenant identifier. Derived from the API key prefix when omitted.
Class methods
DrakoClient.from_config(config_path)
DrakoClient.from_config(config_path)
DrakoClient.from_env()
DrakoClient.from_env()
Instantiate from environment variables. Reads Raises
DRAKO_API_KEY, DRAKO_ENDPOINT, and DRAKO_TENANT_ID.AuthenticationError if DRAKO_API_KEY is not set.Key methods
All async methods have_sync counterparts for use in synchronous code.
verify_agent_identity / verify_agent_identity_sync
verify_agent_identity / verify_agent_identity_sync
Register or verify an agent and return its decentralised identifier (DID) and trust score.Returns a
Display name of the agent.
Role or job description of the agent.
Optional key/value metadata attached to the registration.
dict with at minimum did (string) and trust_score (float).evaluate_policy / evaluate_policy_sync
evaluate_policy / evaluate_policy_sync
Evaluate whether an action is permitted by the tenant’s policies.Returns a
Human-readable action label, e.g.
"tool:web_search".DID returned by
verify_agent_identity.Optional context dict. Recognised keys:
task_id, tool_name, scope, payload_preview.dict containing decision ("allowed", "rejected", "PENDING_APPROVAL", or "escalated").audit_log / audit_log_sync
audit_log / audit_log_sync
verify_chain / verify_chain_sync
verify_chain / verify_chain_sync
Verify the integrity of the audit hash chain.
Verify only the last
n entries. Verifies the entire chain when omitted.check_quota / check_quota_sync
check_quota / check_quota_sync
Return the tenant’s current usage quota and subscription status.
validate_key / validate_key_sync
validate_key / validate_key_sync
Validate the API key and return tenant info.
Context manager (async)
DrakoClient implements the async context manager protocol and closes underlying HTTP connections on exit.
HTTP behaviour
- Timeout: 30 seconds per request.
- Retries: up to 3 attempts with exponential back-off (1 s, 2 s, 4 s) on
ConnectError,ReadTimeout, andWriteTimeout. - Separate connection pools for async (
httpx.AsyncClient) and sync (httpx.Client) code paths.
DrakoConfig
DrakoConfig is the Pydantic model that represents a .drako.yaml file. Load it with DrakoConfig.load().
Loading
DrakoConfig.load() supports template inheritance via the extends field (e.g. extends: fintech).
Key fields
Config schema version.
Your Drako tenant identifier.
Name of the environment variable that holds the API key.
API key stored directly in the YAML file. The environment variable set by
api_key_env takes precedence.Drako API endpoint URL.
Preset governance profile:
autopilot, balanced, strict, or custom.Framework hint stored in the config file.
Action when the Drako backend cannot be reached:
"allow" (fail-open) or "block" (fail-closed).Human-in-the-loop mode:
"off", "audit", or "enforce". Requires Pro plan.Minutes to wait for a HITL approval decision before applying
timeout_action.Action taken when the HITL approval window expires:
"reject" or "allow".Data loss prevention mode:
"audit", "enforce", or "off".Whether to write audit log entries.
Exceptions
All exceptions live indrako.exceptions and are re-exported from drako.
DrakoAPIError
Base class for all errors returned by the Drako API.HTTP status code from the API response.
Human-readable error message.
Value of the
X-Request-ID response header, useful for support.AuthenticationError
Raised on HTTP401. Indicates an invalid or expired API key.
PolicyViolationError
Raised on HTTP403. The requested action was blocked by a governance policy.
Identifier of the policy that blocked the action, when available.
QuotaExceededError
Raised on HTTP429. The tenant has exceeded its usage quota.