ica-capture 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,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,226 @@
1
+ Metadata-Version: 2.4
2
+ Name: ica-capture
3
+ Version: 0.1.0
4
+ Summary: Emit AI agent steps to ICA. ICA signs and governs them. A tool guard, tool hooks, a callback recorder and an approval pause for agent frameworks (the framework is a setting), MCP, plus outside eval intake.
5
+ Author: ALEETH
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://aleeth.com
8
+ Keywords: ai,agents,governance,audit,approvals,tool-guard,mcp,evals,ica
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Provides-Extra: callbacks
13
+ Requires-Dist: langchain-core>=0.2; extra == "callbacks"
14
+ Dynamic: license-file
15
+
16
+ # ICA Capture SDK (Python)
17
+
18
+ Emit your AI agent's steps to ICA in one line. ICA does the rest: it mints a
19
+ signed, append-only receipt for every step, scores the run into continuous
20
+ posture, and can halt an agent that crosses a control. You sign nothing and hold
21
+ no key.
22
+
23
+ A receipt of what ran is the floor. ICA also decides what is allowed to run: a
24
+ gated call waits for ICA's decision before the tool body executes, a call held
25
+ for people waits for their approval, and an agent that crosses a control can be
26
+ halted. Each decision ICA seals carries a signed receipt that anyone can
27
+ re-check later.
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pip install ica-capture # core, zero dependencies
33
+ pip install "ica-capture[callbacks]" # adds the framework callback recorder
34
+ ```
35
+
36
+ ## Configure
37
+
38
+ ```python
39
+ from ica import IcaClient
40
+
41
+ ica = IcaClient(
42
+ token="YOUR_ICA_INGEST_TOKEN", # X-ICA-Ingest-Token
43
+ agent_handle="your-agent", # resolves to your registered identity
44
+ )
45
+ ```
46
+
47
+ Your ingest credential names your tenant, so `customer_id` is optional. If you
48
+ pass it, it must be the same tenant: ICA refuses any other (403
49
+ `ingest_tenant_mismatch`).
50
+
51
+ Telemetry never breaks your agent. Emit failures are swallowed by default; pass
52
+ `raise_on_error=True` while you are wiring things up.
53
+
54
+ ## Three drop-in surfaces
55
+
56
+ ### Callback recorder (one line)
57
+
58
+ ```python
59
+ from ica.callbacks import IcaCallbackHandler
60
+
61
+ agent.invoke(payload, config={"callbacks": [IcaCallbackHandler(ica)]})
62
+ ```
63
+
64
+ Every tool call, ok or error, is recorded with timing, through the agent framework's own callback surface
65
+ (install the `[callbacks]` extra).
66
+
67
+ ### Decorator
68
+
69
+ ```python
70
+ from ica import ica_tool
71
+
72
+ @ica_tool(ica, reversibility_tag="reversible")
73
+ def search(query):
74
+ ...
75
+ ```
76
+
77
+ ### MCP or any callable
78
+
79
+ ```python
80
+ from ica import wrap_mcp_tool
81
+
82
+ guarded = wrap_mcp_tool(ica, raw_tool_call, name="filesystem.read")
83
+ ```
84
+
85
+ ### Manual
86
+
87
+ ```python
88
+ ica.record_tool_call(
89
+ tool_name="web.search",
90
+ tool_input={"query": "..."},
91
+ tool_output={"hits": 3},
92
+ duration_ms=142,
93
+ )
94
+ ```
95
+
96
+ ## What ICA does with it
97
+
98
+ Each step posts to `POST /api/ingest/agent-step`. On arrival ICA:
99
+
100
+ 1. Mints an L7 receipt over the step, signed server-side. You never touch a key.
101
+ 2. Appends it to an append-only, tamper-evident audit trail.
102
+ 3. Feeds it to the assessment engine: decision control, containment,
103
+ reversibility, observability, continuous posture.
104
+ 4. Enforces. A step that bypasses a gate or runs an irreversible action ungated
105
+ is flagged, and a halted agent is quarantined at ingest.
106
+
107
+ Verify any receipt without publishing your data. Public chains are optional, not
108
+ required, and never the default.
109
+
110
+ ## Step fields
111
+
112
+ | Field | Notes |
113
+ |-------|-------|
114
+ | `step_type` | `reasoning`, `tool_call`, `sub_agent_dispatch`, `final_answer`, `gate_request`, `gate_response` |
115
+ | `tool_name` | the tool invoked |
116
+ | `tool_input` / `tool_output` | JSON-safe; coerced if needed |
117
+ | `reversibility_tag` | `reversible`, `partial`, `irreversible`, `unclassified` |
118
+ | `gate_state` | `not_gated`, `pending`, `approved`, `denied`, `bypassed` |
119
+ | `duration_ms`, `tokens_used` | optional metrics |
120
+
121
+ ## Tool guard and tool hooks
122
+
123
+ For a graph whose held calls should wait for people, use `ica.approval_pause` (below): a held call pauses the
124
+ graph instead of ending it, and the block is hard. The callback recorder above still records graph runs. Two
125
+ more, neither of which adds a dependency. The agent framework is a setting, never a module name:
126
+
127
+ | Use | `framework=` | Hard block with `gate=True` |
128
+ |---|---|---|
129
+ | `from ica.tool_guard import guard_tools`; `tools = guard_tools(ica, tools, framework=..., gate=True)` | `"openai_agents"` | yes: wraps each dataclass function tool's `on_invoke_tool` |
130
+ | the same | `"crewai"` | yes: wraps each tool's `_run` |
131
+ | the same | `"llamaindex"` | yes: wraps `FunctionTool` `_fn` and `_async_fn` |
132
+ | `from ica.tool_hooks import IcaHooks`; `Agent(tools=..., hooks=[IcaHooks(ica, gate=True)])` | (frameworks that call tool hooks) | yes: a deny sets `cancel_tool` |
133
+
134
+ An unknown `framework=` raises `ValueError`, so a typo never leaves tools unguarded. A tool of another shape is
135
+ returned unchanged.
136
+
137
+ ## Stated confidence
138
+
139
+ An agent can tell ICA how sure it is of each gated call, as a number from 0 to 1. When the agent's scope
140
+ contract sets a confidence floor (`operating_envelope.confidence_floor`), ICA holds a call below the floor,
141
+ or one that states nothing, for a person: `gate()` answers `pending` and the tool does not run. A high
142
+ number never loosens anything; every other check still decides.
143
+
144
+ - `ica.gate(action, tool_name=..., stated_confidence=0.82)` sends it on one call.
145
+ - Every adapter and decorator takes `confidence=`: a number, or a function `(tool_name, payload) -> number`
146
+ that reads the model's own statement (for example a `confidence` field your tool schema asks the model to
147
+ fill). A function that raises states nothing, so with a floor set the call is held.
148
+
149
+ ```python
150
+ tools = guard_tools(ica, tools, framework="crewai", gate=True, confidence=lambda name, payload: payload.get("kwargs", {}).get("confidence"))
151
+ ```
152
+
153
+ ## Approval pause: a held call pauses the graph
154
+
155
+ Every other adapter treats a call ICA holds for a person (`pending`) as a deny: the run ends. In a graph runtime
156
+ with `interrupt()` and a checkpointer the graph can wait instead.
157
+
158
+ ```python
159
+ from langchain_core.tools import tool
160
+ from langgraph.checkpoint.memory import MemorySaver
161
+ from langgraph.prebuilt import ToolNode
162
+ from ica.approval_pause import ica_approval_pause_tool, route_tool_calls
163
+
164
+ @tool
165
+ @ica_approval_pause_tool(ica, reversibility_tag="irreversible")
166
+ def update_claim(claim_id: int, amount: int) -> str:
167
+ ...
168
+
169
+ builder.add_node("tools", ToolNode([update_claim]))
170
+ builder.add_conditional_edges("agent", route_tool_calls, ["tools", END]) # one task per tool call
171
+ graph = builder.compile(checkpointer=MemorySaver()) # pausing needs a checkpointer
172
+ ```
173
+
174
+ - Approved: the tool runs and its step carries the single-use token. Denied: `GateDenied`, the tool never runs.
175
+ - Held: ICA raises a two-person approval request bound to the exact arguments, and the graph pauses
176
+ (`interrupt()`); the payload carries `approval_request_id`. Two named people approve it in the ICA console.
177
+ Resume with `Command(resume=...)` (one value per pending interrupt when several pause at once). The resume
178
+ value is only a wake-up: the tool asks ICA, and runs only when ICA releases a token for that call. Still
179
+ pending, or ICA briefly unreachable: it pauses again. Denied, expired, arguments changed, or the agent halted,
180
+ retired or cert-blocked since the approval: `GateDenied`. Already released (a re-run after it ran): it does
181
+ not run again and returns a message saying so.
182
+ - One tool call per task. A resumed graph task runs again from the top, and a plain `ToolNode` wired on the
183
+ messages list runs every call of a turn in one task, so the other calls of that turn would run again when one
184
+ pauses. Use `route_tool_calls` (above) or `create_react_agent` (its default version "v2" already sends each
185
+ call on its own). Tested with the graph runtime package at 1.2.14 (tests/test_approval_pause_real.py): with the routing, an approved call beside a held one runs once;
186
+ without it, twice.
187
+ - Needs a per-customer ingest credential: only the credential that raised a request can collect it, and a
188
+ shared token raises none. A tenant that approves with one person gets no request either: this path releases
189
+ only on two named approvals. Outside a graph run nothing is requested and a hold ends the call, as before.
190
+ - A request waits up to an hour for a person, an approval must be collected within an hour of being given, and a
191
+ credential can have at most 25 requests waiting. Arguments holding an integer past 2^53 are refused (JSON cannot
192
+ carry it exactly): send such ids as strings.
193
+ - Each resume re-asks the gate (one more sealed `pending` decision). A `hold_key` derived from the thread and
194
+ task makes the re-ask find the same request. Pass `key_fn=` to name calls yourself.
195
+ - Under it: `ica.gate(..., request_approval=True, args=..., hold_key=...)` and `ica.release(approval_request_id,
196
+ args)`, which any framework can use.
197
+
198
+ ## Signed proof in your agent's trace
199
+
200
+ Every gate decision ICA seals comes back with its signed receipt. Give the client an `on_proof` function and that proof lands
201
+ in your agent's own trace, beside the tool call it decided:
202
+
203
+ ```python
204
+ ica = IcaClient(token="...", agent_handle="pay-bot", on_proof=add_to_current_run)
205
+ ```
206
+
207
+ `add_to_current_run(proof)` is yours: add the dict to the current run's metadata in whatever tracing tool you use. The dict
208
+ is flat strings: `ica_receipt_hash`, `ica_verify_url`, `ica_decision`, `ica_gate_id`, `ica_signing_key_id`, `ica_tool`.
209
+ Anyone holding the hash re-checks the decision at the verify URL (public, no sign-in) or offline against ICA's published
210
+ keys, without trusting your tracer or ALEETH. Every adapter above that gates (`gate=True`, the tool guard, the tool hooks,
211
+ the approval pause) goes through `gate()`, so it carries the proof; the same dict is on the verdict as `verdict["proof"]`,
212
+ and `proof_of(verdict)` builds it from any gate answer. A decision ICA could not seal gives no proof. A function that raises
213
+ never changes the decision (it raises only with `raise_on_error=True`). A step recorded without a gate is signed just after
214
+ ICA answers, so its receipt is not in that answer.
215
+
216
+ ## Outside eval results
217
+
218
+ `from ica.evals import record_eval`, then `record_eval(ica, result, framework="ragas", run_name=..., thresholds={...})`.
219
+ Reads Ragas, DeepEval, Giskard, TruLens, promptfoo and plain `{metric: score}` results, and files the
220
+ summary (per-metric mean, min, max, count, pass and fail counts, failed thresholds, never the eval's
221
+ prompts or answers) as one step on the agent's ICA record, where it is sealed like every other step.
222
+
223
+ ## License
224
+
225
+ This SDK is licensed under the Apache License 2.0 (see LICENSE). Using ICA needs an ingest token: contact ALEETH
226
+ (https://aleeth.com).
@@ -0,0 +1,211 @@
1
+ # ICA Capture SDK (Python)
2
+
3
+ Emit your AI agent's steps to ICA in one line. ICA does the rest: it mints a
4
+ signed, append-only receipt for every step, scores the run into continuous
5
+ posture, and can halt an agent that crosses a control. You sign nothing and hold
6
+ no key.
7
+
8
+ A receipt of what ran is the floor. ICA also decides what is allowed to run: a
9
+ gated call waits for ICA's decision before the tool body executes, a call held
10
+ for people waits for their approval, and an agent that crosses a control can be
11
+ halted. Each decision ICA seals carries a signed receipt that anyone can
12
+ re-check later.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ pip install ica-capture # core, zero dependencies
18
+ pip install "ica-capture[callbacks]" # adds the framework callback recorder
19
+ ```
20
+
21
+ ## Configure
22
+
23
+ ```python
24
+ from ica import IcaClient
25
+
26
+ ica = IcaClient(
27
+ token="YOUR_ICA_INGEST_TOKEN", # X-ICA-Ingest-Token
28
+ agent_handle="your-agent", # resolves to your registered identity
29
+ )
30
+ ```
31
+
32
+ Your ingest credential names your tenant, so `customer_id` is optional. If you
33
+ pass it, it must be the same tenant: ICA refuses any other (403
34
+ `ingest_tenant_mismatch`).
35
+
36
+ Telemetry never breaks your agent. Emit failures are swallowed by default; pass
37
+ `raise_on_error=True` while you are wiring things up.
38
+
39
+ ## Three drop-in surfaces
40
+
41
+ ### Callback recorder (one line)
42
+
43
+ ```python
44
+ from ica.callbacks import IcaCallbackHandler
45
+
46
+ agent.invoke(payload, config={"callbacks": [IcaCallbackHandler(ica)]})
47
+ ```
48
+
49
+ Every tool call, ok or error, is recorded with timing, through the agent framework's own callback surface
50
+ (install the `[callbacks]` extra).
51
+
52
+ ### Decorator
53
+
54
+ ```python
55
+ from ica import ica_tool
56
+
57
+ @ica_tool(ica, reversibility_tag="reversible")
58
+ def search(query):
59
+ ...
60
+ ```
61
+
62
+ ### MCP or any callable
63
+
64
+ ```python
65
+ from ica import wrap_mcp_tool
66
+
67
+ guarded = wrap_mcp_tool(ica, raw_tool_call, name="filesystem.read")
68
+ ```
69
+
70
+ ### Manual
71
+
72
+ ```python
73
+ ica.record_tool_call(
74
+ tool_name="web.search",
75
+ tool_input={"query": "..."},
76
+ tool_output={"hits": 3},
77
+ duration_ms=142,
78
+ )
79
+ ```
80
+
81
+ ## What ICA does with it
82
+
83
+ Each step posts to `POST /api/ingest/agent-step`. On arrival ICA:
84
+
85
+ 1. Mints an L7 receipt over the step, signed server-side. You never touch a key.
86
+ 2. Appends it to an append-only, tamper-evident audit trail.
87
+ 3. Feeds it to the assessment engine: decision control, containment,
88
+ reversibility, observability, continuous posture.
89
+ 4. Enforces. A step that bypasses a gate or runs an irreversible action ungated
90
+ is flagged, and a halted agent is quarantined at ingest.
91
+
92
+ Verify any receipt without publishing your data. Public chains are optional, not
93
+ required, and never the default.
94
+
95
+ ## Step fields
96
+
97
+ | Field | Notes |
98
+ |-------|-------|
99
+ | `step_type` | `reasoning`, `tool_call`, `sub_agent_dispatch`, `final_answer`, `gate_request`, `gate_response` |
100
+ | `tool_name` | the tool invoked |
101
+ | `tool_input` / `tool_output` | JSON-safe; coerced if needed |
102
+ | `reversibility_tag` | `reversible`, `partial`, `irreversible`, `unclassified` |
103
+ | `gate_state` | `not_gated`, `pending`, `approved`, `denied`, `bypassed` |
104
+ | `duration_ms`, `tokens_used` | optional metrics |
105
+
106
+ ## Tool guard and tool hooks
107
+
108
+ For a graph whose held calls should wait for people, use `ica.approval_pause` (below): a held call pauses the
109
+ graph instead of ending it, and the block is hard. The callback recorder above still records graph runs. Two
110
+ more, neither of which adds a dependency. The agent framework is a setting, never a module name:
111
+
112
+ | Use | `framework=` | Hard block with `gate=True` |
113
+ |---|---|---|
114
+ | `from ica.tool_guard import guard_tools`; `tools = guard_tools(ica, tools, framework=..., gate=True)` | `"openai_agents"` | yes: wraps each dataclass function tool's `on_invoke_tool` |
115
+ | the same | `"crewai"` | yes: wraps each tool's `_run` |
116
+ | the same | `"llamaindex"` | yes: wraps `FunctionTool` `_fn` and `_async_fn` |
117
+ | `from ica.tool_hooks import IcaHooks`; `Agent(tools=..., hooks=[IcaHooks(ica, gate=True)])` | (frameworks that call tool hooks) | yes: a deny sets `cancel_tool` |
118
+
119
+ An unknown `framework=` raises `ValueError`, so a typo never leaves tools unguarded. A tool of another shape is
120
+ returned unchanged.
121
+
122
+ ## Stated confidence
123
+
124
+ An agent can tell ICA how sure it is of each gated call, as a number from 0 to 1. When the agent's scope
125
+ contract sets a confidence floor (`operating_envelope.confidence_floor`), ICA holds a call below the floor,
126
+ or one that states nothing, for a person: `gate()` answers `pending` and the tool does not run. A high
127
+ number never loosens anything; every other check still decides.
128
+
129
+ - `ica.gate(action, tool_name=..., stated_confidence=0.82)` sends it on one call.
130
+ - Every adapter and decorator takes `confidence=`: a number, or a function `(tool_name, payload) -> number`
131
+ that reads the model's own statement (for example a `confidence` field your tool schema asks the model to
132
+ fill). A function that raises states nothing, so with a floor set the call is held.
133
+
134
+ ```python
135
+ tools = guard_tools(ica, tools, framework="crewai", gate=True, confidence=lambda name, payload: payload.get("kwargs", {}).get("confidence"))
136
+ ```
137
+
138
+ ## Approval pause: a held call pauses the graph
139
+
140
+ Every other adapter treats a call ICA holds for a person (`pending`) as a deny: the run ends. In a graph runtime
141
+ with `interrupt()` and a checkpointer the graph can wait instead.
142
+
143
+ ```python
144
+ from langchain_core.tools import tool
145
+ from langgraph.checkpoint.memory import MemorySaver
146
+ from langgraph.prebuilt import ToolNode
147
+ from ica.approval_pause import ica_approval_pause_tool, route_tool_calls
148
+
149
+ @tool
150
+ @ica_approval_pause_tool(ica, reversibility_tag="irreversible")
151
+ def update_claim(claim_id: int, amount: int) -> str:
152
+ ...
153
+
154
+ builder.add_node("tools", ToolNode([update_claim]))
155
+ builder.add_conditional_edges("agent", route_tool_calls, ["tools", END]) # one task per tool call
156
+ graph = builder.compile(checkpointer=MemorySaver()) # pausing needs a checkpointer
157
+ ```
158
+
159
+ - Approved: the tool runs and its step carries the single-use token. Denied: `GateDenied`, the tool never runs.
160
+ - Held: ICA raises a two-person approval request bound to the exact arguments, and the graph pauses
161
+ (`interrupt()`); the payload carries `approval_request_id`. Two named people approve it in the ICA console.
162
+ Resume with `Command(resume=...)` (one value per pending interrupt when several pause at once). The resume
163
+ value is only a wake-up: the tool asks ICA, and runs only when ICA releases a token for that call. Still
164
+ pending, or ICA briefly unreachable: it pauses again. Denied, expired, arguments changed, or the agent halted,
165
+ retired or cert-blocked since the approval: `GateDenied`. Already released (a re-run after it ran): it does
166
+ not run again and returns a message saying so.
167
+ - One tool call per task. A resumed graph task runs again from the top, and a plain `ToolNode` wired on the
168
+ messages list runs every call of a turn in one task, so the other calls of that turn would run again when one
169
+ pauses. Use `route_tool_calls` (above) or `create_react_agent` (its default version "v2" already sends each
170
+ call on its own). Tested with the graph runtime package at 1.2.14 (tests/test_approval_pause_real.py): with the routing, an approved call beside a held one runs once;
171
+ without it, twice.
172
+ - Needs a per-customer ingest credential: only the credential that raised a request can collect it, and a
173
+ shared token raises none. A tenant that approves with one person gets no request either: this path releases
174
+ only on two named approvals. Outside a graph run nothing is requested and a hold ends the call, as before.
175
+ - A request waits up to an hour for a person, an approval must be collected within an hour of being given, and a
176
+ credential can have at most 25 requests waiting. Arguments holding an integer past 2^53 are refused (JSON cannot
177
+ carry it exactly): send such ids as strings.
178
+ - Each resume re-asks the gate (one more sealed `pending` decision). A `hold_key` derived from the thread and
179
+ task makes the re-ask find the same request. Pass `key_fn=` to name calls yourself.
180
+ - Under it: `ica.gate(..., request_approval=True, args=..., hold_key=...)` and `ica.release(approval_request_id,
181
+ args)`, which any framework can use.
182
+
183
+ ## Signed proof in your agent's trace
184
+
185
+ Every gate decision ICA seals comes back with its signed receipt. Give the client an `on_proof` function and that proof lands
186
+ in your agent's own trace, beside the tool call it decided:
187
+
188
+ ```python
189
+ ica = IcaClient(token="...", agent_handle="pay-bot", on_proof=add_to_current_run)
190
+ ```
191
+
192
+ `add_to_current_run(proof)` is yours: add the dict to the current run's metadata in whatever tracing tool you use. The dict
193
+ is flat strings: `ica_receipt_hash`, `ica_verify_url`, `ica_decision`, `ica_gate_id`, `ica_signing_key_id`, `ica_tool`.
194
+ Anyone holding the hash re-checks the decision at the verify URL (public, no sign-in) or offline against ICA's published
195
+ keys, without trusting your tracer or ALEETH. Every adapter above that gates (`gate=True`, the tool guard, the tool hooks,
196
+ the approval pause) goes through `gate()`, so it carries the proof; the same dict is on the verdict as `verdict["proof"]`,
197
+ and `proof_of(verdict)` builds it from any gate answer. A decision ICA could not seal gives no proof. A function that raises
198
+ never changes the decision (it raises only with `raise_on_error=True`). A step recorded without a gate is signed just after
199
+ ICA answers, so its receipt is not in that answer.
200
+
201
+ ## Outside eval results
202
+
203
+ `from ica.evals import record_eval`, then `record_eval(ica, result, framework="ragas", run_name=..., thresholds={...})`.
204
+ Reads Ragas, DeepEval, Giskard, TruLens, promptfoo and plain `{metric: score}` results, and files the
205
+ summary (per-metric mean, min, max, count, pass and fail counts, failed thresholds, never the eval's
206
+ prompts or answers) as one step on the agent's ICA record, where it is sealed like every other step.
207
+
208
+ ## License
209
+
210
+ This SDK is licensed under the Apache License 2.0 (see LICENSE). Using ICA needs an ingest token: contact ALEETH
211
+ (https://aleeth.com).
@@ -0,0 +1,27 @@
1
+ """
2
+ ICA capture SDK · emit agent steps; ICA governs and signs them.
3
+
4
+ from ica import IcaClient, ica_tool, wrap_mcp_tool
5
+ from ica.callbacks import IcaCallbackHandler # optional: the [callbacks] extra
6
+ from ica.approval_pause import ica_approval_pause_tool # optional: a held call pauses the agent's graph
7
+ from ica.tool_guard import guard_tools # ICA in front of every tool; framework= is a setting
8
+ from ica.tool_hooks import IcaHooks # a hook provider for frameworks that call tool hooks
9
+ """
10
+
11
+ from .client import IcaClient, IcaError, VALID_GATE_STATES, VALID_REVERSIBILITY, VALID_STEP_TYPES, proof_of
12
+ from .decorator import GateDenied, ica_tool, wrap_mcp_tool
13
+
14
+ __version__ = "0.1.0"
15
+
16
+ __all__ = [
17
+ "IcaClient",
18
+ "IcaError",
19
+ "proof_of",
20
+ "GateDenied",
21
+ "ica_tool",
22
+ "wrap_mcp_tool",
23
+ "VALID_STEP_TYPES",
24
+ "VALID_REVERSIBILITY",
25
+ "VALID_GATE_STATES",
26
+ "__version__",
27
+ ]