aer1-haystack 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.
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.4
2
+ Name: aer1-haystack
3
+ Version: 0.1.0
4
+ Summary: One-line verifiable execution receipts for Haystack pipelines. Free, no API key, offline verification, chain-head anchoring to Nostr and Bitcoin.
5
+ License: Apache-2.0
6
+ Project-URL: Homepage, https://zambo.dev
7
+ Project-URL: IETF Draft, https://datatracker.ietf.org/doc/draft-zambo-aer1/
8
+ Keywords: aer-1,haystack,ai-agents,verifiable-receipts,audit,tracing,mcp,zambo,audit-trail
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: haystack-ai>=2.0.0
16
+ Provides-Extra: anchor
17
+ Requires-Dist: coincurve>=18.0; extra == "anchor"
18
+ Requires-Dist: websocket-client>=1.7; extra == "anchor"
19
+
20
+ # aer1-haystack
21
+
22
+ One-line install, no API key, free forever: wrap one pipeline and every [Haystack](https://github.com/deepset-ai/haystack) 2.x run emits a hash-chained, offline-verifiable **verifiable workflow receipt** (AER-1, an IETF Internet-Draft, Section 8). What each component did, in what order, with per-step hashes and a Merkle root over the whole run. No network calls, no behavior changes, the collector only observes. Receipt chain heads can anchor to Nostr and Bitcoin, so anyone can later confirm the record was not changed, without trusting any server.
23
+
24
+ ## The AER-1 framework collector family
25
+
26
+ The Haystack collector in the AER-1 framework collector family. Any agent running on these frameworks can emit verifiable AER-1 execution receipts: every step recorded, hash-chained, one Merkle root over the whole run.
27
+
28
+ - [aer1-haystack](https://pypi.org/project/aer1-haystack/), Haystack 2.x pipelines via run wrapping
29
+ - [aer1-langchain](https://pypi.org/project/aer1-langchain/), LangChain chains, agents, tools, and retrievers via callback handler
30
+ - [aer1-llamaindex](https://pypi.org/project/aer1-llamaindex/), LlamaIndex agents via callback handler
31
+ - [aer1-smolagents](https://pypi.org/project/aer1-smolagents/), SmolAgents agents via step callbacks
32
+ - [aer1-openai-agents](https://pypi.org/project/aer1-openai-agents/), the OpenAI Agents SDK via its TracingProcessor
33
+ - [aer1-crewai](https://pypi.org/project/aer1-crewai/), CrewAI crews via the event bus
34
+ - [aer1-langgraph](https://pypi.org/project/aer1-langgraph/), LangGraph swarms via callback handler
35
+ - [aer1-autogen](https://pypi.org/project/aer1-autogen/), AutoGen multi-agent chats
36
+ - [aer1-pydantic](https://pypi.org/project/aer1-pydantic/), Pydantic AI agents via run wrapping and manual tool-call recording
37
+ - [aer1-strands](https://pypi.org/project/aer1-strands/), Strands Agents via the typed hook system
38
+
39
+ See the [AER-1 implementation registry](https://rambozambodotdev.gitlab.io/registry.html) for every implementation.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install aer1-haystack
45
+ ```
46
+
47
+ ## Use it (copy, paste, run, no API keys needed)
48
+
49
+ ```python
50
+ # pip install aer1-haystack
51
+ from haystack import Pipeline, component
52
+ from aer1_haystack import AER1ReceiptCollector
53
+
54
+
55
+ @component
56
+ class Adder:
57
+ @component.output_types(total=int)
58
+ def run(self, a: int, b: int):
59
+ return {"total": a + b}
60
+
61
+
62
+ @component
63
+ class Doubler:
64
+ @component.output_types(doubled=int)
65
+ def run(self, total: int):
66
+ return {"doubled": total * 2}
67
+
68
+
69
+ pipeline = Pipeline()
70
+ pipeline.add_component("adder", Adder())
71
+ pipeline.add_component("doubler", Doubler())
72
+ pipeline.connect("adder.total", "doubler.total")
73
+
74
+ collector = AER1ReceiptCollector(goal="add and double")
75
+ collector.wrap_pipeline(pipeline) # line 1: pipeline.run is now observed
76
+
77
+ result = pipeline.run({"adder": {"a": 2, "b": 3}})
78
+ receipt = collector.finalize(final_answer=result) # line 2
79
+ assert collector.verify(receipt) == [] # VALID
80
+ collector.save("receipt.json", workflow=receipt)
81
+ ```
82
+
83
+ That is the whole integration: wrap the pipeline, run, finalize.
84
+ The receipt is a plain JSON object you can store, ship to an auditor,
85
+ or render in a UI.
86
+
87
+ ## What the receipt contains
88
+
89
+ Workflow level (AER-1 Section 8, Table 2):
90
+
91
+ - `type`, `version`, `workflow_id`, `receipt_id`, `session_id`
92
+ - `goal`, `status`
93
+ - `steps`: one record per component, seq 1..n in order
94
+ - `merkle_root`: Section 8.1 root over the ordered step receipt ids
95
+ - `output_hash`: SHA-256 of the final answer
96
+ - `verify_url`: where the verification procedure is documented
97
+
98
+ Step level (AER-1 Section 8, Table 3):
99
+
100
+ - `seq`, `receipt_id`, `tool`, `receipt_hash`, `started_at`, `ended_at`, `status`
101
+
102
+ Each step `receipt_hash` is SHA-256 over the canonical JSON of what the
103
+ component actually did: component name, input values, output values, and
104
+ error if any. The hash commits to the content; the receipt stays compact.
105
+ The wrapper asks the pipeline to include every component's outputs
106
+ (`include_outputs_from`), so intermediate components are recorded, not
107
+ just leaf outputs.
108
+
109
+ ## Verification
110
+
111
+ `collector.verify(receipt)` runs the full offline check and returns a
112
+ list of failure reasons, empty when valid:
113
+
114
+ - all Table 2 / Table 3 members present and well-formed
115
+ - `seq` values exactly 1..n in order, no gaps
116
+ - no two steps share a `receipt_id` (MM-1)
117
+ - `merkle_root` matches the recomputed Section 8.1 root
118
+ - strict RFC 3339 timestamps, lowercase UUIDs, 64-char hex digests
119
+
120
+ Tamper with any field and verification fails. Try it:
121
+
122
+ ```python
123
+ receipt["steps"][0]["tool"] = ""
124
+ assert collector.verify(receipt) != [] # fails, as it should
125
+ ```
126
+
127
+ ## Manual instrumentation
128
+
129
+ For components that need finer control, skip `wrap_pipeline` and record
130
+ steps from inside a component's own `run()` method:
131
+
132
+ ```python
133
+ collector = AER1ReceiptCollector(goal="manual run")
134
+
135
+ @component
136
+ class LoudAdder:
137
+ @component.output_types(total=int)
138
+ def run(self, a: int, b: int):
139
+ out = {"total": a + b}
140
+ collector.record_component(
141
+ "loud_adder", inputs={"a": a, "b": b}, outputs=out)
142
+ return out
143
+ ```
144
+
145
+ `record_component(name, inputs, outputs, error=None)` takes the
146
+ component name as the step's tool field. If the wrapped `pipeline.run`
147
+ raises, a single error step named `pipeline` is recorded and the
148
+ exception is re-raised unchanged.
149
+
150
+ ## Notes
151
+
152
+ - Works with any Haystack 2.x `Pipeline`. The collector never touches
153
+ the network and never changes pipeline behavior; it only observes.
154
+ - Pass `goal=` to the collector; it becomes the receipt's goal field.
155
+ - `session_id` defaults to a fresh UUID per collector; pass your own to
156
+ correlate receipts across runs.
157
+ - `verify_url` defaults to the AER-1 specification page; point it at
158
+ your own verifier in production.
159
+ - Steps accumulate across runs on the same wrapped pipeline; call
160
+ `collector.reset()` between runs to start fresh.
161
+
162
+ ## Spec
163
+
164
+ AER-1: Agent Execution Receipts, `draft-zambo-aer1` (IETF Internet-Draft),
165
+ https://datatracker.ietf.org/doc/draft-zambo-aer1/
166
+
167
+ ## See it live
168
+
169
+ Your receipt is offline-verifiable, but you can also check it on the live verifier:
170
+
171
+ 1. Copy the receipt JSON your code produced
172
+ 2. Paste it at https://zambo.dev/verify
173
+ 3. See the verification result with the Merkle root and step hashes
174
+
175
+ Or mint a live receipt directly: run any call at https://zambo.dev/demo and get a shareable receipt URL like https://zambo.dev/run/<id>.
176
+
177
+ ## License
178
+
179
+ Apache-2.0
@@ -0,0 +1,160 @@
1
+ # aer1-haystack
2
+
3
+ One-line install, no API key, free forever: wrap one pipeline and every [Haystack](https://github.com/deepset-ai/haystack) 2.x run emits a hash-chained, offline-verifiable **verifiable workflow receipt** (AER-1, an IETF Internet-Draft, Section 8). What each component did, in what order, with per-step hashes and a Merkle root over the whole run. No network calls, no behavior changes, the collector only observes. Receipt chain heads can anchor to Nostr and Bitcoin, so anyone can later confirm the record was not changed, without trusting any server.
4
+
5
+ ## The AER-1 framework collector family
6
+
7
+ The Haystack collector in the AER-1 framework collector family. Any agent running on these frameworks can emit verifiable AER-1 execution receipts: every step recorded, hash-chained, one Merkle root over the whole run.
8
+
9
+ - [aer1-haystack](https://pypi.org/project/aer1-haystack/), Haystack 2.x pipelines via run wrapping
10
+ - [aer1-langchain](https://pypi.org/project/aer1-langchain/), LangChain chains, agents, tools, and retrievers via callback handler
11
+ - [aer1-llamaindex](https://pypi.org/project/aer1-llamaindex/), LlamaIndex agents via callback handler
12
+ - [aer1-smolagents](https://pypi.org/project/aer1-smolagents/), SmolAgents agents via step callbacks
13
+ - [aer1-openai-agents](https://pypi.org/project/aer1-openai-agents/), the OpenAI Agents SDK via its TracingProcessor
14
+ - [aer1-crewai](https://pypi.org/project/aer1-crewai/), CrewAI crews via the event bus
15
+ - [aer1-langgraph](https://pypi.org/project/aer1-langgraph/), LangGraph swarms via callback handler
16
+ - [aer1-autogen](https://pypi.org/project/aer1-autogen/), AutoGen multi-agent chats
17
+ - [aer1-pydantic](https://pypi.org/project/aer1-pydantic/), Pydantic AI agents via run wrapping and manual tool-call recording
18
+ - [aer1-strands](https://pypi.org/project/aer1-strands/), Strands Agents via the typed hook system
19
+
20
+ See the [AER-1 implementation registry](https://rambozambodotdev.gitlab.io/registry.html) for every implementation.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install aer1-haystack
26
+ ```
27
+
28
+ ## Use it (copy, paste, run, no API keys needed)
29
+
30
+ ```python
31
+ # pip install aer1-haystack
32
+ from haystack import Pipeline, component
33
+ from aer1_haystack import AER1ReceiptCollector
34
+
35
+
36
+ @component
37
+ class Adder:
38
+ @component.output_types(total=int)
39
+ def run(self, a: int, b: int):
40
+ return {"total": a + b}
41
+
42
+
43
+ @component
44
+ class Doubler:
45
+ @component.output_types(doubled=int)
46
+ def run(self, total: int):
47
+ return {"doubled": total * 2}
48
+
49
+
50
+ pipeline = Pipeline()
51
+ pipeline.add_component("adder", Adder())
52
+ pipeline.add_component("doubler", Doubler())
53
+ pipeline.connect("adder.total", "doubler.total")
54
+
55
+ collector = AER1ReceiptCollector(goal="add and double")
56
+ collector.wrap_pipeline(pipeline) # line 1: pipeline.run is now observed
57
+
58
+ result = pipeline.run({"adder": {"a": 2, "b": 3}})
59
+ receipt = collector.finalize(final_answer=result) # line 2
60
+ assert collector.verify(receipt) == [] # VALID
61
+ collector.save("receipt.json", workflow=receipt)
62
+ ```
63
+
64
+ That is the whole integration: wrap the pipeline, run, finalize.
65
+ The receipt is a plain JSON object you can store, ship to an auditor,
66
+ or render in a UI.
67
+
68
+ ## What the receipt contains
69
+
70
+ Workflow level (AER-1 Section 8, Table 2):
71
+
72
+ - `type`, `version`, `workflow_id`, `receipt_id`, `session_id`
73
+ - `goal`, `status`
74
+ - `steps`: one record per component, seq 1..n in order
75
+ - `merkle_root`: Section 8.1 root over the ordered step receipt ids
76
+ - `output_hash`: SHA-256 of the final answer
77
+ - `verify_url`: where the verification procedure is documented
78
+
79
+ Step level (AER-1 Section 8, Table 3):
80
+
81
+ - `seq`, `receipt_id`, `tool`, `receipt_hash`, `started_at`, `ended_at`, `status`
82
+
83
+ Each step `receipt_hash` is SHA-256 over the canonical JSON of what the
84
+ component actually did: component name, input values, output values, and
85
+ error if any. The hash commits to the content; the receipt stays compact.
86
+ The wrapper asks the pipeline to include every component's outputs
87
+ (`include_outputs_from`), so intermediate components are recorded, not
88
+ just leaf outputs.
89
+
90
+ ## Verification
91
+
92
+ `collector.verify(receipt)` runs the full offline check and returns a
93
+ list of failure reasons, empty when valid:
94
+
95
+ - all Table 2 / Table 3 members present and well-formed
96
+ - `seq` values exactly 1..n in order, no gaps
97
+ - no two steps share a `receipt_id` (MM-1)
98
+ - `merkle_root` matches the recomputed Section 8.1 root
99
+ - strict RFC 3339 timestamps, lowercase UUIDs, 64-char hex digests
100
+
101
+ Tamper with any field and verification fails. Try it:
102
+
103
+ ```python
104
+ receipt["steps"][0]["tool"] = ""
105
+ assert collector.verify(receipt) != [] # fails, as it should
106
+ ```
107
+
108
+ ## Manual instrumentation
109
+
110
+ For components that need finer control, skip `wrap_pipeline` and record
111
+ steps from inside a component's own `run()` method:
112
+
113
+ ```python
114
+ collector = AER1ReceiptCollector(goal="manual run")
115
+
116
+ @component
117
+ class LoudAdder:
118
+ @component.output_types(total=int)
119
+ def run(self, a: int, b: int):
120
+ out = {"total": a + b}
121
+ collector.record_component(
122
+ "loud_adder", inputs={"a": a, "b": b}, outputs=out)
123
+ return out
124
+ ```
125
+
126
+ `record_component(name, inputs, outputs, error=None)` takes the
127
+ component name as the step's tool field. If the wrapped `pipeline.run`
128
+ raises, a single error step named `pipeline` is recorded and the
129
+ exception is re-raised unchanged.
130
+
131
+ ## Notes
132
+
133
+ - Works with any Haystack 2.x `Pipeline`. The collector never touches
134
+ the network and never changes pipeline behavior; it only observes.
135
+ - Pass `goal=` to the collector; it becomes the receipt's goal field.
136
+ - `session_id` defaults to a fresh UUID per collector; pass your own to
137
+ correlate receipts across runs.
138
+ - `verify_url` defaults to the AER-1 specification page; point it at
139
+ your own verifier in production.
140
+ - Steps accumulate across runs on the same wrapped pipeline; call
141
+ `collector.reset()` between runs to start fresh.
142
+
143
+ ## Spec
144
+
145
+ AER-1: Agent Execution Receipts, `draft-zambo-aer1` (IETF Internet-Draft),
146
+ https://datatracker.ietf.org/doc/draft-zambo-aer1/
147
+
148
+ ## See it live
149
+
150
+ Your receipt is offline-verifiable, but you can also check it on the live verifier:
151
+
152
+ 1. Copy the receipt JSON your code produced
153
+ 2. Paste it at https://zambo.dev/verify
154
+ 3. See the verification result with the Merkle root and step hashes
155
+
156
+ Or mint a live receipt directly: run any call at https://zambo.dev/demo and get a shareable receipt URL like https://zambo.dev/run/<id>.
157
+
158
+ ## License
159
+
160
+ Apache-2.0
@@ -0,0 +1,39 @@
1
+ """aer1-haystack: AER-1 verifiable workflow receipts for Haystack."""
2
+
3
+ from .anchor import (
4
+ AnchorError,
5
+ NostrBackend,
6
+ OTSBackend,
7
+ anchor_chain_head,
8
+ bip340_verify,
9
+ proof_from_json,
10
+ proof_to_json,
11
+ verify_anchor,
12
+ )
13
+ from .collector import (
14
+ AER1ReceiptCollector,
15
+ DEFAULT_VERIFY_URL,
16
+ WORKFLOW_TYPE,
17
+ WORKFLOW_VERSION,
18
+ merkle_root,
19
+ verify_workflow_receipt,
20
+ )
21
+
22
+ __all__ = [
23
+ "AER1ReceiptCollector",
24
+ "DEFAULT_VERIFY_URL",
25
+ "WORKFLOW_TYPE",
26
+ "WORKFLOW_VERSION",
27
+ "AnchorError",
28
+ "NostrBackend",
29
+ "OTSBackend",
30
+ "anchor_chain_head",
31
+ "bip340_verify",
32
+ "merkle_root",
33
+ "proof_from_json",
34
+ "proof_to_json",
35
+ "verify_anchor",
36
+ "verify_workflow_receipt",
37
+ ]
38
+
39
+ __version__ = "0.1.0"