watchlight-deepagents 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Watchlight AI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ # The sdist ships the package, README.md, LICENSE and pyproject.toml, and
2
+ # nothing else: the tests and CI files stay in the repository.
3
+ # CI fails a build that ships anything more.
4
+ prune tests
5
+ prune ci
6
+ global-exclude *.py[cod]
@@ -0,0 +1,176 @@
1
+ Metadata-Version: 2.4
2
+ Name: watchlight-deepagents
3
+ Version: 0.1.2
4
+ Summary: Watchlight governance middleware for DeepAgents agents: authorize every tool and filesystem call and gate sub-agent spawns, fail-closed. Model turns are not authorized one by one. Independent plugin, not affiliated with or endorsed by LangChain.
5
+ Author-email: Watchlight AI <team@watchlight.ai>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://watchlight.ai
8
+ Project-URL: Documentation, https://docs.watchlight.ai/de
9
+ Project-URL: Repository, https://github.com/watchlight-ai-beacon/watchlight-de
10
+ Project-URL: Issues, https://github.com/watchlight-ai-beacon/watchlight-de/issues
11
+ Project-URL: DeepAgents, https://github.com/langchain-ai/deepagents
12
+ Keywords: watchlight,deepagents,langchain,ai-agents,ai-governance,agent-runtime
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: watchlight-agent-sdk<0.12,>=0.11.0
25
+ Requires-Dist: deepagents<0.8,>=0.7
26
+ Provides-Extra: otlp
27
+ Requires-Dist: watchlight-agent-sdk[otlp]<0.12,>=0.11.0; extra == "otlp"
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7; extra == "dev"
30
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
31
+ Requires-Dist: mypy>=1.8; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # watchlight-deepagents
35
+
36
+ Watchlight authorization for DeepAgents tool calls and sub-agent spawns, fail-closed.
37
+
38
+ `watchlight-deepagents` puts a Watchlight authorization decision in front of the tool calls, virtual-filesystem calls and `task` sub-agent spawns your DeepAgents agent makes, so each one is allowed or denied *before* it runs. It is a governance middleware plus a drop-in `create_governed_deep_agent(...)` factory, built on the DeepAgents `AgentMiddleware` protocol, with no monkey-patching and no changes to your tool code. The decisions are made by the Developer Edition engine inside your process, or by Watchlight Beacon (Enterprise).
39
+
40
+ > **Independent third-party plugin.** This is an independent integration built by Watchlight AI. It is **not affiliated with, endorsed by, or sponsored by** LangChain. `deepagents`, `LangChain`, `LangGraph`, and related names are trademarks of LangChain, used here nominatively only to describe compatibility.
41
+
42
+ ## Install
43
+
44
+ ```bash
45
+ pip install watchlight-deepagents "watchlight-engine>=0.2.5,<0.3"
46
+ ```
47
+
48
+ `watchlight-engine` is the compiled Developer Edition engine that `InProcessClient` uses. The plugin needs Python 3.11 or later, `deepagents` 0.7 and `watchlight-agent-sdk` 0.11; `pip` installs both with it. CI tests it on Python 3.12 and 3.13.
49
+
50
+ ## Quickstart
51
+
52
+ Swap `create_deep_agent` for `create_governed_deep_agent`, name the agent with `agent_slug`, and give the plugin a backend. Your tool code, sub-agent prompts and the model loop do not change.
53
+
54
+ ```python
55
+ from watchlight_core import InProcessClient
56
+ from watchlight_deepagents import WatchlightDeepAgentsPlugin, create_governed_deep_agent
57
+
58
+ # The principal is the id of the agent. `principal.name` is its registered name (with InProcessClient, the slug it is started with).
59
+ POLICIES = [{"name": "reader", "code": 'permit(principal is Agent, action == Action::"read", resource) when { principal.name == "research-orchestrator" };'}]
60
+ plugin = WatchlightDeepAgentsPlugin(governance=InProcessClient(POLICIES)) # decisions are made in-process, with no network
61
+
62
+ agent = create_governed_deep_agent(model=model, tools=[search_web, send_email], agent_slug="research-orchestrator", plugin=plugin)
63
+ result = await agent.ainvoke({"messages": [{"role": "user", "content": "Find the Q3 filings and email them."}]})
64
+ ```
65
+
66
+ Here `model` is your LangChain chat model and `search_web` and `send_email` are your own tools. The policy lets the research agent read and nothing else, so a `search_web` call runs and a `send_email` call is refused: the model gets an error message in place of the tool's result, and the tool never runs. DeepAgents runs on the async LangGraph runtime, so invoke the agent with `await`. The quickstart also writes the run's events to `.watchlight/audit.jsonl` in the current directory: the run's start and completion, one event per model call (it names the model; the plugin sees the call and not an HTTP request, so the event's `method` and `path` are empty, and a model call that was refused carries `response_status` 403), and one event per tool call with its decision (Allow or Deny).
67
+
68
+ ## What is and is not enforced
69
+
70
+ Enforced:
71
+
72
+ - **Run start.** Every agent run opens a governed Watchlight run before the model loop starts. If the run cannot be opened (unregistered agent, unreachable backend), the agent does not run.
73
+ - **Tool and filesystem calls.** Each call is authorized by Watchlight first. A denial, a required approval, or an unreachable backend returns an error to the model and the tool never runs. Only argument names, count and types are sent with the request, never argument values.
74
+ - **Sub-agent spawns (`task`).** A spawn opens an attenuated child run under the parent, gated by Watchlight. If the spawn is refused, the sub-agent never runs. The sub-agent runs only on the handle its own spawn produced, and only while that `task` call is running; it never reuses another sub-agent's handle. Spawns are refused unless the agent was built with `create_governed_deep_agent(...)`, which installs governance in every sub-agent.
75
+ - **Egress.** When a Watchlight proxy URL is configured (`connect_proxy_url` or `WATCHLIGHT_PROXY_URL`), the run is refused with `GovernanceUnavailable` if Watchlight issued no proxy token or the local sidecar fails to start. It never falls back to direct egress. **One governed run per process.** While a run owns the egress proxy, starting another run in the same process raises `SidecarRunActive` (a `GovernanceUnavailable`) and leaves the running one as it is. The owning run releases it when it ends, or when its session expires (`ttl_seconds`, 3600 by default) if it is never completed. Once the owner has ended, its sidecar is stopped and `HTTPS_PROXY` stays on the stopped port, so traffic fails rather than going direct. Run concurrent governed runs in separate processes.
76
+ - **Async only.** DeepAgents runs on the async LangGraph runtime. The synchronous invocation path is refused.
77
+ - **A governed agent started inside a live run does not open a root of its own.**
78
+ - While a governed run is live in the process, another `create_governed_deep_agent(...)` agent that would start a root outside it is refused with `NestedRunEscapedError` (a `WatchlightError`) before its first model turn. This covers an agent built and invoked inside a tool (awaited directly, or from an executor, a thread pool, a `threading.Thread`, a fresh `contextvars.Context`, or a deferred start after the tool returned) and two undeclared roots started at once.
79
+ - Without this, it would run with none of its parent's attenuation and no link to its lineage. Run sub-agents through `task` instead.
80
+ - Independent roots that run at the same time are declared with `root_run()` (from `watchlight_deepagents`), a context manager (sync or async) and a decorator:
81
+
82
+ ```python
83
+ async with root_run():
84
+ await agent.ainvoke({"messages": [...]})
85
+ ```
86
+
87
+ - The server decides `Action::"open_declared_root"` with the root execution ids live in the process, and records the declaration. A refusal raises `DeclaredRootRefused`. A server that does not confirm the declaration (an older server) gets its session closed, and the run is refused (`declared_root_unsupported`).
88
+ - `root_run()` is refused inside a live run, including a tool body.
89
+ - An agent whose `task` spawn was refused cannot start through `root_run()` while that run tree is live (`SpawnRefusedRootRunError`).
90
+ - With no governed run live, a run opens as before. There is no setting that turns this off.
91
+ - **Ungoverned agents built inside a tool are refused.** An agent that one of your tools builds and runs itself, such as a plain `create_deep_agent(...)` called inside a tool, has no Watchlight middleware. (A governed one is covered by the previous item.) While a governed run is live in the process, the plugin refuses such an agent's work before it runs, whatever thread, config or callbacks it is given:
92
+ - Each tool call the plugin authorizes may start exactly one tool: the one with that call's id and name, once. Any other tool start is refused before the tool runs.
93
+ - A model call made inside the body of a governed tool is refused. If a tool really needs to call a model directly, for example to summarize text, wrap that call in `with direct_model_use():` (from `watchlight_deepagents`). A model call that binds tools is refused even then, so the escape never covers an agent's turn.
94
+ - A model call that binds tools, local or hosted by the provider, is refused unless it is a governed agent's own turn. Hosted tools run on the provider's side, where no tool start is visible, so this is where they are stopped.
95
+ - Each refusal is recorded in the run's lineage as a denied call, with names only and never argument values.
96
+
97
+ This is a change in behaviour: a tool that used to run an inner agent, or call a model directly, now fails with `UngovernedModelCall` or `UngovernedToolCall` (both are `GovernanceUnavailable`). Spawn sub-agents through `task` with `create_governed_deep_agent(...)`, which governs them, or use `direct_model_use()` for a direct, tool-less model call. Governed `task` sub-agents and DeepAgents' own summarization are not affected. With no governed run live, nothing is refused.
98
+
99
+ The check is a callback the plugin registers once with LangChain, through LangChain's public configure hook; no framework class is patched. It has limits:
100
+ - The live-run state is shared by the whole process. While a governed run is live, an ungoverned agent running at the same time elsewhere in the same process is refused too.
101
+ - A model call that binds no tools, made on a new thread or in a fresh `contextvars.Context` started from a tool body, is not refused. It can run no tool: its tool starts are refused, and it binds no hosted tool.
102
+ - A governed agent run inside another governed agent's ordinary tool has its own summarization refused. Run it as a `task` sub-agent instead.
103
+ - Each authorized call may start its tool once, so a retry must pass through Watchlight's middleware again. A retry middleware must sit outside Watchlight's: one that runs inside it and calls the tool again within the same call has the retry refused. `create_governed_deep_agent(...)` places Watchlight's middleware ahead of the `middleware=` you pass, so a tool-retry middleware passed there runs inside it. Retry at the model level instead, as a new tool call, which is authorized again.
104
+ - A refusal that cannot be published to lineage still stands. It is logged at warning level and counted in `watchlight_core.langchain_tool_backstop.emit_failures()`.
105
+ - Code that calls a tool's private `_run`, a model's private `_generate`, or a provider SDK directly bypasses LangChain's callbacks and is not seen. Neither is code that deliberately removes LangChain's configure hooks or resets the plugin's context variables, which turns governance off on purpose.
106
+
107
+ Not enforced:
108
+
109
+ - **Model turns are not authorized one by one.** The plugin records each model turn and refuses it when there is no governed run or when the run is quarantined. It does not send a per-turn authorization request. Governance of the model's network calls comes from the Watchlight proxy, when you configure it.
110
+ - **A policy does not see argument values.** The plugin sends argument names, count and types only. The path of a filesystem call is in the resource name (`deepagents://fs/<path>`).
111
+ - **Reporting is best-effort.** A model-turn or tool-call event that the plugin cannot publish does not stop the run.
112
+ - **The check on agents built inside a tool has limits.** They are listed with it, above.
113
+
114
+ ## Settings
115
+
116
+ `create_governed_deep_agent(...)` takes the arguments of `create_deep_agent` and these:
117
+
118
+ | Argument | What it sets |
119
+ |---|---|
120
+ | `agent_slug` | Required. The registered slug of the root agent. |
121
+ | `plugin` | The `WatchlightDeepAgentsPlugin` to use. Without it, the factory calls `WatchlightDeepAgentsPlugin.from_env()`. |
122
+ | `subagent_scopes` | For each sub-agent name, the scope its spawn asks for: `allowed_tools`, `allowed_resources`, `allowed_intents`, `max_depth` and `time_budget_seconds`. Name a tool as `deepagents://tool/<name>`. A sub-agent with no entry is spawned with no tools and `max_depth` 0. |
123
+ | `subagent_slugs` | The registered slug of each sub-agent name. The default is the sub-agent's name. |
124
+
125
+ `WatchlightDeepAgentsPlugin(...)` takes `governance=` (a backend such as `InProcessClient`), or `apdp_url=` for the Enterprise server, and reads these variables:
126
+
127
+ | Variable | What it sets |
128
+ |---|---|
129
+ | `WATCHLIGHT_APDP_URL` | Enterprise: the server URL. `from_env()` requires it and raises `GovernanceUnavailable` when it is not set. |
130
+ | `WATCHLIGHT_TENANT_ID` | Enterprise: the tenant, read by `from_env()`. |
131
+ | `WATCHLIGHT_PLUGIN_TOKEN` | Enterprise: the plugin credential. The SDK README lists the [other places a credential is read from](https://github.com/watchlight-ai-beacon/watchlight-de/blob/main/integrations/plugins/python/watchlight-core/README.md#settings). |
132
+ | `WATCHLIGHT_PROXY_URL` | The Watchlight proxy that egress goes through. The same as `connect_proxy_url=`. |
133
+ | `WATCHLIGHT_PROXY_CA_CERT` | A PEM CA bundle used to verify an `https://` Watchlight proxy. |
134
+ | `WATCHLIGHT_APPLICATION_ID` | The AI application the runs belong to. See below. |
135
+ | `WATCHLIGHT_INTENT_ENFORCEMENT_MODE` | `brownfield` (the default) or `greenfield`. The same as `intent_enforcement_mode=`. In `greenfield` the agent is given the `watchlight.declare_intent` tool. |
136
+ | `WATCHLIGHT_PLAN_GOVERNANCE_MODE` | `degrade` lets a run start when no constraint manifest could be obtained. Without it the run is refused. Use it only for development. |
137
+
138
+ ### Attributing runs to an AI application
139
+
140
+ Every governed run can be attributed to the AI application the agent belongs to. Pass `application_id="<application UUID>"` to `WatchlightDeepAgentsPlugin(...)`, or per run to `start_run(...)`, or set `WATCHLIGHT_APPLICATION_ID` in the environment (`from_env()` picks it up too). An explicit argument wins over the variable. The middleware opens runs with the plugin-level value, so a deployment attributes an agent without a code change. The server refuses the run if the agent is not a member of that application. An agent in exactly one application needs nothing here. The id is explicit configuration, never inferred from prompts or names, and a value that is not a UUID raises `ValueError`. It is an Enterprise feature: the Developer Edition engine refuses it.
141
+
142
+ ## Errors
143
+
144
+ A refused tool call is not an exception. The model gets an error tool message in place of the tool's result and the tool never runs: for a denial by policy (`Denied by Watchlight policy.`, without the backend's reason), for an action that needs approval, for a tool the sub-agent was not granted, and for a `task` spawn refused for its scope or for a sub-agent that is not registered.
145
+
146
+ The errors below are raised to your code. Branch on the error class, not on the message text.
147
+
148
+ | Error | Meaning |
149
+ |---|---|
150
+ | `GovernanceUnavailable` | A governed run could not be opened or kept: `from_env()` without `WATCHLIGHT_APDP_URL`, a backend that did not open the run, no constraint manifest, a configured Watchlight proxy that cannot be used, a synchronous `invoke`, or a sub-agent the factory cannot govern (a pre-compiled `runnable` or a remote `graph_id`). |
151
+ | `AgentNotRegistered` | The root agent's slug is not registered. |
152
+ | `SidecarRunActive` | Another run in this process owns the egress proxy. A kind of `GovernanceUnavailable`. |
153
+ | `NestedRunEscapedError` | A governed agent tried to open a root of its own while a governed run was live. `SpawnRefusedRootRunError` is the kind raised for an agent whose `task` spawn was refused. |
154
+ | `DeclaredRootRefused` | A root declared with `root_run()` was not opened. A kind of `GovernanceUnavailable`. |
155
+ | `UngovernedModelCall`, `UngovernedToolCall` | A model or tool call that no governed agent authorized was refused. Both are kinds of `GovernanceUnavailable`. |
156
+ | `AgentQuarantinedError` | The backend quarantined the run, and the agent loop stops. |
157
+
158
+ ## Moving to Watchlight Beacon (Enterprise)
159
+
160
+ The Developer Edition decides with the engine inside your process. Watchlight Beacon is the Enterprise server. Your agent code stays the same: set `WATCHLIGHT_APDP_URL`, a credential (`WATCHLIGHT_PLUGIN_TOKEN`) and, in a multi-tenant deployment, `WATCHLIGHT_TENANT_ID`, and leave out `plugin=`, so the factory builds the plugin with `WatchlightDeepAgentsPlugin.from_env()`.
161
+
162
+ What changes when you move is described once, in the SDK README: [Moving to Watchlight Beacon (Enterprise)](https://github.com/watchlight-ai-beacon/watchlight-de/blob/main/integrations/plugins/python/watchlight-core/README.md#moving-to-watchlight-beacon-enterprise).
163
+
164
+ ## Links
165
+
166
+ - Documentation: https://docs.watchlight.ai/de
167
+ - Source and issues: https://github.com/watchlight-ai-beacon/watchlight-de
168
+ - Website: https://watchlight.ai
169
+
170
+ ## License
171
+
172
+ Apache-2.0
173
+
174
+ ## Trademarks
175
+
176
+ DeepAgents, LangChain, LangGraph and other product names in this README belong to their respective owners. They are used only to describe compatibility. This plugin is not affiliated with, endorsed by or sponsored by them.
@@ -0,0 +1,143 @@
1
+ # watchlight-deepagents
2
+
3
+ Watchlight authorization for DeepAgents tool calls and sub-agent spawns, fail-closed.
4
+
5
+ `watchlight-deepagents` puts a Watchlight authorization decision in front of the tool calls, virtual-filesystem calls and `task` sub-agent spawns your DeepAgents agent makes, so each one is allowed or denied *before* it runs. It is a governance middleware plus a drop-in `create_governed_deep_agent(...)` factory, built on the DeepAgents `AgentMiddleware` protocol, with no monkey-patching and no changes to your tool code. The decisions are made by the Developer Edition engine inside your process, or by Watchlight Beacon (Enterprise).
6
+
7
+ > **Independent third-party plugin.** This is an independent integration built by Watchlight AI. It is **not affiliated with, endorsed by, or sponsored by** LangChain. `deepagents`, `LangChain`, `LangGraph`, and related names are trademarks of LangChain, used here nominatively only to describe compatibility.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install watchlight-deepagents "watchlight-engine>=0.2.5,<0.3"
13
+ ```
14
+
15
+ `watchlight-engine` is the compiled Developer Edition engine that `InProcessClient` uses. The plugin needs Python 3.11 or later, `deepagents` 0.7 and `watchlight-agent-sdk` 0.11; `pip` installs both with it. CI tests it on Python 3.12 and 3.13.
16
+
17
+ ## Quickstart
18
+
19
+ Swap `create_deep_agent` for `create_governed_deep_agent`, name the agent with `agent_slug`, and give the plugin a backend. Your tool code, sub-agent prompts and the model loop do not change.
20
+
21
+ ```python
22
+ from watchlight_core import InProcessClient
23
+ from watchlight_deepagents import WatchlightDeepAgentsPlugin, create_governed_deep_agent
24
+
25
+ # The principal is the id of the agent. `principal.name` is its registered name (with InProcessClient, the slug it is started with).
26
+ POLICIES = [{"name": "reader", "code": 'permit(principal is Agent, action == Action::"read", resource) when { principal.name == "research-orchestrator" };'}]
27
+ plugin = WatchlightDeepAgentsPlugin(governance=InProcessClient(POLICIES)) # decisions are made in-process, with no network
28
+
29
+ agent = create_governed_deep_agent(model=model, tools=[search_web, send_email], agent_slug="research-orchestrator", plugin=plugin)
30
+ result = await agent.ainvoke({"messages": [{"role": "user", "content": "Find the Q3 filings and email them."}]})
31
+ ```
32
+
33
+ Here `model` is your LangChain chat model and `search_web` and `send_email` are your own tools. The policy lets the research agent read and nothing else, so a `search_web` call runs and a `send_email` call is refused: the model gets an error message in place of the tool's result, and the tool never runs. DeepAgents runs on the async LangGraph runtime, so invoke the agent with `await`. The quickstart also writes the run's events to `.watchlight/audit.jsonl` in the current directory: the run's start and completion, one event per model call (it names the model; the plugin sees the call and not an HTTP request, so the event's `method` and `path` are empty, and a model call that was refused carries `response_status` 403), and one event per tool call with its decision (Allow or Deny).
34
+
35
+ ## What is and is not enforced
36
+
37
+ Enforced:
38
+
39
+ - **Run start.** Every agent run opens a governed Watchlight run before the model loop starts. If the run cannot be opened (unregistered agent, unreachable backend), the agent does not run.
40
+ - **Tool and filesystem calls.** Each call is authorized by Watchlight first. A denial, a required approval, or an unreachable backend returns an error to the model and the tool never runs. Only argument names, count and types are sent with the request, never argument values.
41
+ - **Sub-agent spawns (`task`).** A spawn opens an attenuated child run under the parent, gated by Watchlight. If the spawn is refused, the sub-agent never runs. The sub-agent runs only on the handle its own spawn produced, and only while that `task` call is running; it never reuses another sub-agent's handle. Spawns are refused unless the agent was built with `create_governed_deep_agent(...)`, which installs governance in every sub-agent.
42
+ - **Egress.** When a Watchlight proxy URL is configured (`connect_proxy_url` or `WATCHLIGHT_PROXY_URL`), the run is refused with `GovernanceUnavailable` if Watchlight issued no proxy token or the local sidecar fails to start. It never falls back to direct egress. **One governed run per process.** While a run owns the egress proxy, starting another run in the same process raises `SidecarRunActive` (a `GovernanceUnavailable`) and leaves the running one as it is. The owning run releases it when it ends, or when its session expires (`ttl_seconds`, 3600 by default) if it is never completed. Once the owner has ended, its sidecar is stopped and `HTTPS_PROXY` stays on the stopped port, so traffic fails rather than going direct. Run concurrent governed runs in separate processes.
43
+ - **Async only.** DeepAgents runs on the async LangGraph runtime. The synchronous invocation path is refused.
44
+ - **A governed agent started inside a live run does not open a root of its own.**
45
+ - While a governed run is live in the process, another `create_governed_deep_agent(...)` agent that would start a root outside it is refused with `NestedRunEscapedError` (a `WatchlightError`) before its first model turn. This covers an agent built and invoked inside a tool (awaited directly, or from an executor, a thread pool, a `threading.Thread`, a fresh `contextvars.Context`, or a deferred start after the tool returned) and two undeclared roots started at once.
46
+ - Without this, it would run with none of its parent's attenuation and no link to its lineage. Run sub-agents through `task` instead.
47
+ - Independent roots that run at the same time are declared with `root_run()` (from `watchlight_deepagents`), a context manager (sync or async) and a decorator:
48
+
49
+ ```python
50
+ async with root_run():
51
+ await agent.ainvoke({"messages": [...]})
52
+ ```
53
+
54
+ - The server decides `Action::"open_declared_root"` with the root execution ids live in the process, and records the declaration. A refusal raises `DeclaredRootRefused`. A server that does not confirm the declaration (an older server) gets its session closed, and the run is refused (`declared_root_unsupported`).
55
+ - `root_run()` is refused inside a live run, including a tool body.
56
+ - An agent whose `task` spawn was refused cannot start through `root_run()` while that run tree is live (`SpawnRefusedRootRunError`).
57
+ - With no governed run live, a run opens as before. There is no setting that turns this off.
58
+ - **Ungoverned agents built inside a tool are refused.** An agent that one of your tools builds and runs itself, such as a plain `create_deep_agent(...)` called inside a tool, has no Watchlight middleware. (A governed one is covered by the previous item.) While a governed run is live in the process, the plugin refuses such an agent's work before it runs, whatever thread, config or callbacks it is given:
59
+ - Each tool call the plugin authorizes may start exactly one tool: the one with that call's id and name, once. Any other tool start is refused before the tool runs.
60
+ - A model call made inside the body of a governed tool is refused. If a tool really needs to call a model directly, for example to summarize text, wrap that call in `with direct_model_use():` (from `watchlight_deepagents`). A model call that binds tools is refused even then, so the escape never covers an agent's turn.
61
+ - A model call that binds tools, local or hosted by the provider, is refused unless it is a governed agent's own turn. Hosted tools run on the provider's side, where no tool start is visible, so this is where they are stopped.
62
+ - Each refusal is recorded in the run's lineage as a denied call, with names only and never argument values.
63
+
64
+ This is a change in behaviour: a tool that used to run an inner agent, or call a model directly, now fails with `UngovernedModelCall` or `UngovernedToolCall` (both are `GovernanceUnavailable`). Spawn sub-agents through `task` with `create_governed_deep_agent(...)`, which governs them, or use `direct_model_use()` for a direct, tool-less model call. Governed `task` sub-agents and DeepAgents' own summarization are not affected. With no governed run live, nothing is refused.
65
+
66
+ The check is a callback the plugin registers once with LangChain, through LangChain's public configure hook; no framework class is patched. It has limits:
67
+ - The live-run state is shared by the whole process. While a governed run is live, an ungoverned agent running at the same time elsewhere in the same process is refused too.
68
+ - A model call that binds no tools, made on a new thread or in a fresh `contextvars.Context` started from a tool body, is not refused. It can run no tool: its tool starts are refused, and it binds no hosted tool.
69
+ - A governed agent run inside another governed agent's ordinary tool has its own summarization refused. Run it as a `task` sub-agent instead.
70
+ - Each authorized call may start its tool once, so a retry must pass through Watchlight's middleware again. A retry middleware must sit outside Watchlight's: one that runs inside it and calls the tool again within the same call has the retry refused. `create_governed_deep_agent(...)` places Watchlight's middleware ahead of the `middleware=` you pass, so a tool-retry middleware passed there runs inside it. Retry at the model level instead, as a new tool call, which is authorized again.
71
+ - A refusal that cannot be published to lineage still stands. It is logged at warning level and counted in `watchlight_core.langchain_tool_backstop.emit_failures()`.
72
+ - Code that calls a tool's private `_run`, a model's private `_generate`, or a provider SDK directly bypasses LangChain's callbacks and is not seen. Neither is code that deliberately removes LangChain's configure hooks or resets the plugin's context variables, which turns governance off on purpose.
73
+
74
+ Not enforced:
75
+
76
+ - **Model turns are not authorized one by one.** The plugin records each model turn and refuses it when there is no governed run or when the run is quarantined. It does not send a per-turn authorization request. Governance of the model's network calls comes from the Watchlight proxy, when you configure it.
77
+ - **A policy does not see argument values.** The plugin sends argument names, count and types only. The path of a filesystem call is in the resource name (`deepagents://fs/<path>`).
78
+ - **Reporting is best-effort.** A model-turn or tool-call event that the plugin cannot publish does not stop the run.
79
+ - **The check on agents built inside a tool has limits.** They are listed with it, above.
80
+
81
+ ## Settings
82
+
83
+ `create_governed_deep_agent(...)` takes the arguments of `create_deep_agent` and these:
84
+
85
+ | Argument | What it sets |
86
+ |---|---|
87
+ | `agent_slug` | Required. The registered slug of the root agent. |
88
+ | `plugin` | The `WatchlightDeepAgentsPlugin` to use. Without it, the factory calls `WatchlightDeepAgentsPlugin.from_env()`. |
89
+ | `subagent_scopes` | For each sub-agent name, the scope its spawn asks for: `allowed_tools`, `allowed_resources`, `allowed_intents`, `max_depth` and `time_budget_seconds`. Name a tool as `deepagents://tool/<name>`. A sub-agent with no entry is spawned with no tools and `max_depth` 0. |
90
+ | `subagent_slugs` | The registered slug of each sub-agent name. The default is the sub-agent's name. |
91
+
92
+ `WatchlightDeepAgentsPlugin(...)` takes `governance=` (a backend such as `InProcessClient`), or `apdp_url=` for the Enterprise server, and reads these variables:
93
+
94
+ | Variable | What it sets |
95
+ |---|---|
96
+ | `WATCHLIGHT_APDP_URL` | Enterprise: the server URL. `from_env()` requires it and raises `GovernanceUnavailable` when it is not set. |
97
+ | `WATCHLIGHT_TENANT_ID` | Enterprise: the tenant, read by `from_env()`. |
98
+ | `WATCHLIGHT_PLUGIN_TOKEN` | Enterprise: the plugin credential. The SDK README lists the [other places a credential is read from](https://github.com/watchlight-ai-beacon/watchlight-de/blob/main/integrations/plugins/python/watchlight-core/README.md#settings). |
99
+ | `WATCHLIGHT_PROXY_URL` | The Watchlight proxy that egress goes through. The same as `connect_proxy_url=`. |
100
+ | `WATCHLIGHT_PROXY_CA_CERT` | A PEM CA bundle used to verify an `https://` Watchlight proxy. |
101
+ | `WATCHLIGHT_APPLICATION_ID` | The AI application the runs belong to. See below. |
102
+ | `WATCHLIGHT_INTENT_ENFORCEMENT_MODE` | `brownfield` (the default) or `greenfield`. The same as `intent_enforcement_mode=`. In `greenfield` the agent is given the `watchlight.declare_intent` tool. |
103
+ | `WATCHLIGHT_PLAN_GOVERNANCE_MODE` | `degrade` lets a run start when no constraint manifest could be obtained. Without it the run is refused. Use it only for development. |
104
+
105
+ ### Attributing runs to an AI application
106
+
107
+ Every governed run can be attributed to the AI application the agent belongs to. Pass `application_id="<application UUID>"` to `WatchlightDeepAgentsPlugin(...)`, or per run to `start_run(...)`, or set `WATCHLIGHT_APPLICATION_ID` in the environment (`from_env()` picks it up too). An explicit argument wins over the variable. The middleware opens runs with the plugin-level value, so a deployment attributes an agent without a code change. The server refuses the run if the agent is not a member of that application. An agent in exactly one application needs nothing here. The id is explicit configuration, never inferred from prompts or names, and a value that is not a UUID raises `ValueError`. It is an Enterprise feature: the Developer Edition engine refuses it.
108
+
109
+ ## Errors
110
+
111
+ A refused tool call is not an exception. The model gets an error tool message in place of the tool's result and the tool never runs: for a denial by policy (`Denied by Watchlight policy.`, without the backend's reason), for an action that needs approval, for a tool the sub-agent was not granted, and for a `task` spawn refused for its scope or for a sub-agent that is not registered.
112
+
113
+ The errors below are raised to your code. Branch on the error class, not on the message text.
114
+
115
+ | Error | Meaning |
116
+ |---|---|
117
+ | `GovernanceUnavailable` | A governed run could not be opened or kept: `from_env()` without `WATCHLIGHT_APDP_URL`, a backend that did not open the run, no constraint manifest, a configured Watchlight proxy that cannot be used, a synchronous `invoke`, or a sub-agent the factory cannot govern (a pre-compiled `runnable` or a remote `graph_id`). |
118
+ | `AgentNotRegistered` | The root agent's slug is not registered. |
119
+ | `SidecarRunActive` | Another run in this process owns the egress proxy. A kind of `GovernanceUnavailable`. |
120
+ | `NestedRunEscapedError` | A governed agent tried to open a root of its own while a governed run was live. `SpawnRefusedRootRunError` is the kind raised for an agent whose `task` spawn was refused. |
121
+ | `DeclaredRootRefused` | A root declared with `root_run()` was not opened. A kind of `GovernanceUnavailable`. |
122
+ | `UngovernedModelCall`, `UngovernedToolCall` | A model or tool call that no governed agent authorized was refused. Both are kinds of `GovernanceUnavailable`. |
123
+ | `AgentQuarantinedError` | The backend quarantined the run, and the agent loop stops. |
124
+
125
+ ## Moving to Watchlight Beacon (Enterprise)
126
+
127
+ The Developer Edition decides with the engine inside your process. Watchlight Beacon is the Enterprise server. Your agent code stays the same: set `WATCHLIGHT_APDP_URL`, a credential (`WATCHLIGHT_PLUGIN_TOKEN`) and, in a multi-tenant deployment, `WATCHLIGHT_TENANT_ID`, and leave out `plugin=`, so the factory builds the plugin with `WatchlightDeepAgentsPlugin.from_env()`.
128
+
129
+ What changes when you move is described once, in the SDK README: [Moving to Watchlight Beacon (Enterprise)](https://github.com/watchlight-ai-beacon/watchlight-de/blob/main/integrations/plugins/python/watchlight-core/README.md#moving-to-watchlight-beacon-enterprise).
130
+
131
+ ## Links
132
+
133
+ - Documentation: https://docs.watchlight.ai/de
134
+ - Source and issues: https://github.com/watchlight-ai-beacon/watchlight-de
135
+ - Website: https://watchlight.ai
136
+
137
+ ## License
138
+
139
+ Apache-2.0
140
+
141
+ ## Trademarks
142
+
143
+ DeepAgents, LangChain, LangGraph and other product names in this README belong to their respective owners. They are used only to describe compatibility. This plugin is not affiliated with, endorsed by or sponsored by them.
@@ -0,0 +1,75 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "watchlight-deepagents"
7
+ version = "0.1.2"
8
+ description = "Watchlight governance middleware for DeepAgents agents: authorize every tool and filesystem call and gate sub-agent spawns, fail-closed. Model turns are not authorized one by one. Independent plugin, not affiliated with or endorsed by LangChain."
9
+ readme = "README.md"
10
+ # SPDX licence expression (PEP 639; setuptools 77 or later).
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ requires-python = ">=3.11"
14
+ authors = [
15
+ {name = "Watchlight AI", email = "team@watchlight.ai"},
16
+ ]
17
+ keywords = [
18
+ "watchlight",
19
+ "deepagents",
20
+ "langchain",
21
+ "ai-agents",
22
+ "ai-governance",
23
+ "agent-runtime",
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 4 - Beta",
27
+ "Intended Audience :: Developers",
28
+ "Programming Language :: Python :: 3",
29
+ "Programming Language :: Python :: 3.11",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Programming Language :: Python :: 3.13",
32
+ "Topic :: Software Development :: Libraries :: Python Modules",
33
+ "Typing :: Typed",
34
+ ]
35
+
36
+ # ``deepagents`` is the framework this plugin wraps. The load-bearing
37
+ # external contract is the LangChain v1 ``AgentMiddleware`` hook surface
38
+ # (``before_agent`` / ``after_agent`` / ``before_model`` /
39
+ # ``wrap_model_call`` / ``wrap_tool_call`` + the ``tools`` /
40
+ # ``state_schema`` / ``name`` attributes), the ``SubAgent.middleware``
41
+ # field, and the ``task`` tool schema (``subagent_type``). LangChain v1
42
+ # middleware is young (``wrap_model_call`` was renamed from
43
+ # ``modify_model_request``); the pin below is deliberately tight and a
44
+ # major bump that moves any of those needs an explicit range update +
45
+ # a security review of the change. ``test_middleware_lifecycle.py`` asserts
46
+ # the hook surface so drift breaks loudly in CI rather than silently
47
+ # disabling governance. ``langchain`` / ``langchain-core`` / ``langgraph``
48
+ # come transitively via ``deepagents``.
49
+ # ``watchlight-agent-sdk`` 0.11.0: the tool-start check, root admission and
50
+ # the declared-root errors this plugin imports are not in 0.10.x, so the
51
+ # plugin does not import against it.
52
+ dependencies = [
53
+ "watchlight-agent-sdk>=0.11.0,<0.12",
54
+ "deepagents>=0.7,<0.8",
55
+ ]
56
+
57
+ [project.optional-dependencies]
58
+ otlp = ["watchlight-agent-sdk[otlp]>=0.11.0,<0.12"]
59
+ dev = ["pytest>=7", "pytest-asyncio>=0.21", "mypy>=1.8"]
60
+
61
+ [project.urls]
62
+ Homepage = "https://watchlight.ai"
63
+ Documentation = "https://docs.watchlight.ai/de"
64
+ Repository = "https://github.com/watchlight-ai-beacon/watchlight-de"
65
+ Issues = "https://github.com/watchlight-ai-beacon/watchlight-de/issues"
66
+ "DeepAgents" = "https://github.com/langchain-ai/deepagents"
67
+
68
+ [tool.setuptools.packages.find]
69
+ include = ["watchlight_deepagents*"]
70
+
71
+ [tool.setuptools.package-data]
72
+ watchlight_deepagents = ["py.typed"]
73
+
74
+ [tool.pytest.ini_options]
75
+ asyncio_mode = "auto"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+