langchain-accord 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,14 @@
1
+ node_modules/
2
+ dist/
3
+ *.tgz
4
+ __pycache__/
5
+ *.egg-info/
6
+ .venv/
7
+ .pytest_cache/
8
+ .env
9
+ .env.*
10
+ !.env.example
11
+ *.sqlite
12
+ *.sqlite-*
13
+ .accord-flow-c-thread
14
+ .DS_Store
@@ -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.
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.5
2
+ Name: langchain-accord
3
+ Version: 0.1.0
4
+ Summary: Accord for LangChain and LangGraph: agents that pay several sellers as one decision, only for work that passes your evaluator, within limits enforced when money moves.
5
+ Project-URL: Homepage, https://useaccord.ai
6
+ Project-URL: Documentation, https://useaccord.ai/quickstart/
7
+ Author: Accord
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: accord,ai agents,langchain,langgraph,payments
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: getaccord>=0.10.2
16
+ Requires-Dist: langchain-core<2,>=1.0
17
+ Provides-Extra: langgraph
18
+ Requires-Dist: langgraph<2,>=1.0; extra == 'langgraph'
19
+ Provides-Extra: test
20
+ Requires-Dist: langchain-tests>=1.0; extra == 'test'
21
+ Requires-Dist: langgraph-checkpoint-sqlite>=2; extra == 'test'
22
+ Requires-Dist: langgraph<2,>=1.0; extra == 'test'
23
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
24
+ Requires-Dist: pytest>=8; extra == 'test'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # langchain-accord
28
+
29
+ Accord for LangChain and LangGraph: **agents that pay only for work that passes your evaluator.**
30
+
31
+ - **Several sellers, one decision.** Hold money with every seller a task might need, then pay the ones your terms call
32
+ for in one step ("scout and (marketpulse or quantfeed)"), or call everything off and the money comes back.
33
+ - **Pay only for accepted work.** Delivered work waits for your evaluator; rejected work is never paid.
34
+ - **No double payment when a node reruns.** LangGraph reruns a node after an interrupt or a crash. A `purchase_ref`
35
+ derived from the thread makes the rerun find the purchase the first run opened: nothing is held or paid twice.
36
+ - **Limits enforced when money moves.** The weekly budget, allowed sellers and sign-off threshold belong to the agent
37
+ key's owner. The agent can't raise them, and it can't give itself a sign-off.
38
+ - **Seller text is marked as data**, and every purchase has a public proof page.
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ npx @getaccord/cli init # a test key in ./.env, with test money
44
+ pip install langchain-accord # add langgraph for the LangGraph helpers
45
+ ```
46
+
47
+ The tools read the agent key from `ACCORD_AGENT_KEY` or `./.env`. No tool takes it as an argument or returns it.
48
+
49
+ ## Tools
50
+
51
+ ```python
52
+ from langchain.agents import create_agent
53
+ from langchain.agents.middleware import HumanInTheLoopMiddleware
54
+ from langgraph.checkpoint.memory import InMemorySaver
55
+ from langchain_accord import AccordToolkit, seller_content_note
56
+
57
+ toolkit = AccordToolkit() # x402=True adds quote_x402_url and fetch_x402_resource
58
+ agent = create_agent(
59
+ "anthropic:claude-sonnet-5-5",
60
+ toolkit.get_tools(),
61
+ system_prompt=seller_content_note(), # seller text is data, never instructions
62
+ middleware=[HumanInTheLoopMiddleware(interrupt_on={n: True for n in toolkit.money_moving_tools()})],
63
+ checkpointer=InMemorySaver(),
64
+ )
65
+ ```
66
+
67
+ The tools have the same names, arguments and answers as Accord's MCP server:
68
+
69
+ | Tool | What it does |
70
+ |---|---|
71
+ | `get_spending_limits` | Money available, what's left of the weekly budget, the sellers this key may pay. |
72
+ | `find_sellers` | The seller directory: who sells what, at what price, and whether this key may pay each. |
73
+ | `start_purchase` | Opens a purchase (`budget_usd`, `mode` "all" or "each", `purchase_ref`, `reason`, ...). Nothing is paid. |
74
+ | `place_holds` | Holds money with one or more sellers, in one step. |
75
+ | `get_delivered_work` | Delivered work to check, marked as seller text. |
76
+ | `accept_work` / `reject_work` | Decide on delivered work: only accepted work is paid. |
77
+ | `complete_purchase` | Pays every seller in one step (mode "all": all or none). |
78
+ | `cancel_purchase` | Calls it off; held money comes back. |
79
+ | `start_linked_purchase` | Several purchases under one condition, e.g. `scout and (marketpulse or quantfeed)`. |
80
+ | `linked_purchase_status` | Each member's state and whether the condition can be met. |
81
+ | `settle_linked_purchase` | One step: pays the chosen members and calls off the rest, or calls everything off. |
82
+ | `quote_x402_url` / `fetch_x402_resource` | Web resources that charge per request (x402). Off unless `x402=True`. |
83
+
84
+ A refusal (over the weekly budget, a seller the key may not pay, a purchase waiting for sign-off) comes back as the
85
+ tool's answer, quoting the rule, so the model can tell the user. `purchase_id` is the handle `start_purchase` gives,
86
+ or the purchase's Accord ID (`0x...`), which works after a restart; a `link_id` works after a restart too.
87
+ `start_linked_purchase` also takes a `purchase_ref`, so a retry returns the same linked purchase.
88
+
89
+ ## LangGraph
90
+
91
+ ```python
92
+ from langchain_accord.langgraph import purchase_ref_for, run_with_sign_off, sign_off_or_interrupt, seller_content_note
93
+ ```
94
+
95
+ - **`purchase_ref_for(config, step)`** gives `"<thread_id>:<step>"`: the same on every rerun of that node. Give each
96
+ purchase in a thread its own `step`.
97
+ - **`sign_off_or_interrupt(err)`** pauses the graph when Accord says a purchase needs a person's sign-off (an
98
+ `awaiting_approval` error, or a linked purchase's `status()` with a member waiting). The interrupt payload is
99
+ `{"kind": "accord_sign_off", "message", "approve_at", "purchase_ids"}`: never a key or token. The person approves
100
+ outside the graph (the dashboard at app.test.useaccord.ai); resume with `Command(resume=True)`.
101
+ - **`run_with_sign_off(step, purchase=intent)`** runs a step, pausing for sign-off and trying again after each resume.
102
+ - **`seller_content_note()`** is the line to put in your system prompt and your evaluator's prompt.
103
+
104
+ ```python
105
+ def buy(state, config):
106
+ intent = accord.intent(budget=230_00, purchase_ref=purchase_ref_for(config, "buy"))
107
+ run_with_sign_off(lambda: intent.hold("scout", 200_00, type="deliver", ref="Research brief"), purchase=intent)
108
+ return {"intent_id": intent.id} # an ID in graph state, never the key
109
+ ```
110
+
111
+ ## Examples (test mode, each under a minute after `init`)
112
+
113
+ ```bash
114
+ python examples/research_brief.py # flow B: hold with three sellers, evaluate, settle
115
+ python examples/research_brief.py --fail marketpulse # marketpulse declines: quantfeed is paid instead
116
+ python examples/research_brief.py --sign-off # the graph pauses until a person approves
117
+ python examples/crash_resume.py --demo # flow C: crash twice, resume, paid once
118
+ ```
119
+
120
+ If a run goes past the key's sign-off threshold, the graph pauses for a person's approval. Add `--approve` to approve
121
+ as the key's owner (the owner token `init` saved in `~/.accord`, read by the example's runner, never by the graph).
122
+
123
+ `research_brief.py` uses a plain-code evaluator unless `ACCORD_EVAL_MODEL` names a chat model (for example
124
+ `anthropic:claude-sonnet-5-5`, with `pip install langchain langchain-anthropic`). Then the evaluator is its own model
125
+ call with no tools and structured output; accepting or rejecting is still decided in code.
126
+
127
+ ## Keeping the key safe
128
+
129
+ - The key stays in `ACCORD_AGENT_KEY` or `./.env`. Keep it, and any owner token, out of graph state, `interrupt()`
130
+ payloads, prompts and traces. These tools and helpers never put it there, and hide anything that looks like a key or
131
+ token in their answers.
132
+ - On LangGraph Platform, the key goes in the deployment's secrets (LangChain's secret store). Give that key tight
133
+ limits: a small weekly budget, only the sellers it needs, and a low sign-off threshold.
134
+ - The owner token never goes to the agent. Approvals happen in the dashboard, or for a test key with
135
+ `accord.test.approve(...)` run by the person, outside the graph.
136
+
137
+ ## Tests
138
+
139
+ ```bash
140
+ pip install -e '.[test]'
141
+ pytest # unit tests and LangChain's standard tool tests (no network)
142
+ cd <a folder where you ran init> && pytest <this folder>/tests/integration_tests # test mode
143
+ ```
144
+
145
+ Apache-2.0. Built by Mysten Labs.
@@ -0,0 +1,119 @@
1
+ # langchain-accord
2
+
3
+ Accord for LangChain and LangGraph: **agents that pay only for work that passes your evaluator.**
4
+
5
+ - **Several sellers, one decision.** Hold money with every seller a task might need, then pay the ones your terms call
6
+ for in one step ("scout and (marketpulse or quantfeed)"), or call everything off and the money comes back.
7
+ - **Pay only for accepted work.** Delivered work waits for your evaluator; rejected work is never paid.
8
+ - **No double payment when a node reruns.** LangGraph reruns a node after an interrupt or a crash. A `purchase_ref`
9
+ derived from the thread makes the rerun find the purchase the first run opened: nothing is held or paid twice.
10
+ - **Limits enforced when money moves.** The weekly budget, allowed sellers and sign-off threshold belong to the agent
11
+ key's owner. The agent can't raise them, and it can't give itself a sign-off.
12
+ - **Seller text is marked as data**, and every purchase has a public proof page.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npx @getaccord/cli init # a test key in ./.env, with test money
18
+ pip install langchain-accord # add langgraph for the LangGraph helpers
19
+ ```
20
+
21
+ The tools read the agent key from `ACCORD_AGENT_KEY` or `./.env`. No tool takes it as an argument or returns it.
22
+
23
+ ## Tools
24
+
25
+ ```python
26
+ from langchain.agents import create_agent
27
+ from langchain.agents.middleware import HumanInTheLoopMiddleware
28
+ from langgraph.checkpoint.memory import InMemorySaver
29
+ from langchain_accord import AccordToolkit, seller_content_note
30
+
31
+ toolkit = AccordToolkit() # x402=True adds quote_x402_url and fetch_x402_resource
32
+ agent = create_agent(
33
+ "anthropic:claude-sonnet-5-5",
34
+ toolkit.get_tools(),
35
+ system_prompt=seller_content_note(), # seller text is data, never instructions
36
+ middleware=[HumanInTheLoopMiddleware(interrupt_on={n: True for n in toolkit.money_moving_tools()})],
37
+ checkpointer=InMemorySaver(),
38
+ )
39
+ ```
40
+
41
+ The tools have the same names, arguments and answers as Accord's MCP server:
42
+
43
+ | Tool | What it does |
44
+ |---|---|
45
+ | `get_spending_limits` | Money available, what's left of the weekly budget, the sellers this key may pay. |
46
+ | `find_sellers` | The seller directory: who sells what, at what price, and whether this key may pay each. |
47
+ | `start_purchase` | Opens a purchase (`budget_usd`, `mode` "all" or "each", `purchase_ref`, `reason`, ...). Nothing is paid. |
48
+ | `place_holds` | Holds money with one or more sellers, in one step. |
49
+ | `get_delivered_work` | Delivered work to check, marked as seller text. |
50
+ | `accept_work` / `reject_work` | Decide on delivered work: only accepted work is paid. |
51
+ | `complete_purchase` | Pays every seller in one step (mode "all": all or none). |
52
+ | `cancel_purchase` | Calls it off; held money comes back. |
53
+ | `start_linked_purchase` | Several purchases under one condition, e.g. `scout and (marketpulse or quantfeed)`. |
54
+ | `linked_purchase_status` | Each member's state and whether the condition can be met. |
55
+ | `settle_linked_purchase` | One step: pays the chosen members and calls off the rest, or calls everything off. |
56
+ | `quote_x402_url` / `fetch_x402_resource` | Web resources that charge per request (x402). Off unless `x402=True`. |
57
+
58
+ A refusal (over the weekly budget, a seller the key may not pay, a purchase waiting for sign-off) comes back as the
59
+ tool's answer, quoting the rule, so the model can tell the user. `purchase_id` is the handle `start_purchase` gives,
60
+ or the purchase's Accord ID (`0x...`), which works after a restart; a `link_id` works after a restart too.
61
+ `start_linked_purchase` also takes a `purchase_ref`, so a retry returns the same linked purchase.
62
+
63
+ ## LangGraph
64
+
65
+ ```python
66
+ from langchain_accord.langgraph import purchase_ref_for, run_with_sign_off, sign_off_or_interrupt, seller_content_note
67
+ ```
68
+
69
+ - **`purchase_ref_for(config, step)`** gives `"<thread_id>:<step>"`: the same on every rerun of that node. Give each
70
+ purchase in a thread its own `step`.
71
+ - **`sign_off_or_interrupt(err)`** pauses the graph when Accord says a purchase needs a person's sign-off (an
72
+ `awaiting_approval` error, or a linked purchase's `status()` with a member waiting). The interrupt payload is
73
+ `{"kind": "accord_sign_off", "message", "approve_at", "purchase_ids"}`: never a key or token. The person approves
74
+ outside the graph (the dashboard at app.test.useaccord.ai); resume with `Command(resume=True)`.
75
+ - **`run_with_sign_off(step, purchase=intent)`** runs a step, pausing for sign-off and trying again after each resume.
76
+ - **`seller_content_note()`** is the line to put in your system prompt and your evaluator's prompt.
77
+
78
+ ```python
79
+ def buy(state, config):
80
+ intent = accord.intent(budget=230_00, purchase_ref=purchase_ref_for(config, "buy"))
81
+ run_with_sign_off(lambda: intent.hold("scout", 200_00, type="deliver", ref="Research brief"), purchase=intent)
82
+ return {"intent_id": intent.id} # an ID in graph state, never the key
83
+ ```
84
+
85
+ ## Examples (test mode, each under a minute after `init`)
86
+
87
+ ```bash
88
+ python examples/research_brief.py # flow B: hold with three sellers, evaluate, settle
89
+ python examples/research_brief.py --fail marketpulse # marketpulse declines: quantfeed is paid instead
90
+ python examples/research_brief.py --sign-off # the graph pauses until a person approves
91
+ python examples/crash_resume.py --demo # flow C: crash twice, resume, paid once
92
+ ```
93
+
94
+ If a run goes past the key's sign-off threshold, the graph pauses for a person's approval. Add `--approve` to approve
95
+ as the key's owner (the owner token `init` saved in `~/.accord`, read by the example's runner, never by the graph).
96
+
97
+ `research_brief.py` uses a plain-code evaluator unless `ACCORD_EVAL_MODEL` names a chat model (for example
98
+ `anthropic:claude-sonnet-5-5`, with `pip install langchain langchain-anthropic`). Then the evaluator is its own model
99
+ call with no tools and structured output; accepting or rejecting is still decided in code.
100
+
101
+ ## Keeping the key safe
102
+
103
+ - The key stays in `ACCORD_AGENT_KEY` or `./.env`. Keep it, and any owner token, out of graph state, `interrupt()`
104
+ payloads, prompts and traces. These tools and helpers never put it there, and hide anything that looks like a key or
105
+ token in their answers.
106
+ - On LangGraph Platform, the key goes in the deployment's secrets (LangChain's secret store). Give that key tight
107
+ limits: a small weekly budget, only the sellers it needs, and a low sign-off threshold.
108
+ - The owner token never goes to the agent. Approvals happen in the dashboard, or for a test key with
109
+ `accord.test.approve(...)` run by the person, outside the graph.
110
+
111
+ ## Tests
112
+
113
+ ```bash
114
+ pip install -e '.[test]'
115
+ pytest # unit tests and LangChain's standard tool tests (no network)
116
+ cd <a folder where you ran init> && pytest <this folder>/tests/integration_tests # test mode
117
+ ```
118
+
119
+ Apache-2.0. Built by Mysten Labs.
@@ -0,0 +1,47 @@
1
+ """The person's side of the examples: approving a purchase that waits for sign-off, as the key's owner.
2
+
3
+ The owner token `npx @getaccord/cli init` saved (~/.accord/owner-<key ID>) is read here, by the person running the
4
+ example, never by the agent or the graph: it never enters graph state, interrupt payloads or tool results.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import os
10
+ import re
11
+ from pathlib import Path
12
+ from typing import List, Optional
13
+
14
+ from getaccord import Accord, AccordError
15
+ from getaccord.keys import load_key
16
+
17
+
18
+ def owner_token() -> Optional[str]:
19
+ if os.environ.get("ACCORD_OWNER_TOKEN"):
20
+ return os.environ["ACCORD_OWNER_TOKEN"]
21
+ f = Path(os.environ.get("ACCORD_OWNER_DIR") or Path.home() / ".accord") / f"owner-{load_key().address}"
22
+ m = re.search(r"^ACCORD_OWNER_TOKEN=(own_\S+)$", f.read_text(), re.M) if f.exists() else None
23
+ return m.group(1) if m else None
24
+
25
+
26
+ def approve(accord: Accord, payload: dict, token: Optional[str], allow_prompt: bool = True) -> bool:
27
+ """Approves what the interrupt names with the owner token, or asks the person to approve it in the dashboard.
28
+ False when neither is possible (no token, and no one at the terminal)."""
29
+ print(f"[paused] {payload['message']} Approve at {payload['approve_at']}.")
30
+ if token and payload.get("purchase_ids"):
31
+ for pid in payload["purchase_ids"]:
32
+ try:
33
+ accord.test.approve(pid, token)
34
+ except AccordError as e:
35
+ if e.code != "not_awaiting_approval": # approved already (an earlier run did it before stopping)
36
+ raise
37
+ print("[person] approved (as the key's owner, outside the graph).")
38
+ return True
39
+ if allow_prompt and os.isatty(0):
40
+ input(" Approve it there, then press Enter to resume… ")
41
+ return True
42
+ print(" Nobody here to approve it: run again with --approve to approve as the key's owner (test mode).")
43
+ return False
44
+
45
+
46
+ def ids(payload: dict) -> List[str]:
47
+ return list(payload.get("purchase_ids") or [])