acuto 0.1.1__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.
acuto-0.1.1/LICENSE ADDED
@@ -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 2026 Yifeng Xiao
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 @@
1
+ prune tests
acuto-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,215 @@
1
+ Metadata-Version: 2.4
2
+ Name: acuto
3
+ Version: 0.1.1
4
+ Summary: A symbolic control layer for LLM agents: contracts over tool calls, compiled to automata that mask, route and verify every step
5
+ Author: Yifeng Xiao
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/yfxiao16/acuto
8
+ Project-URL: Repository, https://github.com/yfxiao16/acuto
9
+ Project-URL: Issues, https://github.com/yfxiao16/acuto/issues
10
+ Project-URL: Changelog, https://github.com/yfxiao16/acuto/blob/main/CHANGELOG.md
11
+ Keywords: llm-agents,runtime-enforcement,assume-guarantee-contracts,ltlf,tool-use,neuro-symbolic,symbolic-control
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: contragent<2,>=1.2
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7; extra == "dev"
28
+ Requires-Dist: ruff==0.15.16; extra == "dev"
29
+ Requires-Dist: pyyaml; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # Acuto
33
+
34
+ **A**gentic **C**ontract-based r**u**n**t**ime **O**rchestration: contract-based symbolic control of LLM agents.
35
+
36
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/yfxiao16/acuto/blob/main/LICENSE)
37
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
38
+ [![CI](https://github.com/yfxiao16/acuto/actions/workflows/ci.yml/badge.svg)](https://github.com/yfxiao16/acuto/actions/workflows/ci.yml)
39
+
40
+ Declare a procedure once, as contracts over the agent's tool calls.
41
+ Acuto hides the tools the contracts rule out, executes the steps they
42
+ determine without asking the model, and checks every call before it
43
+ runs.
44
+
45
+ Acuto (Agentic Contract-based Runtime Orchestration) is a symbolic
46
+ control layer for LLM agents. A library of assume-guarantee contracts in
47
+ ALTL<sub>f</sub> over the tool-call trace compiles to deterministic
48
+ automata whose joint state the framework walks as a residual policy
49
+ graph: each node carries the tools the contracts still admit and, when
50
+ only one remains, the call itself. Three mechanisms read that graph
51
+ before every step. **Masking** exposes only the admissible tools.
52
+ **Fast-forward** executes a step the contracts determine, or an
53
+ obligation that has fallen due, with no model call. **Verification**
54
+ checks every call before it executes, whether the model proposed it or
55
+ the framework scheduled it, and every result before the model sees it.
56
+ Acuto drives the agent loop itself, so the guarantee holds by
57
+ construction: every executed action crosses the same boundary.
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ pip install acuto # Python 3.10+
63
+ ```
64
+
65
+ `pip` installs the `contragent` runtime dependency automatically. To
66
+ work on Acuto itself, clone this repository and run:
67
+
68
+ ```bash
69
+ pip install -e ".[dev]"
70
+ ```
71
+
72
+ ## Quick start
73
+
74
+ An agent is a model, its tools, and a contract library. Tools say what
75
+ the agent *can* do; contracts say what is *allowed and required*; Acuto
76
+ drives the loop. Register tools as synchronous functions.
77
+
78
+ ```python
79
+ import acuto
80
+
81
+ agent = acuto.Agent(model=acuto.models.resolve("openai:gpt-5-mini"),
82
+ instructions="You are a bank service agent.")
83
+
84
+ @agent.tool
85
+ def verify_identity(user_id: str) -> dict:
86
+ "Verify the customer's identity."
87
+ return {"verified": True}
88
+
89
+ @agent.tool
90
+ def issue_refund(order_id: str, amount: float) -> dict:
91
+ "Issue a refund for an order."
92
+ return {"refunded": True}
93
+
94
+ agent.attach(acuto.ContractLibrary("refund-desk-v1", [
95
+ acuto.action("issue_refund").requires("identity_verified").at_most(1),
96
+ acuto.after("verify_identity").asserts("identity_verified",
97
+ when=lambda r: r.output["verified"]),
98
+ ]))
99
+
100
+ agent.run("Refund order #123 for customer u1", verbose=True)
101
+ ```
102
+
103
+ Until the identity is verified the model does not see `issue_refund`; a
104
+ premature refund is refused with the recovery step named; a second
105
+ refund is refused outright. A contract is a rule about the trace, a
106
+ fact is what a tool result established, and an obligation
107
+ (`acuto.when(fact).obligates(tool)`) is a duty a fact creates, which
108
+ Acuto discharges itself when its arguments are determined. `verbose=True`
109
+ prints every decision as it happens.
110
+
111
+ The model key is read from the environment (`OPENAI_API_KEY`,
112
+ `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`, or the AWS pair), then from a
113
+ `.env` in the working directory. [`examples/`](https://github.com/yfxiao16/acuto/tree/main/examples/) runs the same
114
+ programs with a scripted model and no credentials:
115
+ [`quickstart.py`](https://github.com/yfxiao16/acuto/blob/main/examples/quickstart.py) is the program above,
116
+ [`bank_demo.py`](https://github.com/yfxiao16/acuto/blob/main/examples/bank_demo.py) shows an obligation being
117
+ fast-forwarded and a forbidden call refused, and
118
+ [`embed_controller.py`](https://github.com/yfxiao16/acuto/blob/main/examples/embed_controller.py) drives Acuto from
119
+ a loop of its own.
120
+
121
+ ## Use your own model
122
+
123
+ Acuto talks to the provider with your key; there is no Acuto service in
124
+ between and no provider SDK to install.
125
+
126
+ ```python
127
+ import acuto
128
+
129
+ acuto.models.resolve("anthropic:claude-sonnet-5-5") # ANTHROPIC_API_KEY
130
+ acuto.models.resolve("openai:gpt-5-mini") # OPENAI_API_KEY
131
+ acuto.models.resolve("gemini:gemini-2.5-flash") # GEMINI_API_KEY
132
+ acuto.models.resolve("bedrock:us.anthropic.claude-haiku-4-5-20251001-v1:0") # AWS keys
133
+
134
+ # any OpenAI-compatible endpoint: a hosted one, or vLLM / SGLang on your machine
135
+ acuto.models.resolve("openai:deepseek-chat",
136
+ base_url="https://api.deepseek.com/v1",
137
+ api_key_env="DEEPSEEK_API_KEY")
138
+
139
+ # local OpenAI-compatible server without authentication
140
+ acuto.models.resolve("openai:local-model", base_url="http://localhost:8000/v1")
141
+ ```
142
+
143
+ For the default endpoints, credentials come from the environment variables
144
+ shown, then from a `.env` file in the working directory. For a custom
145
+ OpenAI-compatible endpoint, pass `api_key=` or `api_key_env=` if it requires
146
+ authentication. Acuto sends the request without an authorization header
147
+ when both are omitted. An explicit `api_key=` overrides the environment. For a model
148
+ behind your own API, write a class with one method,
149
+ `generate(messages, tools, system)`, that returns a `ModelTurn`:
150
+ [`examples/custom_model.py`](https://github.com/yfxiao16/acuto/blob/main/examples/custom_model.py).
151
+
152
+ ## Long runs
153
+
154
+ A long task outgrows the context window and outlives the process. The
155
+ control state (monitors, facts, obligations) is kept apart from the
156
+ messages, so both can be handled without changing what is allowed or
157
+ required.
158
+
159
+ ```python
160
+ from acuto import Agent, Checkpoint, MaskCompactor
161
+
162
+ agent = Agent(model=model, compactor=MaskCompactor(threshold=100_000))
163
+ agent.run(task, checkpoint_path="run.json") # state written before every step
164
+
165
+ # after a crash or a kill: continue from the step that was cut off
166
+ agent.run(task, resume=Checkpoint.load("run.json"))
167
+ ```
168
+
169
+ A compactor moves old tool results out of the model's view once the
170
+ context passes its threshold; the model reads them back with the
171
+ `acuto_recall` tool. A resumed run replays its journal into a fresh
172
+ controller, so no call that completed is made again. A call that was
173
+ sent when the run died, to a tool not marked `idempotent`, is not
174
+ repeated unless you pass `on_in_flight="redo"`.
175
+ [`examples/long_run.py`](https://github.com/yfxiao16/acuto/blob/main/examples/long_run.py) shows a run that dies and
176
+ is resumed; [docs/LONG_RUNS.md](https://github.com/yfxiao16/acuto/blob/main/docs/LONG_RUNS.md) has the design and
177
+ its guarantees.
178
+
179
+ ## Using Acuto from your own loop
180
+
181
+ `acuto.Agent` is a reference loop over `acuto.Controller`, one session of
182
+ control any loop can drive. `route()` masks the tools and says who acts
183
+ next; `verify(call)` is the boundary every call crosses; `commit(call,
184
+ result)` verifies the result and advances the state; `execute(call)`
185
+ chains the three when Acuto runs the tools.
186
+
187
+ ```python
188
+ controller = acuto.Controller(library, tools=registry)
189
+ while True:
190
+ decision = controller.route()
191
+ if decision.kind is acuto.StepKind.SYMBOLIC_EXECUTE:
192
+ controller.execute(decision.action) # no model call
193
+ continue
194
+ turn = my_model(messages, tools=registry.schemas(decision.actions))
195
+ for call in turn.tool_calls:
196
+ outcome = controller.execute(call) # verify → run → commit
197
+ messages.append(tool_message(outcome.feedback()))
198
+ ```
199
+
200
+ ## Documentation
201
+
202
+ - [SDK reference](https://github.com/yfxiao16/acuto/blob/main/docs/SDK.md): the public surface in three tiers, the
203
+ contract DSL, where a contract library lives, flows, model adapters,
204
+ and the extension points.
205
+ - [Design](https://github.com/yfxiao16/acuto/blob/main/docs/DESIGN.md) covers the runtime architecture.
206
+
207
+ ## Citation
208
+
209
+ Cite the software using [CITATION.cff](https://github.com/yfxiao16/acuto/blob/main/CITATION.cff).
210
+
211
+ ## License
212
+
213
+ Acuto is licensed under [Apache-2.0](https://github.com/yfxiao16/acuto/blob/main/LICENSE).
214
+ See [CONTRIBUTING.md](https://github.com/yfxiao16/acuto/blob/main/CONTRIBUTING.md)
215
+ for the development workflow.
acuto-0.1.1/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # Acuto
2
+
3
+ **A**gentic **C**ontract-based r**u**n**t**ime **O**rchestration: contract-based symbolic control of LLM agents.
4
+
5
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/yfxiao16/acuto/blob/main/LICENSE)
6
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
7
+ [![CI](https://github.com/yfxiao16/acuto/actions/workflows/ci.yml/badge.svg)](https://github.com/yfxiao16/acuto/actions/workflows/ci.yml)
8
+
9
+ Declare a procedure once, as contracts over the agent's tool calls.
10
+ Acuto hides the tools the contracts rule out, executes the steps they
11
+ determine without asking the model, and checks every call before it
12
+ runs.
13
+
14
+ Acuto (Agentic Contract-based Runtime Orchestration) is a symbolic
15
+ control layer for LLM agents. A library of assume-guarantee contracts in
16
+ ALTL<sub>f</sub> over the tool-call trace compiles to deterministic
17
+ automata whose joint state the framework walks as a residual policy
18
+ graph: each node carries the tools the contracts still admit and, when
19
+ only one remains, the call itself. Three mechanisms read that graph
20
+ before every step. **Masking** exposes only the admissible tools.
21
+ **Fast-forward** executes a step the contracts determine, or an
22
+ obligation that has fallen due, with no model call. **Verification**
23
+ checks every call before it executes, whether the model proposed it or
24
+ the framework scheduled it, and every result before the model sees it.
25
+ Acuto drives the agent loop itself, so the guarantee holds by
26
+ construction: every executed action crosses the same boundary.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install acuto # Python 3.10+
32
+ ```
33
+
34
+ `pip` installs the `contragent` runtime dependency automatically. To
35
+ work on Acuto itself, clone this repository and run:
36
+
37
+ ```bash
38
+ pip install -e ".[dev]"
39
+ ```
40
+
41
+ ## Quick start
42
+
43
+ An agent is a model, its tools, and a contract library. Tools say what
44
+ the agent *can* do; contracts say what is *allowed and required*; Acuto
45
+ drives the loop. Register tools as synchronous functions.
46
+
47
+ ```python
48
+ import acuto
49
+
50
+ agent = acuto.Agent(model=acuto.models.resolve("openai:gpt-5-mini"),
51
+ instructions="You are a bank service agent.")
52
+
53
+ @agent.tool
54
+ def verify_identity(user_id: str) -> dict:
55
+ "Verify the customer's identity."
56
+ return {"verified": True}
57
+
58
+ @agent.tool
59
+ def issue_refund(order_id: str, amount: float) -> dict:
60
+ "Issue a refund for an order."
61
+ return {"refunded": True}
62
+
63
+ agent.attach(acuto.ContractLibrary("refund-desk-v1", [
64
+ acuto.action("issue_refund").requires("identity_verified").at_most(1),
65
+ acuto.after("verify_identity").asserts("identity_verified",
66
+ when=lambda r: r.output["verified"]),
67
+ ]))
68
+
69
+ agent.run("Refund order #123 for customer u1", verbose=True)
70
+ ```
71
+
72
+ Until the identity is verified the model does not see `issue_refund`; a
73
+ premature refund is refused with the recovery step named; a second
74
+ refund is refused outright. A contract is a rule about the trace, a
75
+ fact is what a tool result established, and an obligation
76
+ (`acuto.when(fact).obligates(tool)`) is a duty a fact creates, which
77
+ Acuto discharges itself when its arguments are determined. `verbose=True`
78
+ prints every decision as it happens.
79
+
80
+ The model key is read from the environment (`OPENAI_API_KEY`,
81
+ `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`, or the AWS pair), then from a
82
+ `.env` in the working directory. [`examples/`](https://github.com/yfxiao16/acuto/tree/main/examples/) runs the same
83
+ programs with a scripted model and no credentials:
84
+ [`quickstart.py`](https://github.com/yfxiao16/acuto/blob/main/examples/quickstart.py) is the program above,
85
+ [`bank_demo.py`](https://github.com/yfxiao16/acuto/blob/main/examples/bank_demo.py) shows an obligation being
86
+ fast-forwarded and a forbidden call refused, and
87
+ [`embed_controller.py`](https://github.com/yfxiao16/acuto/blob/main/examples/embed_controller.py) drives Acuto from
88
+ a loop of its own.
89
+
90
+ ## Use your own model
91
+
92
+ Acuto talks to the provider with your key; there is no Acuto service in
93
+ between and no provider SDK to install.
94
+
95
+ ```python
96
+ import acuto
97
+
98
+ acuto.models.resolve("anthropic:claude-sonnet-5-5") # ANTHROPIC_API_KEY
99
+ acuto.models.resolve("openai:gpt-5-mini") # OPENAI_API_KEY
100
+ acuto.models.resolve("gemini:gemini-2.5-flash") # GEMINI_API_KEY
101
+ acuto.models.resolve("bedrock:us.anthropic.claude-haiku-4-5-20251001-v1:0") # AWS keys
102
+
103
+ # any OpenAI-compatible endpoint: a hosted one, or vLLM / SGLang on your machine
104
+ acuto.models.resolve("openai:deepseek-chat",
105
+ base_url="https://api.deepseek.com/v1",
106
+ api_key_env="DEEPSEEK_API_KEY")
107
+
108
+ # local OpenAI-compatible server without authentication
109
+ acuto.models.resolve("openai:local-model", base_url="http://localhost:8000/v1")
110
+ ```
111
+
112
+ For the default endpoints, credentials come from the environment variables
113
+ shown, then from a `.env` file in the working directory. For a custom
114
+ OpenAI-compatible endpoint, pass `api_key=` or `api_key_env=` if it requires
115
+ authentication. Acuto sends the request without an authorization header
116
+ when both are omitted. An explicit `api_key=` overrides the environment. For a model
117
+ behind your own API, write a class with one method,
118
+ `generate(messages, tools, system)`, that returns a `ModelTurn`:
119
+ [`examples/custom_model.py`](https://github.com/yfxiao16/acuto/blob/main/examples/custom_model.py).
120
+
121
+ ## Long runs
122
+
123
+ A long task outgrows the context window and outlives the process. The
124
+ control state (monitors, facts, obligations) is kept apart from the
125
+ messages, so both can be handled without changing what is allowed or
126
+ required.
127
+
128
+ ```python
129
+ from acuto import Agent, Checkpoint, MaskCompactor
130
+
131
+ agent = Agent(model=model, compactor=MaskCompactor(threshold=100_000))
132
+ agent.run(task, checkpoint_path="run.json") # state written before every step
133
+
134
+ # after a crash or a kill: continue from the step that was cut off
135
+ agent.run(task, resume=Checkpoint.load("run.json"))
136
+ ```
137
+
138
+ A compactor moves old tool results out of the model's view once the
139
+ context passes its threshold; the model reads them back with the
140
+ `acuto_recall` tool. A resumed run replays its journal into a fresh
141
+ controller, so no call that completed is made again. A call that was
142
+ sent when the run died, to a tool not marked `idempotent`, is not
143
+ repeated unless you pass `on_in_flight="redo"`.
144
+ [`examples/long_run.py`](https://github.com/yfxiao16/acuto/blob/main/examples/long_run.py) shows a run that dies and
145
+ is resumed; [docs/LONG_RUNS.md](https://github.com/yfxiao16/acuto/blob/main/docs/LONG_RUNS.md) has the design and
146
+ its guarantees.
147
+
148
+ ## Using Acuto from your own loop
149
+
150
+ `acuto.Agent` is a reference loop over `acuto.Controller`, one session of
151
+ control any loop can drive. `route()` masks the tools and says who acts
152
+ next; `verify(call)` is the boundary every call crosses; `commit(call,
153
+ result)` verifies the result and advances the state; `execute(call)`
154
+ chains the three when Acuto runs the tools.
155
+
156
+ ```python
157
+ controller = acuto.Controller(library, tools=registry)
158
+ while True:
159
+ decision = controller.route()
160
+ if decision.kind is acuto.StepKind.SYMBOLIC_EXECUTE:
161
+ controller.execute(decision.action) # no model call
162
+ continue
163
+ turn = my_model(messages, tools=registry.schemas(decision.actions))
164
+ for call in turn.tool_calls:
165
+ outcome = controller.execute(call) # verify → run → commit
166
+ messages.append(tool_message(outcome.feedback()))
167
+ ```
168
+
169
+ ## Documentation
170
+
171
+ - [SDK reference](https://github.com/yfxiao16/acuto/blob/main/docs/SDK.md): the public surface in three tiers, the
172
+ contract DSL, where a contract library lives, flows, model adapters,
173
+ and the extension points.
174
+ - [Design](https://github.com/yfxiao16/acuto/blob/main/docs/DESIGN.md) covers the runtime architecture.
175
+
176
+ ## Citation
177
+
178
+ Cite the software using [CITATION.cff](https://github.com/yfxiao16/acuto/blob/main/CITATION.cff).
179
+
180
+ ## License
181
+
182
+ Acuto is licensed under [Apache-2.0](https://github.com/yfxiao16/acuto/blob/main/LICENSE).
183
+ See [CONTRIBUTING.md](https://github.com/yfxiao16/acuto/blob/main/CONTRIBUTING.md)
184
+ for the development workflow.