watchlight-agent-sdk
Build governed AI agents. The Watchlight Agent SDK lets you put a real, fail-closed authorization decision in front of every action your agent takes — and record what happened — with the same code whether you run it on your laptop or across a production fleet.
pip install watchlight-agent-sdk
Import it as watchlight_core.
What it does
Your agent asks "may I do this?" before it acts; Watchlight answers Allow or
Deny by evaluating your policies, and the action only runs if it's permitted.
The SDK gives you:
- Authorization —
authorize_action(action, resource)gates every step, fail-closed. - Preflight — a cheap read-only "would this be allowed?" check.
- Lifecycle — a
RunHandleper agent run: submit a plan, authorize steps, complete or terminate. - Lineage — canonical, value-free execution events for audit and debugging.
- Framework plugins — ready-made integrations for LangGraph, Google ADK, AWS Bedrock, Microsoft Agent Framework, Pydantic AI, and more.
The SDK is glue: it shapes a request, hands it to a Watchlight backend, and projects the answer. Every decision is made by the backend — never in this package — which is why it's open source (Apache-2.0).
Two backends, same code
The SDK talks to a backend through one small interface, so the exact same agent and plugin code runs against either:
| Backend | Runs | |
|---|---|---|
| Developer Edition | InProcessClient |
The compiled engine, in-process — no server, no network |
| Enterprise | ApdpClient |
The governed control plane — signed lineage, drift detection, fleet-wide governance |
| Enterprise, through the connector | SidecarBackend |
The same control plane, reached through the Watchlight connector (wl-sidecar) on the same host or pod |
Moving from one to the other is a one-line change, never a rewrite.
Choosing a backend
select_backend() picks the backend for a plugin. The rules are short, and
the SDK never falls back quietly from one backend to another:
- If you pass a backend explicitly (
select_backend(my_backend)), that backend is used. - Otherwise, if
WATCHLIGHT_BACKEND=sidecaror any Enterprise variable is set, the SDK usesSidecarBackendand requires the connector. The Enterprise variables are every endpoint, credential, run-grant, TLS and connector setting the plugins read, such asWATCHLIGHT_APDP_URL,WATCHLIGHT_PROXY_URL,WATCHLIGHT_PLUGIN_TOKEN,WATCHLIGHT_CREDENTIAL_FILE,WATCHLIGHT_RUN_CREDENTIAL,WATCHLIGHT_APDP_MTLS_CERT_PATHandWATCHLIGHT_SIDECAR_SOCKET; the full list iswatchlight_core.sidecar_backend.ENTERPRISE_ENV_VARS. If the connector is not running or cannot be reached, the run is refused withGovernanceUnavailable. - Otherwise the SDK uses the Developer Edition backend,
InProcessClient.
WATCHLIGHT_BACKEND accepts sidecar or in_process. Any other value is
refused, and so is in_process together with an Enterprise variable.
How SidecarBackend reaches the connector
SidecarBackend is a thin client. The connector holds the plugin credential,
every run credential and every egress token, and talks to the control plane
itself. Your process only ever holds an opaque run reference, so no token can
end up in your heap, your logs or an exception.
You tell the SDK where the connector is; it never guesses.
- A Unix socket is the preferred way. Set
WATCHLIGHT_SIDECAR_SOCKETto the socket's absolute path. Without it, the SDK uses the connector's default path,$XDG_RUNTIME_DIR/watchlight/control.sockor/tmp/wl-<uid>/control.sock. Before connecting, the SDK checks that the socket's directory has mode 0700 and belongs to your user, that no parent directory lets another user replace it, and that the socket itself is yours. After connecting, it asks the kernel which user is on the other end and refuses any user but yours. - Loopback TCP is for platforms where a shared socket is not possible. Set
WATCHLIGHT_SIDECAR_ADDRto the connector's address as an IP literal and a port, such as127.0.0.1:41000or[::1]:41000(host names such aslocalhostare refused). SetWATCHLIGHT_SIDECAR_SECRET_FILEto the path of the secret file the connector writes. The secret never goes in an environment variable or on a command line, and it never crosses the connection: the SDK and the connector prove to each other that they know it, and the SDK checks the connector's proof before it sends anything else. - A connector you launch yourself:
SidecarBackend.launch(argv)starts the connector, reads its address and secret from its standard output pipe, and keeps the secret in memory only. Once that connector exits, the backend never connects to its port again.
Every error, timeout or malformed answer from the connector is treated as a
refusal: authorize returns a Deny, and a refused sub-agent spawn raises, so
the child never runs. If the connection to the connector is lost, every run
that was open on it is treated as killed.
A request the connector does not answer within request_timeout_s (60
seconds by default) gets its fail-closed answer at that point, but a late
answer alone does not end the connection, because some connector paths are
slow on purpose: a session create that waits on the control plane, or a
lineage publish or session close that the connector retries for up to its
retry budget, which operators can raise to 300 seconds. Instead the SDK then
asks the connector for its health. If that also gets no answer within 5
seconds, the connection is dropped and its runs are treated as killed,
because a connection that has stopped answering can no longer deliver kill
signals either. A run that a timed-out create or spawn makes later is ended
as soon as its answer arrives.
Egress
await backend.fetch_egress(run) returns where the run's outbound traffic
goes: the connector's local proxy URL and the name of the header that carries
the run's marker. It does not return a CA bundle, and the SDK does not change
any trust settings. The connector inspects traffic with a CA that your
organisation issues, and you configure your clients to trust that CA in the
same way you configure any other internal CA.
Quickstart — a governed decision, zero infrastructure
Install the in-process engine alongside the SDK:
pip install watchlight-agent-sdk "watchlight-engine>=0.2.4,<0.3"
import asyncio
from watchlight_core import InProcessClient
# A Cedar policy: an agent may read, nothing else.
POLICIES = [
{"name": "reader",
"code": 'permit(principal is Agent, action == Action::"read", resource);'},
]
async def main():
gov = InProcessClient(POLICIES) # real engine decisions, in-process — no network
agent = await gov.resolve_agent("research-agent")
me = f'Agent::"{agent["id"]}"' # the principal: the agent's id, never its slug
print((await gov.authorize(me, "read", "dataset"))["decision"]) # Allow
print((await gov.authorize(me, "delete", "dataset"))["decision"]) # Deny
asyncio.run(main())
Allow
Deny
That Deny is the point: the action is refused before it runs — by the same
engine that powers the Watchlight platform, with no database and no network.
Agent-scoped policies
The principal of a governed call is the agent's id, Agent::"<agent uuid>",
never its slug. start_run("research-agent") resolves the slug to that id before
the first decision. Against wl-apdp the id is the agent's registry id. Under
InProcessClient it is the id resolve_agent returns, a UUID derived from the
slug. A policy that names the slug, principal == Agent::"research-agent", matches
neither, and neither does principal.name == "research-agent": under
InProcessClient the agent's name attribute holds the id too.
- To allow every governed agent, write
principal is Agent. It decides the same on every backend. - To scope a rule to one agent, name its id:
principal == Agent::"<agent uuid>". Read the id fromresolve_agent(in-process) or from the registry (wl-apdp). - Write a
forbidfor every principal, for exampleforbid(principal, action == Action::"delete", resource);, and narrow thepermitrules instead. Aforbidwhose principal never matches forbids nothing, so a mistyped id there allows what it was meant to stop. A mistyped id in apermitonly denies.
Govern a framework agent
Install the plugin for your framework and point it at a backend — your agent code doesn't change:
from watchlight_langgraph import WatchlightLangGraphPlugin # or -adk, -bedrock, -pydantic-ai, …
from watchlight_core import InProcessClient
plugin = WatchlightLangGraphPlugin()
plugin.apdp = InProcessClient(POLICIES) # the one line that differs from production
async with await plugin.start_run("research-agent") as handle:
if not await handle.authorize_action("read", "dataset"):
raise PermissionError("denied by policy")
# ... your agent runs, every action governed ...
Custom agents (any framework)
For an agent not built on a supported framework, the @watchlight decorator
governs any function:
from watchlight_core import InProcessClient, watchlight
gov = InProcessClient(POLICIES)
@watchlight(agent_id="custom-research", client=gov)
async def run_research(query: str) -> str:
...
Optional: OpenTelemetry export
Install the [otlp] extra to export a subset of the lineage stream to your OTel
collector (off by default):
pip install 'watchlight-agent-sdk[otlp]'
Lineage delivery and retries
Lineage events and the run's session close are retried when the server answers
429, 502, 503 (it cannot yet know the run's state) or 504, or the
connection fails. The SDK waits with exponential backoff and jitter and honours
Retry-After. A retried event is deduplicated by its event_id. A 500 and
every other 4xx are final and never retried.
| Variable | Default | Range |
|---|---|---|
WATCHLIGHT_LINEAGE_RETRY_MAX_ATTEMPTS |
6 |
1 to 20 |
WATCHLIGHT_LINEAGE_RETRY_MAX_WAIT_SECONDS |
30 (hard wall-clock bound) |
0 to 300 |
A run's events are sent in call order. Authorization is never retried or delayed by lineage. The
execution_started sent before authorize is one direct attempt that never
waits behind a retry; if it fails, authorize fails closed (an action whose
execution was never started would be dropped from lineage), and a transient
failure is also queued for background delivery. Other events emitted while a
decision is applied (execution_quarantined) get one attempt if nothing else
is being sent for the run, and are otherwise queued; such an event can land
after a batch that was being retried when it was emitted, and the lineage view
orders events by timestamp. The quarantine kill signal fires before any
lineage is sent.
When a batch runs out of budget, the SDK logs one WARNING with
reason=lineage_retry_exhausted (event types and counts, no payloads), and
the run's later events get one attempt each and are then queued, until one is
delivered. When the run ends, the SDK waits up to one budget for its queued
events. ApdpClient.lineage_delivery_counters counts retries, give-ups,
queued batches and cancelled publishes.
Learn more
- Documentation: https://docs.watchlight.ai/de
- Developer Edition (zero-infra quickstart) and Enterprise (the governed control plane): https://watchlight.ai
License
Apache-2.0.
Metadata
Release files for watchlight-agent-sdk 0.10.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| watchlight_agent_sdk-0.10.1.tar.gz | 538.1 kB | With provenance | Details for watchlight_agent_sdk-0.10.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| watchlight_agent_sdk-0.10.1-py3-none-any.whl | Python 3 | none | any | Details for watchlight_agent_sdk-0.10.1-py3-none-any.whl |
Total release size: 853.0 kB
Release files / watchlight_agent_sdk-0.10.1.tar.gz
| Download URL | watchlight_agent_sdk-0.10.1.tar.gz |
|---|---|
| Size | 538.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39c9ec9a0515c80002cba4a2233d199bfa326ea47c81e3780de06bf28d6ad850
|
|
BLAKE2b-256 checksum How to use checksums |
7a17e375d8d38b991b0d6c8816b51e42529f1034df1dc43541806935c54d5bdd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logRelease files / watchlight_agent_sdk-0.10.1-py3-none-any.whl
| Download URL | watchlight_agent_sdk-0.10.1-py3-none-any.whl |
|---|---|
| Size | 314.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
383c3dbc3a32ce619d2845173254aa30672f15d274f4120c04ff57f53a8e626f
|
|
BLAKE2b-256 checksum How to use checksums |
599b86ab9041df2ada3c96c7d8056e10d0b6a03696e793c081a4630369ba84c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logSecurity for watchlight-agent-sdk 0.10.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for watchlight_agent_sdk-0.10.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.
Transparency logA 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.