acdp-agent-hooks 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.
- acdp_agent_hooks-0.1.0/.gitignore +11 -0
- acdp_agent_hooks-0.1.0/CHANGELOG.md +17 -0
- acdp_agent_hooks-0.1.0/LICENSE +201 -0
- acdp_agent_hooks-0.1.0/PKG-INFO +317 -0
- acdp_agent_hooks-0.1.0/README.md +280 -0
- acdp_agent_hooks-0.1.0/pyproject.toml +92 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/__init__.py +36 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/claude_agent.py +206 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/cli.py +37 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/config.py +129 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/ctxids.py +79 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/openai_agents.py +138 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/otel.py +132 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/publisher.py +384 -0
- acdp_agent_hooks-0.1.0/src/acdp_hooks/py.typed +0 -0
- acdp_agent_hooks-0.1.0/tests/__init__.py +0 -0
- acdp_agent_hooks-0.1.0/tests/conftest.py +86 -0
- acdp_agent_hooks-0.1.0/tests/integration/__init__.py +0 -0
- acdp_agent_hooks-0.1.0/tests/integration/compose.yml +54 -0
- acdp_agent_hooks-0.1.0/tests/integration/test_registry.py +107 -0
- acdp_agent_hooks-0.1.0/tests/test_claude_agent.py +215 -0
- acdp_agent_hooks-0.1.0/tests/test_config.py +87 -0
- acdp_agent_hooks-0.1.0/tests/test_ctxids.py +38 -0
- acdp_agent_hooks-0.1.0/tests/test_openai_agents.py +150 -0
- acdp_agent_hooks-0.1.0/tests/test_otel.py +177 -0
- acdp_agent_hooks-0.1.0/tests/test_publisher.py +247 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-10-26
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- `AcdpPublisher`: signs one body per tool result / final output with a
|
|
8
|
+
did:key or did:web Ed25519 producer key and publishes it, with retries under
|
|
9
|
+
a content-hash idempotency key.
|
|
10
|
+
- Claude Agent SDK: `AcdpClaudeHooks` (`PostToolUse`, `PostToolUseFailure`,
|
|
11
|
+
`Stop`), appended to existing hooks via `attach` / `install` / `merge_hooks`.
|
|
12
|
+
- OpenAI Agents SDK: `AcdpRunHooks` and `compose_run_hooks`.
|
|
13
|
+
- `derived_from` from declared inputs, cited and observed ctx_ids, and the
|
|
14
|
+
run's own tool-result bodies.
|
|
15
|
+
- OpenTelemetry `acdp.*` attributes from the spec registry (optional extra).
|
|
16
|
+
- Fail-open by default; fail-closed opt-in.
|
|
17
|
+
- `acdp-hooks keygen`.
|
|
@@ -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,317 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: acdp-agent-hooks
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Agent-framework hooks that sign tool results and final outputs and publish them to an ACDP registry, with derived_from lineage and OpenTelemetry attributes.
|
|
5
|
+
Project-URL: Homepage, https://agentcontextdistributionprotocol.io
|
|
6
|
+
Project-URL: Source, https://github.com/agentcontextdistributionprotocol/acdp-agent-hooks
|
|
7
|
+
Project-URL: Issues, https://github.com/agentcontextdistributionprotocol/acdp-agent-hooks/issues
|
|
8
|
+
Author: Agent Context Distribution Protocol
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: acdp,agents,claude-agent-sdk,openai-agents,opentelemetry,provenance
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: acdp>=0.17.3
|
|
22
|
+
Requires-Dist: httpx>=0.27
|
|
23
|
+
Provides-Extra: claude
|
|
24
|
+
Requires-Dist: claude-agent-sdk<0.3,>=0.2; extra == 'claude'
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: coverage[toml]>=7.6; extra == 'dev'
|
|
27
|
+
Requires-Dist: mypy>=1.13; extra == 'dev'
|
|
28
|
+
Requires-Dist: opentelemetry-sdk>=1.27; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff==0.16.9; extra == 'dev'
|
|
32
|
+
Provides-Extra: openai
|
|
33
|
+
Requires-Dist: openai-agents>=0.24; extra == 'openai'
|
|
34
|
+
Provides-Extra: otel
|
|
35
|
+
Requires-Dist: opentelemetry-api>=1.27; extra == 'otel'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# acdp-agent-hooks
|
|
39
|
+
|
|
40
|
+
Hooks for agent frameworks that sign every tool result and every final output,
|
|
41
|
+
publish each one to an [ACDP](https://agentcontextdistributionprotocol.io)
|
|
42
|
+
registry, and link them together with `derived_from`. Each publish returns an
|
|
43
|
+
`acdp://` link, and OpenTelemetry spans get the spec's `acdp.*` attributes.
|
|
44
|
+
|
|
45
|
+
- **Claude Agent SDK**: `PostToolUse`, `PostToolUseFailure` and `Stop` hooks,
|
|
46
|
+
appended to whatever hooks you already have (seam's `SeamHooks`, for example).
|
|
47
|
+
- **OpenAI Agents SDK**: a `RunHooks` (`on_tool_end`, `on_agent_end`) plus a
|
|
48
|
+
composer, so it runs alongside your own hooks.
|
|
49
|
+
- **OpenTelemetry**: optional. Only the names in the spec's
|
|
50
|
+
[`registries/otel-attributes.md`](https://github.com/agentcontextdistributionprotocol/agentcontextdistributionprotocol/blob/main/registries/otel-attributes.md)
|
|
51
|
+
are emitted.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install "acdp-agent-hooks[claude]" # or [openai]; add ,otel for spans
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Python 3.10+. Depends on the [`acdp`](https://pypi.org/project/acdp/) SDK (≥ 0.17.3)
|
|
58
|
+
for canonicalisation and signing, and on `httpx` for transport.
|
|
59
|
+
|
|
60
|
+
## Configuration: two lines
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
ACDP_REGISTRY_URL=https://registry.agentcontextdistributionprotocol.io
|
|
64
|
+
ACDP_PRODUCER_KEY=ed25519:<base64url seed>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`acdp-hooks keygen` prints a fresh `ACDP_PRODUCER_KEY` line. The key decides
|
|
68
|
+
the producer DID:
|
|
69
|
+
|
|
70
|
+
| `ACDP_PRODUCER_KEY` | Producer |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `ed25519:<seed>` | `did:key`, derived from the key. Nothing to host; verifiers check it offline. A new key is a new identity. |
|
|
73
|
+
| `ed25519:<seed>;did=did:web:agents.example.com:my-agent#key-1` | `did:web`. Publish the key in that DID document (`acdp-hooks keygen --did-web <key-id>` prints the public key). Use it for a long-lived identity that can rotate keys. |
|
|
74
|
+
|
|
75
|
+
`<seed>` is the 32-byte Ed25519 seed as base64url or 64 hex characters. It is
|
|
76
|
+
the private key. Keep it in your secret store.
|
|
77
|
+
|
|
78
|
+
Keyless signing (RFC-ACDP-0021) is still a draft, so it is not supported yet.
|
|
79
|
+
|
|
80
|
+
In code, `HooksConfig(registry_url, producer_key)` does the same job, and
|
|
81
|
+
`HooksConfig.from_env()` reads the two variables. The other settings have
|
|
82
|
+
defaults: `fail_policy` (`open`), `visibility` (`public`), `timeout_s` (10)
|
|
83
|
+
and `retries` (2).
|
|
84
|
+
|
|
85
|
+
## Claude Agent SDK
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from claude_agent_sdk import ClaudeAgentOptions, query
|
|
89
|
+
from acdp_hooks import AcdpPublisher
|
|
90
|
+
from acdp_hooks.claude_agent import AcdpClaudeHooks
|
|
91
|
+
|
|
92
|
+
provenance = AcdpClaudeHooks(AcdpPublisher.from_env())
|
|
93
|
+
options = ClaudeAgentOptions(hooks=provenance.attach()) # or provenance.attach(existing_hooks)
|
|
94
|
+
|
|
95
|
+
async for message in query(prompt="...", options=options):
|
|
96
|
+
...
|
|
97
|
+
|
|
98
|
+
ledger = provenance.ledger(session_id)
|
|
99
|
+
ledger.tool_links # one Link per tool result
|
|
100
|
+
ledger.output_link # the final output's Link
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- **Tool results** (`PostToolUse`, and `PostToolUseFailure` with
|
|
104
|
+
`is_error: true`). One body per call. Its `ctx_id` goes back to the model as
|
|
105
|
+
`additionalContext` (`ACDP provenance for this Read result: acdp://…`). Turn
|
|
106
|
+
that off with `inject_link=False`.
|
|
107
|
+
- **Final output** (`Stop`). One body over `last_assistant_message`. To publish
|
|
108
|
+
`ResultMessage.result` yourself, use
|
|
109
|
+
`await provenance.publish_final_output(result, session_id)`, and pass
|
|
110
|
+
`publish_output_on_stop=False` so the output isn't published twice.
|
|
111
|
+
- `attach(existing)` returns a new hooks map: `existing` with this package's
|
|
112
|
+
matchers **appended** to each event's list. It never removes, replaces or
|
|
113
|
+
reorders a matcher, and it does not mutate `existing`. `install(options)`
|
|
114
|
+
does the same in place on a `ClaudeAgentOptions`. `merge_hooks(a, b, …)`
|
|
115
|
+
concatenates any number of maps.
|
|
116
|
+
- Each matcher's timeout (`hook_timeout_s`) is set longer than one publish
|
|
117
|
+
including all its retries. That way the fail policy settles a slow registry,
|
|
118
|
+
not the SDK's hook timeout.
|
|
119
|
+
- Every hook body is sentineled. A malformed hook input or an unexpected error
|
|
120
|
+
is handled by the fail policy and never raised into the SDK.
|
|
121
|
+
|
|
122
|
+
### With seam's `SeamHooks`
|
|
123
|
+
|
|
124
|
+
seam's `SeamHooks` (package `seam-claude-agent`, from seam-adapters) gates
|
|
125
|
+
tool calls with `PreToolUse` and audits them with
|
|
126
|
+
`PostToolUse`/`PostToolUseFailure`. The two packages coexist on the same
|
|
127
|
+
events:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from seam_claude_agent import SeamHooks
|
|
131
|
+
from acdp_hooks.claude_agent import AcdpClaudeHooks
|
|
132
|
+
|
|
133
|
+
seam = SeamHooks(gate)
|
|
134
|
+
provenance = AcdpClaudeHooks(AcdpPublisher.from_env())
|
|
135
|
+
|
|
136
|
+
options = ClaudeAgentOptions(hooks=provenance.attach(seam.matchers()))
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- **Order.** Seam's matchers come first in each list and ACDP's are appended
|
|
140
|
+
after them. Neither hook reads the other's output.
|
|
141
|
+
- **Seam decides, ACDP records.** `PreToolUse` belongs to seam alone. A call
|
|
142
|
+
seam denies never runs, so it gets no `PostToolUse` and no ACDP body. A call
|
|
143
|
+
seam transforms is recorded with the `tool_input` the SDK reports to
|
|
144
|
+
`PostToolUse`.
|
|
145
|
+
- **Both audit, independently.** Seam's `ToolUseAudit` and the ACDP ledger
|
|
146
|
+
both see the same `tool_response`. Seam's post hooks return `{}`. Under
|
|
147
|
+
fail-open, ACDP's return only `additionalContext`, so nothing collides.
|
|
148
|
+
- **Fail-closed.** If you set ACDP to fail-closed, a failed publish replaces
|
|
149
|
+
the tool output that reaches the model (`updatedToolOutput` /
|
|
150
|
+
`updatedMCPToolOutput`). Seam's audit row still records the real result,
|
|
151
|
+
because the tool did run.
|
|
152
|
+
- **Timeouts are per matcher.** Seam derives its timeout from its gate
|
|
153
|
+
deadline; ACDP derives its own from the publish deadline. Neither one
|
|
154
|
+
stretches the other.
|
|
155
|
+
- **`can_use_tool`.** ACDP never sets it, so seam's escalation adjudicator
|
|
156
|
+
keeps working as before.
|
|
157
|
+
|
|
158
|
+
## OpenAI Agents SDK
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from agents import Runner
|
|
162
|
+
from acdp_hooks import AcdpPublisher
|
|
163
|
+
from acdp_hooks.openai_agents import AcdpRunHooks, compose_run_hooks
|
|
164
|
+
|
|
165
|
+
publisher = AcdpPublisher.from_env() # reuse across runs
|
|
166
|
+
provenance = AcdpRunHooks(publisher) # one per run
|
|
167
|
+
|
|
168
|
+
result = await Runner.run(agent, prompt, hooks=compose_run_hooks(my_hooks, provenance))
|
|
169
|
+
provenance.ledger.output_link # the final output's acdp:// link
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
- `on_tool_end` publishes one body per local tool call. For function tools the
|
|
173
|
+
arguments come from `ToolContext.tool_arguments`, and `on_tool_start` supplies
|
|
174
|
+
`started_at`. `on_agent_end` publishes the final output, with the agent's
|
|
175
|
+
`name` included.
|
|
176
|
+
- `Runner.run` accepts a single `hooks` object, so `compose_run_hooks(a, b, …)`
|
|
177
|
+
forwards every `RunHooks` callback to each member in order.
|
|
178
|
+
- The SDK gives a hook no way to change a tool result, so **fail-closed raises**
|
|
179
|
+
`PublishError` out of the hook. The SDK wraps it in `UserError` and the run
|
|
180
|
+
stops before the model sees the result.
|
|
181
|
+
|
|
182
|
+
## What gets published
|
|
183
|
+
|
|
184
|
+
Bodies never contain the result. Each one is a record of **salted hashes**,
|
|
185
|
+
following the model of RFC-ACDP-0019 §4.3: `H(salt ‖ JCS(value))`, with a fresh
|
|
186
|
+
32-byte salt for every body.
|
|
187
|
+
|
|
188
|
+
| | Tool result | Final output |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| `type` | `agent_hooks:tool-result` | `agent_hooks:agent-output` |
|
|
191
|
+
| `title` | `Tool result: <tool>` | `Agent output[: <agent>]` |
|
|
192
|
+
| `metadata.record_version` | `acdp-agent-hooks-tool-result/1` | `acdp-agent-hooks-output/1` |
|
|
193
|
+
| `metadata` | `framework`, `tool`, `arguments_hash`, `result_hash`, `is_error`, `salted`, `embedded`, `started_at`?, `completed_at` | `framework`, `agent`?, `output_hash`, `salted`, `embedded`, `completed_at` |
|
|
194
|
+
| `tags` | `["acdp-agent-hooks"]` | same |
|
|
195
|
+
|
|
196
|
+
The `Link` returned for each body (`ctx_id`, `lineage_id`, `version`,
|
|
197
|
+
`content_hash`, `registry`, `producer`, `type`, `derived_from`, `salt`) is the
|
|
198
|
+
only place the salt exists. Holding the result plus the link lets you prove the
|
|
199
|
+
binding: fetch the body, verify it, then recompute the hash with
|
|
200
|
+
`acdp_hooks.salted_hash(salt, result)`. Without the salt, the public body
|
|
201
|
+
reveals nothing about the content. Treat the salt as carefully as the result.
|
|
202
|
+
It is not in `repr(link)` and never goes into a span.
|
|
203
|
+
|
|
204
|
+
These types are custom (`<namespace>:<type>`), not the RFC-ACDP-0019
|
|
205
|
+
`acdp:mcp-tool-result`. That record describes an MCP proxy's view of an MCP
|
|
206
|
+
server (`serverInfo`, transport, endpoint hash), and an in-process hook can't
|
|
207
|
+
see any of it, especially for built-in tools.
|
|
208
|
+
|
|
209
|
+
### `derived_from`
|
|
210
|
+
|
|
211
|
+
Every body links to the `ctx_id`s the run consumed:
|
|
212
|
+
|
|
213
|
+
- **Declared inputs**: `ledger.consume(ctx_id, verified=…)`, for example a
|
|
214
|
+
context your app placed in the prompt.
|
|
215
|
+
- **Cited in a tool's arguments**: picked up by the RFC-ACDP-0019 §4.4 walk
|
|
216
|
+
(JCS order, whole-string matches only).
|
|
217
|
+
- **Seen in a tool's result**: any `acdp://` id embedded in what a tool
|
|
218
|
+
returned. It counts as an input to everything the run does *afterwards*, not
|
|
219
|
+
to that tool's own body.
|
|
220
|
+
- **The run's own tool results**: the final-output body also derives from every
|
|
221
|
+
tool-result body published during the run.
|
|
222
|
+
|
|
223
|
+
The list keeps first occurrences in that order and is capped at 1000, the
|
|
224
|
+
RFC-ACDP-0002 maximum.
|
|
225
|
+
|
|
226
|
+
### Visibility
|
|
227
|
+
|
|
228
|
+
The default is `public`. With salted hashes, a public body shows only *that*
|
|
229
|
+
the producer called a named tool at a given time; it never shows what went in
|
|
230
|
+
or came out. If even that is sensitive, set `visibility="private"`. In that
|
|
231
|
+
case only callers the registry authorises can resolve the link.
|
|
232
|
+
RFC-ACDP-0019 §8.3 reasons the same way. The configured value is used as is; a
|
|
233
|
+
rejected publish is never retried with a wider visibility.
|
|
234
|
+
|
|
235
|
+
## Publish failure policy
|
|
236
|
+
|
|
237
|
+
**The default is fail-open.** A hook that can't publish lets the agent carry
|
|
238
|
+
on, and the failure is recorded in three places: `ledger.failures`, the
|
|
239
|
+
`acdp.publish.error` span attribute and a `WARNING` on the `acdp_hooks` logger.
|
|
240
|
+
Provenance is an observer of the agent and shouldn't take production agents
|
|
241
|
+
down when a registry is unreachable. RFC-ACDP-0019 §7 uses the same default.
|
|
242
|
+
|
|
243
|
+
Set `fail_policy="closed"` when nothing should leave the run without
|
|
244
|
+
provenance:
|
|
245
|
+
|
|
246
|
+
| | Fail-open (default) | Fail-closed |
|
|
247
|
+
|---|---|---|
|
|
248
|
+
| Claude, tool result | result passes through unchanged | result replaced by a "withheld" message (`updatedToolOutput` / `updatedMCPToolOutput`, `decision: block`) |
|
|
249
|
+
| Claude, `Stop` | nothing changes | `continue_: false` with a `stopReason` |
|
|
250
|
+
| Claude, `publish_final_output` | returns `None` | raises `PublishError` |
|
|
251
|
+
| OpenAI, any hook | the run continues | raises `PublishError`, which stops the run |
|
|
252
|
+
|
|
253
|
+
A publish counts as failed when the registry returns an error, when the body
|
|
254
|
+
can't be built (for example, metadata over 64 KB), or when retries run out:
|
|
255
|
+
`retries` extra attempts with exponential backoff, each with a `timeout_s`
|
|
256
|
+
limit. Retries resend the same bytes under
|
|
257
|
+
`Idempotency-Key: acdp-hooks-<content hash>`, so a retry never publishes twice.
|
|
258
|
+
`PublishError.code` holds the registry's RFC-ACDP-0007 error code, or
|
|
259
|
+
`transport` when no ACDP error was returned.
|
|
260
|
+
|
|
261
|
+
## OpenTelemetry
|
|
262
|
+
|
|
263
|
+
Install the `otel` extra (`opentelemetry-api`) and configure a tracer provider
|
|
264
|
+
as usual. Without the extra, every OTel call is a no-op.
|
|
265
|
+
|
|
266
|
+
- **`acdp.publish` span.** Each publish opens a child span under the active
|
|
267
|
+
span. It gets `acdp.ctx_id`, `acdp.lineage_id`, `acdp.version`,
|
|
268
|
+
`acdp.content_hash`, `acdp.producer`, `acdp.registry`, `acdp.type` and
|
|
269
|
+
`acdp.derived_from`; on failure it gets `acdp.publish.error` instead of the
|
|
270
|
+
identifiers. Giving each body its own span keeps several tool results under
|
|
271
|
+
one agent span from overwriting each other's `acdp.ctx_id`.
|
|
272
|
+
- **The active span** (the work that used the inputs) gets
|
|
273
|
+
`acdp.input.ctx_ids`. When you reported verification through
|
|
274
|
+
`consume(..., verified=…)`, it also gets `acdp.input.verified`, which is
|
|
275
|
+
`true` only if every input was reported verified.
|
|
276
|
+
- `acdp_hooks.annotate_chain_verdict(verdict)` copies an RFC-ACDP-0017 chain
|
|
277
|
+
verdict's `chain.latest`, `chain.as_of` and `verdict_digest` onto the active
|
|
278
|
+
span (`acdp.input.chain_verdict*`, `acdp.input.verdict_digest`).
|
|
279
|
+
|
|
280
|
+
Values are copied from the wire without changes. A name outside the registry
|
|
281
|
+
raises an error instead of being emitted. Body content, arguments, results and
|
|
282
|
+
salts never go into an attribute. CI checks the name list against the pinned
|
|
283
|
+
spec checkout.
|
|
284
|
+
|
|
285
|
+
## Development
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
uv venv && uv pip install -e ".[claude,openai,otel,dev]"
|
|
289
|
+
ruff format --check . && ruff check . && mypy
|
|
290
|
+
coverage run -m pytest && coverage report # unit tests, coverage-gated
|
|
291
|
+
|
|
292
|
+
# integration: a local acdp-registry-rs (docker) …
|
|
293
|
+
docker compose -f tests/integration/compose.yml up -d --wait
|
|
294
|
+
ACDP_IT_REGISTRY=http://localhost:8443 pytest -m integration
|
|
295
|
+
# … or production (publishes public bodies under a throwaway did:key)
|
|
296
|
+
ACDP_IT_REGISTRY=https://registry.agentcontextdistributionprotocol.io pytest -m integration
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
CI follows the [ACDP Delivery Standard](https://github.com/agentcontextdistributionprotocol/acdp-ci/blob/main/DELIVERY-STANDARD.md):
|
|
300
|
+
format, lint, `mypy --strict`, a coverage gate, a no-extras install, a build
|
|
301
|
+
with `twine check`, and the integration suite against a local registry
|
|
302
|
+
container. `main` is protected by `acdp-ci/scripts/standardize.sh`.
|
|
303
|
+
|
|
304
|
+
## Releasing
|
|
305
|
+
|
|
306
|
+
Bump `version` in `pyproject.toml` and `__version__` in
|
|
307
|
+
`src/acdp_hooks/__init__.py`, update `CHANGELOG.md`, merge, then push a
|
|
308
|
+
`v<version>` tag. `release.yml` builds the package, attests provenance and
|
|
309
|
+
publishes to PyPI through **Trusted Publishing**, so no token is stored. The
|
|
310
|
+
PyPI trusted publisher names this repo, `release.yml` and the `pypi`
|
|
311
|
+
environment.
|
|
312
|
+
|
|
313
|
+
TypeScript packages will follow.
|
|
314
|
+
|
|
315
|
+
## License
|
|
316
|
+
|
|
317
|
+
Apache-2.0
|