watchdog-agent-sdk 0.1.0__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.
- watchdog_agent_sdk-0.1.0/ADAPTER_VERIFICATION.md +66 -0
- watchdog_agent_sdk-0.1.0/LICENSE +201 -0
- watchdog_agent_sdk-0.1.0/MANIFEST.in +7 -0
- watchdog_agent_sdk-0.1.0/PKG-INFO +263 -0
- watchdog_agent_sdk-0.1.0/README.md +242 -0
- watchdog_agent_sdk-0.1.0/examples/CONTROL_ADAPTER.md +118 -0
- watchdog_agent_sdk-0.1.0/examples/control_webhook.py +302 -0
- watchdog_agent_sdk-0.1.0/examples/daily_report.py +24 -0
- watchdog_agent_sdk-0.1.0/examples/openai_agent.py +27 -0
- watchdog_agent_sdk-0.1.0/pyproject.toml +35 -0
- watchdog_agent_sdk-0.1.0/setup.cfg +4 -0
- watchdog_agent_sdk-0.1.0/tests/test_client.py +287 -0
- watchdog_agent_sdk-0.1.0/tests/test_control_webhook.py +178 -0
- watchdog_agent_sdk-0.1.0/tests/test_openai_adapter.py +62 -0
- watchdog_agent_sdk-0.1.0/tests/test_real_openai.py +134 -0
- watchdog_agent_sdk-0.1.0/watchdog_agent/__init__.py +6 -0
- watchdog_agent_sdk-0.1.0/watchdog_agent/client.py +456 -0
- watchdog_agent_sdk-0.1.0/watchdog_agent/openai_agents.py +95 -0
- watchdog_agent_sdk-0.1.0/watchdog_agent_sdk.egg-info/PKG-INFO +263 -0
- watchdog_agent_sdk-0.1.0/watchdog_agent_sdk.egg-info/SOURCES.txt +21 -0
- watchdog_agent_sdk-0.1.0/watchdog_agent_sdk.egg-info/dependency_links.txt +1 -0
- watchdog_agent_sdk-0.1.0/watchdog_agent_sdk.egg-info/requires.txt +4 -0
- watchdog_agent_sdk-0.1.0/watchdog_agent_sdk.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# OpenAI Agents adapter verification
|
|
2
|
+
|
|
3
|
+
The adapter uses the lifecycle contract below. Signatures include `self` and a
|
|
4
|
+
trailing `**kwargs` in the Watchdog implementation for forward-compatible keyword
|
|
5
|
+
extensions. Inputs are accepted only to match the framework contract and are not
|
|
6
|
+
serialized.
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
async def on_agent_start(self, context, agent): ...
|
|
10
|
+
async def on_agent_end(self, context, agent, output): ...
|
|
11
|
+
async def on_handoff(self, context, from_agent, to_agent): ...
|
|
12
|
+
async def on_llm_start(self, context, agent, system_prompt, input_items): ...
|
|
13
|
+
async def on_llm_end(self, context, agent, response): ...
|
|
14
|
+
async def on_tool_start(self, context, agent, tool): ...
|
|
15
|
+
async def on_tool_end(self, context, agent, tool, result): ...
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The adapter reads `response.usage.input_tokens` and
|
|
19
|
+
`response.usage.output_tokens`. It does not read response output or cumulative
|
|
20
|
+
run-context usage. For function calls it reads tool names, local argument
|
|
21
|
+
fingerprints, and elapsed monotonic time. If exposed by the framework,
|
|
22
|
+
`context.tool_call_id` is used only for local timing correlation and
|
|
23
|
+
`context.tool_arguments` is HMACed locally.
|
|
24
|
+
|
|
25
|
+
Sources inspected on September 5, 2026:
|
|
26
|
+
|
|
27
|
+
- [Official Agents SDK overview](https://developers.openai.com/api/docs/guides/agents)
|
|
28
|
+
- [Official running agents guide](https://developers.openai.com/api/docs/guides/agents/running-agents)
|
|
29
|
+
- [Official integrations and observability guide](https://developers.openai.com/api/docs/guides/agents/integrations-observability)
|
|
30
|
+
|
|
31
|
+
The official `openai-agents` 0.8.4 distribution was downloaded and its source
|
|
32
|
+
inspected. Wheel SHA-256:
|
|
33
|
+
`2383c6e8e59ed4146b89d1b6f53e34e55caf94bc14ae3fd704e7aad5021f4ff1`.
|
|
34
|
+
|
|
35
|
+
The optional dependency pins `openai-agents==0.8.4` and `openai==2.19.0` as a
|
|
36
|
+
compatible baseline. Resolving the upstream Agents dependency without this pin
|
|
37
|
+
installed `openai==2.54.0`, whose required `cache_write_tokens` usage field breaks
|
|
38
|
+
the Agents 0.8.4 default `Usage()` constructor before lifecycle hooks run. The
|
|
39
|
+
adapter does not monkeypatch upstream models or hide this compatibility failure.
|
|
40
|
+
|
|
41
|
+
Verified directly in the distribution:
|
|
42
|
+
|
|
43
|
+
- `agents/lifecycle.py`: all seven signatures above match. `RunHooks` is an alias
|
|
44
|
+
for `RunHooksBase[TContext, Agent]`.
|
|
45
|
+
- `agents/run_internal/tool_execution.py`: function-tool hooks receive the
|
|
46
|
+
`ToolContext`, including the call ID and arguments used by this adapter.
|
|
47
|
+
- `agents/tool_context.py`: `tool_call_id` and `tool_arguments` are required
|
|
48
|
+
context fields. The adapter only hashes arguments locally.
|
|
49
|
+
- `agents/run_internal/run_loop.py`: per-response usage is added to the cumulative
|
|
50
|
+
context before the end hook. Reading `response.usage` avoids double counting.
|
|
51
|
+
- `agents/run_internal/tool_actions.py`: some local action tools receive a plain
|
|
52
|
+
run context, so per-call ID/argument fidelity is not universally available.
|
|
53
|
+
|
|
54
|
+
Four tests in `tests/test_real_openai.py` passed against the actual installed
|
|
55
|
+
Runner using a deterministic local Model. They verify exact installed signatures,
|
|
56
|
+
parallel tool calls with distinct private fingerprints, correct per-response token
|
|
57
|
+
counts, preserved Runner exceptions, and cooperative cancellation. The tested
|
|
58
|
+
environment used Python 3.12, `openai-agents==0.8.4`, `openai==2.19.0`, and
|
|
59
|
+
`pydantic==2.13.5`. No live model request was made.
|
|
60
|
+
|
|
61
|
+
Run the complete SDK and control-adapter suite after installing the optional
|
|
62
|
+
extra: `python -m unittest discover -s tests -v`. Without the optional dependency,
|
|
63
|
+
the four real Runner tests are explicitly skipped. The rest of the suite covers
|
|
64
|
+
fail-open delivery, privacy, idempotency, and signed control dispatch.
|
|
65
|
+
|
|
66
|
+
Final integration validation: all 39 tests passed, including the real loopback signed HTTP server test and four real OpenAI Runner tests.
|
|
@@ -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
|
|
95
|
+
Derivative 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 [yyyy] [name of copyright owner]
|
|
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,263 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: watchdog-agent-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fail-open reliability monitoring for unattended agent jobs
|
|
5
|
+
Author: Watchdog Limited
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://withwatchdog.com
|
|
8
|
+
Project-URL: Documentation, https://withwatchdog.com/docs/quickstart
|
|
9
|
+
Project-URL: Repository, https://github.com/withwatchdog/watchdog-sdk
|
|
10
|
+
Project-URL: Issues, https://github.com/withwatchdog/watchdog-sdk/issues
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Provides-Extra: openai
|
|
18
|
+
Requires-Dist: openai-agents==0.8.4; extra == "openai"
|
|
19
|
+
Requires-Dist: openai==2.19.0; extra == "openai"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# Watchdog Python SDK
|
|
23
|
+
|
|
24
|
+
Track the completion, progress, cost, tool activity, and expected outcomes of an
|
|
25
|
+
unattended job. The SDK sends metadata to the Watchdog API from a bounded background
|
|
26
|
+
queue. Monitoring outages do not raise exceptions into application code.
|
|
27
|
+
|
|
28
|
+
## Install and configure
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python -m pip install watchdog-agent-sdk
|
|
32
|
+
export WATCHDOG_URL="https://withwatchdog.com"
|
|
33
|
+
export WATCHDOG_API_KEY="your-ingest-key"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The distribution is `watchdog-agent-sdk`; its import is `watchdog_agent`. This
|
|
37
|
+
avoids colliding with the unrelated Python filesystem package named `watchdog`.
|
|
38
|
+
The base SDK has no runtime dependencies and supports Python 3.10 or newer.
|
|
39
|
+
|
|
40
|
+
For local development, clone this repository and run `python -m pip install .`
|
|
41
|
+
from its root. Self-hosted installations can set `WATCHDOG_URL` to their API origin.
|
|
42
|
+
|
|
43
|
+
Register an agent and a job in the dashboard, then use the job ID or slug:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from watchdog_agent import Watchdog
|
|
47
|
+
|
|
48
|
+
with Watchdog() as watchdog:
|
|
49
|
+
with watchdog.run("daily-report", cancellable=True) as run:
|
|
50
|
+
with run.tool_call("competitors.search", arguments={"sector": "software"}):
|
|
51
|
+
results = search_competitors()
|
|
52
|
+
run.progress("Research complete", completed=len(results))
|
|
53
|
+
|
|
54
|
+
report = create_report(results)
|
|
55
|
+
run.outcome("report_created", metadata={"record_id": report.id})
|
|
56
|
+
|
|
57
|
+
run.check_cancelled()
|
|
58
|
+
post_report(report)
|
|
59
|
+
run.outcome("report_posted")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`run.started` is emitted on entry. Normal exit emits `run.completed`; an exception
|
|
63
|
+
emits `run.failed` and preserves the original exception. Cancellation emits
|
|
64
|
+
`run.cancelled`. Exceptions' type names are collected; their messages, stack
|
|
65
|
+
traces, and local variables are not collected. Completion means the agent exited;
|
|
66
|
+
the server evaluates whether the required business outcomes were satisfied.
|
|
67
|
+
|
|
68
|
+
Only explicit `run.progress()` calls indicate meaningful progress. Tool calls,
|
|
69
|
+
model calls, handoffs, and repeated activity do not reset the progress timer.
|
|
70
|
+
|
|
71
|
+
## Usage, costs, and outcomes
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
run.usage(
|
|
75
|
+
model="your-model-name",
|
|
76
|
+
input_tokens=2100,
|
|
77
|
+
output_tokens=300,
|
|
78
|
+
cost_usd=0.017,
|
|
79
|
+
)
|
|
80
|
+
run.tool("crm.update", duration_ms=180, status="success", arguments={"id": record_id})
|
|
81
|
+
run.outcome("crm_updated", success=True, metadata={"record_id": record_id})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Each usage event is a **delta for one model request**, not the cumulative run
|
|
85
|
+
usage. Omit `cost_usd` when it is unknown. The SDK does not embed a stale model
|
|
86
|
+
price table. This version only sums explicitly reported costs; token counts alone do not calculate spending.
|
|
87
|
+
Report an outcome only after the corresponding application operation succeeds.
|
|
88
|
+
An emitted outcome is an application attestation, not independent verification.
|
|
89
|
+
|
|
90
|
+
Tool fingerprints use a per-run random HMAC key over canonical tool name,
|
|
91
|
+
arguments, and status. Raw arguments stay in the customer process. Reordered
|
|
92
|
+
JSON keys and insignificant JSON whitespace produce the same fingerprint;
|
|
93
|
+
different arguments normally produce different fingerprints. Without arguments,
|
|
94
|
+
only tool names/status distinguish calls. Emit explicit progress within legitimate
|
|
95
|
+
bulk-processing loops to avoid treating repeated work as a lack of progress.
|
|
96
|
+
|
|
97
|
+
## Async jobs and cancellation
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
async with Watchdog() as watchdog:
|
|
101
|
+
async with watchdog.run("daily-report", cancellable=True) as run:
|
|
102
|
+
await execute_agent()
|
|
103
|
+
run.outcome("report_created")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
For a cancellable async context, an authenticated cancel command schedules
|
|
107
|
+
`Task.cancel()` on the task owning that context. It takes effect at an await
|
|
108
|
+
boundary. Application code must allow `asyncio.CancelledError` to propagate.
|
|
109
|
+
For synchronous code, call `run.check_cancelled()` between work units.
|
|
110
|
+
`run.tool_call()` checks automatically before entering a tool. Blocking external
|
|
111
|
+
operations cannot be forcefully stopped by this SDK.
|
|
112
|
+
|
|
113
|
+
The SDK acknowledges a cancel action only after the run exits cancelled. A
|
|
114
|
+
received command is not proof that execution has stopped. If the application
|
|
115
|
+
completes without observing cancellation, the action is acknowledged as failed.
|
|
116
|
+
Retry commands require a customer runtime webhook/controller; this client does
|
|
117
|
+
not retain business input or execute customer code again.
|
|
118
|
+
|
|
119
|
+
The included [signed control adapter](https://github.com/withwatchdog/watchdog-sdk/blob/main/examples/CONTROL_ADAPTER.md) implements a
|
|
120
|
+
customer-owned callback endpoint with cancellation, retry, fallback allowlisting,
|
|
121
|
+
missed-slot correlation, HMAC verification, and a durable action ledger. Its local
|
|
122
|
+
demo executes a supplied application function and writes report files.
|
|
123
|
+
|
|
124
|
+
Cancellation is out of band. Polling, network latency, in-flight tool requests,
|
|
125
|
+
and model requests can cause delay or budget overshoot. This is not a hard
|
|
126
|
+
real-time spend ceiling.
|
|
127
|
+
|
|
128
|
+
## OpenAI Agents adapter
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
python -m pip install 'watchdog-agent-sdk[openai]'
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The optional extra pins the verified combination `openai-agents==0.8.4` and
|
|
135
|
+
`openai==2.19.0`. Run the integration suite when upgrading either dependency;
|
|
136
|
+
the upstream Agents version's broad dependency range also permits a newer,
|
|
137
|
+
incompatible usage schema. Details are in
|
|
138
|
+
[ADAPTER_VERIFICATION.md](https://github.com/withwatchdog/watchdog-sdk/blob/main/ADAPTER_VERIFICATION.md).
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from agents import Runner, RunConfig
|
|
142
|
+
from watchdog_agent.openai_agents import WatchdogHooks
|
|
143
|
+
|
|
144
|
+
async with watchdog.run("daily-report", cancellable=True) as run:
|
|
145
|
+
result = await Runner.run(
|
|
146
|
+
agent,
|
|
147
|
+
business_input,
|
|
148
|
+
hooks=WatchdogHooks(run),
|
|
149
|
+
run_config=RunConfig(trace_include_sensitive_data=False),
|
|
150
|
+
)
|
|
151
|
+
# Save the result in your application before recording the outcome.
|
|
152
|
+
saved = await save_report(result.final_output)
|
|
153
|
+
run.outcome("report_created", metadata={"record_id": saved.id})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Use one hook instance per Watchdog run. The outer context owns job completion,
|
|
157
|
+
so handoffs and nested-agent completion cannot finish it prematurely. Per-response
|
|
158
|
+
token usage is used; cumulative `context.usage` would double-count earlier calls.
|
|
159
|
+
OpenAI's own tracing is separate from Watchdog telemetry: disabling sensitive
|
|
160
|
+
data there does not change application-provided Watchdog messages or metadata.
|
|
161
|
+
|
|
162
|
+
Adapter coverage and limitations:
|
|
163
|
+
|
|
164
|
+
- Lifecycle hooks capture function-tool completions and per-model response usage.
|
|
165
|
+
- Hosted provider tools may not pass through function-tool hooks; supply explicit
|
|
166
|
+
instrumentation when that activity needs to count toward a tool-call policy.
|
|
167
|
+
- Tool exceptions converted by a framework into result strings cannot be
|
|
168
|
+
classified safely without examining sensitive output. Use `run.tool_call()`
|
|
169
|
+
inside a custom tool, or emit explicit error status for accurate error storms.
|
|
170
|
+
Avoid also counting the same completed tool through the adapter.
|
|
171
|
+
- Call IDs distinguish concurrent tool calls where the framework exposes them.
|
|
172
|
+
Older contexts without call IDs use a FIFO fallback; durations may be
|
|
173
|
+
approximate for parallel calls of the same tool.
|
|
174
|
+
- Hook-generated events do not imply business outcomes or semantic progress.
|
|
175
|
+
|
|
176
|
+
The official [Agents SDK guide](https://developers.openai.com/api/docs/guides/agents)
|
|
177
|
+
and [running agents guide](https://developers.openai.com/api/docs/guides/agents/running-agents)
|
|
178
|
+
describe the SDK execution model. See `ADAPTER_VERIFICATION.md` for the exact
|
|
179
|
+
compatibility evidence and remaining limitations.
|
|
180
|
+
|
|
181
|
+
## Delivery and privacy behavior
|
|
182
|
+
|
|
183
|
+
- The default queue holds 1,024 requests; enqueue never waits for network I/O.
|
|
184
|
+
Full queues drop new telemetry and increment `watchdog.stats["dropped"]`.
|
|
185
|
+
- Events have unique IDs and per-run monotonic sequences. Retries preserve the
|
|
186
|
+
original serialized event, timestamp, sequence, and ID for server deduplication.
|
|
187
|
+
- Transient failures receive two retries by default. HTTP 4xx other than 408/429
|
|
188
|
+
are not retried. No prompts, outputs, payloads, or bearer keys are logged.
|
|
189
|
+
- Use the client as a context manager or call `watchdog.close(timeout=2)` before
|
|
190
|
+
a short-lived process exits. `flush()` and `close()` return `False` if their
|
|
191
|
+
bounded wait expires. Daemon threads cannot guarantee delivery after a crash
|
|
192
|
+
or process kill. There is no durable disk spool in this version.
|
|
193
|
+
- Missing `WATCHDOG_API_KEY` disables delivery. Inspect `.enabled` and `.stats`
|
|
194
|
+
during installation checks. Configuration errors, such as insecure remote URLs,
|
|
195
|
+
raise immediately; network failures do not interrupt an otherwise valid job.
|
|
196
|
+
- Metadata accepts bounded JSON values and removes common secret-bearing keys.
|
|
197
|
+
Application-provided messages, names, and metadata values are intentionally
|
|
198
|
+
transmitted: do not place secrets in them. Secret-key filtering is defense in
|
|
199
|
+
depth, not a content classifier.
|
|
200
|
+
- HTTPS is required except for loopback development. Redirects are rejected so
|
|
201
|
+
bearer credentials are not forwarded to another host.
|
|
202
|
+
- Customer-supplied `headers={...}` can support additional deployment access
|
|
203
|
+
layers. Authentication and request-framing headers cannot be overridden.
|
|
204
|
+
|
|
205
|
+
Create the client **after forking** a worker process. A client owns live threads
|
|
206
|
+
and is not process-safe. Reuse one client across jobs within each process.
|
|
207
|
+
|
|
208
|
+
## Wire protocol
|
|
209
|
+
|
|
210
|
+
`POST /api/v1/events` accepts a single JSON event with bearer authentication:
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
{
|
|
214
|
+
"event_id": "evt_a_unique_id",
|
|
215
|
+
"run_id": "run_a_unique_id",
|
|
216
|
+
"job_id": "daily-report",
|
|
217
|
+
"type": "tool.completed",
|
|
218
|
+
"sequence": 3,
|
|
219
|
+
"timestamp": "2026-09-05T12:00:00.000Z",
|
|
220
|
+
"data": {
|
|
221
|
+
"name": "crm.update",
|
|
222
|
+
"fingerprint": "a-per-run-hmac",
|
|
223
|
+
"duration_ms": 180,
|
|
224
|
+
"status": "success",
|
|
225
|
+
"metadata": {}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Types: `run.started`, `progress`, `tool.completed`, `llm.completed`, `outcome`,
|
|
231
|
+
`run.completed`, `run.failed`, `run.cancelled`.
|
|
232
|
+
|
|
233
|
+
`GET /api/v1/runs/{run_id}/commands` returns
|
|
234
|
+
`{"commands":[{"id":"action-id","type":"cancel"}]}`.
|
|
235
|
+
The SDK sends `POST /api/v1/actions/{action_id}/ack` with
|
|
236
|
+
`{"status":"acknowledged","message":"Runtime stopped cooperatively"}`
|
|
237
|
+
after cancellation takes effect, or `status: "failed"` when it cannot be applied.
|
|
238
|
+
|
|
239
|
+
## Tests
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
python -m pip install '.[openai]'
|
|
243
|
+
python -m unittest discover -s tests -v
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Run these commands from the cloned repository root. Tests cover outages,
|
|
247
|
+
queue saturation, bounded shutdown, retry idempotency,
|
|
248
|
+
privacy, concurrent event sequences, sync/async cancellation acknowledgments,
|
|
249
|
+
tool failures, outcomes, and hook mapping without requiring a model API key.
|
|
250
|
+
|
|
251
|
+
## Start with lifecycle-only monitoring
|
|
252
|
+
|
|
253
|
+
New Watchdog jobs leave progress monitoring disabled (`progress_timeout: 0`) and have no expected schedule unless you add one. Set a realistic maximum runtime, for example 1,200 seconds for a legitimate 15-minute job. The run context reports start, completion and failure; it cannot report a process kill. A missing completion is detected when the runtime deadline expires.
|
|
254
|
+
|
|
255
|
+
Add `run.progress()` after meaningful completed work, then explicitly enable a milestone timeout in the job's Additional checks. The timer starts at run start. Tool calls do not reset it, and emitting progress does not turn the timeout on. Progress can still reset the tool-loop window while milestone timeout monitoring is off. Existing jobs retain their saved policies; edits apply to future runs.
|
|
256
|
+
|
|
257
|
+
Install without repository access:
|
|
258
|
+
|
|
259
|
+
```sh
|
|
260
|
+
python -m pip install watchdog-agent-sdk==0.1.0
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Use `watchdog-agent-sdk`, not the unrelated `watchdog` filesystem package.
|