call4agents 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.
- call4agents-0.1.0/LICENSE +202 -0
- call4agents-0.1.0/NOTICE +6 -0
- call4agents-0.1.0/PKG-INFO +265 -0
- call4agents-0.1.0/README.md +240 -0
- call4agents-0.1.0/call4agents/__init__.py +322 -0
- call4agents-0.1.0/call4agents/__main__.py +217 -0
- call4agents-0.1.0/call4agents/adapters/__init__.py +3 -0
- call4agents-0.1.0/call4agents/adapters/langgraph.py +61 -0
- call4agents-0.1.0/call4agents/codec.py +114 -0
- call4agents-0.1.0/call4agents/examples/__init__.py +2 -0
- call4agents-0.1.0/call4agents/examples/crash_resume.py +138 -0
- call4agents-0.1.0/call4agents/ledger.py +326 -0
- call4agents-0.1.0/call4agents/ops.py +185 -0
- call4agents-0.1.0/call4agents/proof.py +75 -0
- call4agents-0.1.0/call4agents/quickstart.py +95 -0
- call4agents-0.1.0/call4agents/replay.py +153 -0
- call4agents-0.1.0/call4agents.egg-info/PKG-INFO +265 -0
- call4agents-0.1.0/call4agents.egg-info/SOURCES.txt +24 -0
- call4agents-0.1.0/call4agents.egg-info/dependency_links.txt +1 -0
- call4agents-0.1.0/call4agents.egg-info/entry_points.txt +2 -0
- call4agents-0.1.0/call4agents.egg-info/top_level.txt +1 -0
- call4agents-0.1.0/pyproject.toml +37 -0
- call4agents-0.1.0/setup.cfg +4 -0
- call4agents-0.1.0/tests/test_c4a_kit.py +566 -0
- call4agents-0.1.0/tests/test_c4a_production.py +347 -0
- call4agents-0.1.0/tests/test_idempotency.py +148 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
call4agents-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Call4Agents
|
|
2
|
+
Copyright 2026 Salah Eddine Makboul (GitHub: salahmakboul)
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
"Call4Agents" is the project name used by its author. Redistributions must keep
|
|
6
|
+
this NOTICE file, as required by section 4(d) of the Apache License 2.0.
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: call4agents
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Once-only actions, approvals bound to exact arguments, and record/replay for Python AI agents
|
|
5
|
+
Author: Salah Eddine Makboul
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/salahmakboul/call4agents
|
|
8
|
+
Project-URL: Issues, https://github.com/salahmakboul/call4agents/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/salahmakboul/call4agents/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: ai-agents,langgraph,pydantic-ai,openai-agents,idempotency,approvals,human-in-the-loop
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
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: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# Call4Agents
|
|
27
|
+
|
|
28
|
+
Call4Agents makes the actions of a Python agent safe to retry. You add it to the agent you already
|
|
29
|
+
have: LangGraph, Pydantic AI, the OpenAI Agents SDK, or plain Python. It does not replace any of them.
|
|
30
|
+
|
|
31
|
+
- **Once-only actions.** A crash, a retry or a resume does not send the same email or payment twice.
|
|
32
|
+
- **Approvals bound to exact arguments.** A "yes" to `pay(10, alice)` cannot run `pay(9999, mallory)`.
|
|
33
|
+
A "yes" covers one action, and a later "no" is enforced.
|
|
34
|
+
- **Idempotency keys for outside APIs.** The same key across crashes and resumes, so the payment API
|
|
35
|
+
itself can drop the duplicate.
|
|
36
|
+
- **Record, replay, diff.** Rerun a recorded run offline with zero model calls, and find the step where
|
|
37
|
+
two runs (for example two models) begin to differ.
|
|
38
|
+
|
|
39
|
+
Version 0.1, early. Standard library only, zero dependencies. Apache-2.0.
|
|
40
|
+
|
|
41
|
+
**Tested on every change** ([tests.yml](.github/workflows/tests.yml)). These are the only systems we claim:
|
|
42
|
+
|
|
43
|
+
| | Python 3.10 | Python 3.11 | Python 3.12 | Python 3.13 |
|
|
44
|
+
|---|---|---|---|---|
|
|
45
|
+
| Linux (GitHub `ubuntu-latest`) | ✓ | ✓ | ✓ | ✓ |
|
|
46
|
+
| macOS (GitHub `macos-latest`) | ✓ | ✓ | ✓ | ✓ |
|
|
47
|
+
| Windows (GitHub `windows-latest`) | ✓ | ✓ | ✓ | ✓ |
|
|
48
|
+
|
|
49
|
+
With the real frameworks, on all three systems with Python 3.12: LangGraph (+ LangChain), Pydantic AI and
|
|
50
|
+
the OpenAI Agents SDK. CI installs the latest release of each, and each run prints the exact versions
|
|
51
|
+
with `call4agents doctor`.
|
|
52
|
+
|
|
53
|
+
## Try it (under a minute, offline, no API keys)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install call4agents
|
|
57
|
+
call4agents quickstart
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`quickstart` runs a plain-Python demo. Then, for each of LangGraph, Pydantic AI and the OpenAI
|
|
61
|
+
Agents SDK that is installed, it runs a real crash and resume in that framework, using a fake model.
|
|
62
|
+
Each framework is run once without Call4Agents and once with it. Output on our machine (Windows 10,
|
|
63
|
+
Python 3.12, all three installed):
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
Plain Python - crash right after an email is sent, then resume:
|
|
67
|
+
without the run record emails sent: 2
|
|
68
|
+
with the run record (crash after the tool) emails sent: 1
|
|
69
|
+
with the run record (crash inside the tool) emails sent: 1 (refused to resend: in doubt)
|
|
70
|
+
"yes" to pay(10, alice), call changed to pay(9999, mallory): REFUSED; approved call: PAID; payments: 1
|
|
71
|
+
|
|
72
|
+
Frameworks found: LangGraph, Pydantic AI, OpenAI Agents SDK
|
|
73
|
+
LangGraph crash after the email, resume: without call4agents 2 emails, with call4agents 1
|
|
74
|
+
Pydantic AI crash after the email, resume: without call4agents 2 emails, with call4agents 1
|
|
75
|
+
OpenAI Agents SDK crash after the email, resume: without call4agents 2 emails, with call4agents 1
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
With no framework installed, only the plain-Python part runs (about 5 seconds on our machine). To see
|
|
79
|
+
the framework rows, install them first: `pip install langgraph langgraph-checkpoint-sqlite pydantic-ai
|
|
80
|
+
openai-agents` (about 75 seconds in a fresh virtual environment).
|
|
81
|
+
|
|
82
|
+
`call4agents selftest` checks the demo results. Run it from the root of a repository checkout to run the
|
|
83
|
+
full offline suites instead (kit, production, stress and idempotency checks).
|
|
84
|
+
|
|
85
|
+
Found a problem, or something missing? `call4agents doctor` prints your system and framework versions
|
|
86
|
+
(it sends nothing). Paste it into an [issue](https://github.com/salahmakboul/call4agents/issues/new/choose).
|
|
87
|
+
|
|
88
|
+
## When you need it
|
|
89
|
+
|
|
90
|
+
- Your agent sends emails, payments, tickets or database writes, and a crash, a timeout retry or a
|
|
91
|
+
resume from a checkpoint can repeat them.
|
|
92
|
+
- A person approves an action, and the arguments can change before it runs, for example through an
|
|
93
|
+
edited saved state or a model asked again after a restart.
|
|
94
|
+
- A person double-clicks "approve", or two workers pick up the same approved task.
|
|
95
|
+
- You call an API that supports `Idempotency-Key` (Stripe, Adyen and others) and want a crash
|
|
96
|
+
half-way through to be retried safely instead of needing a person.
|
|
97
|
+
- You switch model or provider and want to see which tool calls changed before you release.
|
|
98
|
+
|
|
99
|
+
You probably do not need it if your agent only reads data, or if every action already runs inside
|
|
100
|
+
a durable workflow engine that gives you these guarantees.
|
|
101
|
+
|
|
102
|
+
## How to use it
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import call4agents as c4a
|
|
106
|
+
|
|
107
|
+
c4a.init() # creates .c4a/ledger.sqlite and .c4a/secret
|
|
108
|
+
|
|
109
|
+
@c4a.effect # once per (run, tool, exact arguments)
|
|
110
|
+
def send_email(to, body): ...
|
|
111
|
+
|
|
112
|
+
@c4a.effect(approval=True) # also needs a "yes" for these exact arguments
|
|
113
|
+
def pay(amount, to): ...
|
|
114
|
+
|
|
115
|
+
@c4a.effect(idempotent_for=24 * 3600) # the API remembers keys for 24 h (Stripe v1)
|
|
116
|
+
def charge(amount, to):
|
|
117
|
+
return requests.post(URL, json={"amount": amount, "to": to},
|
|
118
|
+
headers=c4a.idempotency_headers()).json()
|
|
119
|
+
|
|
120
|
+
@c4a.recorded # model calls, for replay and diff
|
|
121
|
+
def ask_model(prompt): ...
|
|
122
|
+
|
|
123
|
+
with c4a.run("thread-42"): # use the id your framework resumes with
|
|
124
|
+
send_email("bob", "hi")
|
|
125
|
+
send_email("bob", "hi") # same action: returns the recorded result, sends nothing
|
|
126
|
+
send_email("bob", "hi", c4a_key="second") # a deliberate second identical action
|
|
127
|
+
c4a.approve(pay, amount=10, to="alice") # when the person says yes to what they SAW
|
|
128
|
+
pay(amount=10, to="alice")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Rules worth knowing before you start:
|
|
132
|
+
- **Always inside `c4a.run(...)`.** An action or approval outside a run raises `RuntimeError`. New threads
|
|
133
|
+
do not inherit the run, so enter `c4a.run` in the thread (or use `contextvars.copy_context().run`).
|
|
134
|
+
- **A tool is identified by module + function name** (`billing.charge`). If you move or rename the
|
|
135
|
+
function between deploys, a resumed run sees a new tool. Give long-lived tools a fixed `name="charge"`.
|
|
136
|
+
- **Arguments need a stable text form**: numbers, strings, lists, dicts, sets, dataclasses, Pydantic models.
|
|
137
|
+
An object that prints its memory address raises `TypeError`; pass `c4a_key=` instead. For methods,
|
|
138
|
+
`self` is not part of the key.
|
|
139
|
+
- **If the function raises**, the action may or may not have happened (a timeout after the charge
|
|
140
|
+
raises too). The next call raises `EffectInDoubt` and names the error. List errors that prove nothing
|
|
141
|
+
happened with `retry_on=(ConnectionRefusedError,)`; after those, the next call runs the action again.
|
|
142
|
+
|
|
143
|
+
**LangGraph and LangChain.**
|
|
144
|
+
- `from call4agents.adapters import langgraph as c4a_lg`.
|
|
145
|
+
- Use `@c4a_lg.effect` in nodes or tools.
|
|
146
|
+
- Call `c4a_lg.approve(tool, config, **shown_args)` when an interrupt is answered, or `c4a_lg.deny(...)`.
|
|
147
|
+
- The thread id becomes the run id.
|
|
148
|
+
|
|
149
|
+
**Pydantic AI, the OpenAI Agents SDK, plain Python.** Decorate the tool function with `@c4a.effect` and
|
|
150
|
+
wrap the run in `c4a.run(<your session or conversation id>)`. You can see working code for each framework
|
|
151
|
+
in [call4agents/examples/crash_resume.py](call4agents/examples/crash_resume.py).
|
|
152
|
+
|
|
153
|
+
## How it works
|
|
154
|
+
|
|
155
|
+
The kit's whole state is one local SQLite file, which we call the run record. Entries are only ever
|
|
156
|
+
added to it, never changed or deleted.
|
|
157
|
+
|
|
158
|
+
1. **Before** a decorated action runs, an *intent* is written: run id, tool name, and a hash of the
|
|
159
|
+
exact arguments. A unique index lets only one caller write the intent for the same action, so
|
|
160
|
+
simultaneous callers cannot both start it.
|
|
161
|
+
2. **After** it returns, the *result* is written. A later call of the same action gets that result back
|
|
162
|
+
and the action does not run again.
|
|
163
|
+
3. If the process dies **between** the two writes, nobody knows whether the action happened. The kit
|
|
164
|
+
raises `EffectInDoubt` instead of guessing. You can resolve it in two ways:
|
|
165
|
+
- `reconcile=` asks the outside system whether the action happened;
|
|
166
|
+
- `idempotent_for=` lets the kit resend it with the same key while the API still remembers that key
|
|
167
|
+
([docs/IDEMPOTENCY.md](docs/IDEMPOTENCY.md)).
|
|
168
|
+
4. **Approvals.** An approval is an HMAC, made with a local secret, over the tool name and its exact
|
|
169
|
+
arguments, and it is scoped to the run. Each approval can be spent by one action only. A later `deny`
|
|
170
|
+
cancels it.
|
|
171
|
+
5. **Replay.** `c4a.init(replay_from="old.sqlite")` returns recorded model calls and results without
|
|
172
|
+
calling anything. They come back as the same Python types, including Pydantic models and dataclasses.
|
|
173
|
+
`call4agents diff a.sqlite b.sqlite` shows the step where two runs start to differ.
|
|
174
|
+
|
|
175
|
+
## Commands
|
|
176
|
+
|
|
177
|
+
| Command | What it does |
|
|
178
|
+
|---|---|
|
|
179
|
+
| `call4agents quickstart` | the demo plus a crash and resume in each installed framework |
|
|
180
|
+
| `call4agents demo` | the plain-Python demo only |
|
|
181
|
+
| `call4agents selftest` | the kit's checks (in a repository checkout, the full offline suites) |
|
|
182
|
+
| `call4agents doctor` | system and framework versions for a bug report; prints only, sends nothing |
|
|
183
|
+
| `call4agents status <record>` | rows, actions, actions in doubt, integrity |
|
|
184
|
+
| `call4agents doubt <record> [--fail-if-any]` | every action that may or may not have happened (exit 3 if any, for alerts) |
|
|
185
|
+
| `call4agents resolve <record> <key> done\|not-done "note"` | decide one in-doubt action; stored as a new row with your note |
|
|
186
|
+
| `call4agents archive <record> <archive> <days>` | move finished runs older than N days to another file |
|
|
187
|
+
| `call4agents verify <record>` | integrity, format version, late results |
|
|
188
|
+
| `call4agents diff a.sqlite b.sqlite [run_id]` | the step where two recorded runs start to differ |
|
|
189
|
+
| `call4agents prove spec.json` | puts each bug back and checks that your guard catches it |
|
|
190
|
+
|
|
191
|
+
`python -m call4agents ...` works the same way.
|
|
192
|
+
|
|
193
|
+
## In production
|
|
194
|
+
|
|
195
|
+
[docs/PRODUCTION.md](docs/PRODUCTION.md) covers the rest:
|
|
196
|
+
- costs: a new action is 1.9 ms (median) on our machine, a repeated one 45 µs;
|
|
197
|
+
- the big test, with 12 processes, random kills and a payment API that drops answers: 0 double charges,
|
|
198
|
+
against 244 of 300 orders without the kit;
|
|
199
|
+
- secret rotation, archiving, what the record stores, every error message and what to do;
|
|
200
|
+
- a guide for whoever is on call.
|
|
201
|
+
|
|
202
|
+
## Measured in each framework
|
|
203
|
+
|
|
204
|
+
You can rerun every number in this table. The tests use fake models, fake tools and real process kills.
|
|
205
|
+
|
|
206
|
+
| Case | LangGraph | Pydantic AI | OpenAI Agents SDK | How to check |
|
|
207
|
+
|---|---|---|---|---|
|
|
208
|
+
| Crash after the email, then resume: emails sent without the kit | 2 | 2 | 2 | `call4agents quickstart` |
|
|
209
|
+
| The same with Call4Agents | **1** | **1** | **1** | `call4agents quickstart` |
|
|
210
|
+
| With Call4Agents: timeout retry after the email | **1** | – | – | `python -m tests.framework_kill_langgraph` |
|
|
211
|
+
| With Call4Agents: model asked again after a restart (approved 10, now says 12) | **refused** | – | – | same |
|
|
212
|
+
| With Call4Agents: LangChain human-in-the-loop, saved state edited to 9999 → mallory | **refused** | – | – | same |
|
|
213
|
+
|
|
214
|
+
A dash means the case was not tested in that framework.
|
|
215
|
+
|
|
216
|
+
## What is proven and what is not
|
|
217
|
+
|
|
218
|
+
**Proven by tests in this repository** (`tests/`):
|
|
219
|
+
- the table above;
|
|
220
|
+
- the big test (`python -m tests.bigtest_c4a`). 12 processes are killed at random while they charge
|
|
221
|
+
300 orders through a payment API that drops and delays answers. The result is 0 double charges.
|
|
222
|
+
Without the kit, the same run charges 244 of 300 orders twice or more;
|
|
223
|
+
- an action resumed in 3 new processes, as a method with a set argument, runs once;
|
|
224
|
+
- 14 simultaneous callers of one action: it runs once;
|
|
225
|
+
- 8 simultaneous actions on one "yes": exactly one runs;
|
|
226
|
+
- 3,000 of 3,000 records from 20 parallel writers;
|
|
227
|
+
- 5 kills during writes left the file intact;
|
|
228
|
+
- a crash after a payment API charged, then a resume with the idempotency key: 1 charge, and the
|
|
229
|
+
original charge is returned;
|
|
230
|
+
- replay returns the same types, including real Pydantic and OpenAI SDK objects.
|
|
231
|
+
|
|
232
|
+
Each guard is mutation-tested: when its bug is put back, its check fails. A no-op control is run
|
|
233
|
+
next to every batch of mutations. Rerun them with `python -m tests.mutations.run_kit_mutations`.
|
|
234
|
+
|
|
235
|
+
**Not proven:**
|
|
236
|
+
- real payment or email systems, and production traffic;
|
|
237
|
+
- systems and Python versions not listed at the top of this page;
|
|
238
|
+
- several machines sharing one run record (once-only holds for processes that share the file);
|
|
239
|
+
- an independent code review;
|
|
240
|
+
- adapters other than LangGraph (the decorator itself works in any framework).
|
|
241
|
+
|
|
242
|
+
## Costs and limits
|
|
243
|
+
|
|
244
|
+
- A crash *during* an action is not resolved for you. You get `EffectInDoubt` unless you use `reconcile=`
|
|
245
|
+
or `idempotent_for=`. Most frameworks would simply run the action again.
|
|
246
|
+
- A refused approval means the action does not run. Your app has to ask the person again.
|
|
247
|
+
- You decorate each action yourself, and call `approve` with the arguments the person saw.
|
|
248
|
+
- Replaying a recorded run that contains approval-gated actions needs the approvals again in the
|
|
249
|
+
new run record (`c4a.approve(...)` before the replayed call).
|
|
250
|
+
- If the model rewrites the arguments on a retry (`10` becomes `10.00`), the call is treated as a new
|
|
251
|
+
action. Pass `c4a_key=` (for example, an order id) when that can happen.
|
|
252
|
+
- The secret in `.c4a/secret` protects approvals from anyone who cannot read that file. It does not
|
|
253
|
+
protect them from someone who can (see [docs/THREAT_MODEL.md](docs/THREAT_MODEL.md)).
|
|
254
|
+
|
|
255
|
+
## More
|
|
256
|
+
|
|
257
|
+
- [docs/PRODUCTION.md](docs/PRODUCTION.md): costs, the big test, running it on call, every error message
|
|
258
|
+
- [docs/IDEMPOTENCY.md](docs/IDEMPOTENCY.md): idempotency keys and the exact retry rule
|
|
259
|
+
- [docs/THREAT_MODEL.md](docs/THREAT_MODEL.md): what the approval secret protects, and what it does not
|
|
260
|
+
- [CHANGELOG.md](CHANGELOG.md)
|
|
261
|
+
|
|
262
|
+
## Licence
|
|
263
|
+
|
|
264
|
+
Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE). Copyright 2026 Salah Eddine Makboul.
|
|
265
|
+
"Call4Agents" is the project's name. The licence does not grant the right to use it for other products (Apache-2.0, section 6).
|