recall-langgraph 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.
- recall_langgraph-0.1.0/.gitignore +13 -0
- recall_langgraph-0.1.0/LICENSE +202 -0
- recall_langgraph-0.1.0/PKG-INFO +209 -0
- recall_langgraph-0.1.0/README.md +185 -0
- recall_langgraph-0.1.0/pyproject.toml +47 -0
- recall_langgraph-0.1.0/recall_langgraph/__init__.py +20 -0
- recall_langgraph-0.1.0/recall_langgraph/py.typed +0 -0
- recall_langgraph-0.1.0/recall_langgraph/resume.py +347 -0
- recall_langgraph-0.1.0/recall_langgraph/tools.py +140 -0
- recall_langgraph-0.1.0/tests/__init__.py +0 -0
- recall_langgraph-0.1.0/tests/integration_tests/__init__.py +0 -0
- recall_langgraph-0.1.0/tests/integration_tests/conftest.py +157 -0
- recall_langgraph-0.1.0/tests/integration_tests/test_live.py +70 -0
- recall_langgraph-0.1.0/tests/scripted.py +51 -0
- recall_langgraph-0.1.0/tests/unit_tests/__init__.py +0 -0
- recall_langgraph-0.1.0/tests/unit_tests/conftest.py +9 -0
- recall_langgraph-0.1.0/tests/unit_tests/fake_client.py +88 -0
- recall_langgraph-0.1.0/tests/unit_tests/test_resume.py +266 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.pyc
|
|
3
|
+
.pytest_cache/
|
|
4
|
+
.ruff_cache/
|
|
5
|
+
.venv/
|
|
6
|
+
python/dist/
|
|
7
|
+
python/build/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
|
|
10
|
+
# The LiveKit example: provider keys, and the local Recall database with its key
|
|
11
|
+
examples/livekit/.env
|
|
12
|
+
examples/livekit/memory-api-key
|
|
13
|
+
recall-data/
|
|
@@ -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 2026 Polign, Inc.
|
|
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,209 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: recall-langgraph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Resume LangGraph agents from their own records, backed by Recall by Polign
|
|
5
|
+
Project-URL: Homepage, https://polign.com
|
|
6
|
+
Project-URL: Documentation, https://polign.com/integrations.html
|
|
7
|
+
Project-URL: Repository, https://github.com/Polign/polign
|
|
8
|
+
Project-URL: Issues, https://github.com/Polign/polign/issues
|
|
9
|
+
Author: Polign
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agent memory,langchain,langgraph,polign,recall,resume
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: langchain-core<2,>=1.0
|
|
21
|
+
Requires-Dist: langgraph<2,>=1.0
|
|
22
|
+
Requires-Dist: polign-recall>=0.4.0
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# recall-langgraph
|
|
26
|
+
|
|
27
|
+
Resume [LangGraph](https://github.com/langchain-ai/langgraph) agents from
|
|
28
|
+
their own records, backed by [Recall by Polign](https://polign.com/recall.html).
|
|
29
|
+
|
|
30
|
+
A long-running agent that crashes, gets rescheduled, or moves to another
|
|
31
|
+
machine usually starts over, or restores an exact snapshot of its state. With
|
|
32
|
+
this package it picks up where it left off from what it wrote down instead:
|
|
33
|
+
while it works, it keeps a working state (its goal, plan, progress and
|
|
34
|
+
decisions) and pointers to where its work lives, and every message of the run
|
|
35
|
+
is recorded. The next process that opens the same agent id gets a fresh
|
|
36
|
+
starting context built from those records, sized to a token budget.
|
|
37
|
+
|
|
38
|
+
This sits beside your checkpointer, not in place of it. LangGraph's
|
|
39
|
+
checkpointer still handles threads and interrupts however you configure it.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install recall-langgraph
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
pip also brings the [`polign_db`](https://pypi.org/project/polign-db/)
|
|
46
|
+
package with the `polign` CLI and `polign-server` binaries for Linux, macOS
|
|
47
|
+
and Windows, so there is no separate database to download.
|
|
48
|
+
|
|
49
|
+
## Usage with create_react_agent
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from langchain_openai import ChatOpenAI
|
|
53
|
+
from langgraph.prebuilt import create_react_agent
|
|
54
|
+
from recall_langgraph import RecallResume, recall_tools
|
|
55
|
+
|
|
56
|
+
with RecallResume("billing-migrator", local_dir="./recall-data") as resume:
|
|
57
|
+
agent = create_react_agent(
|
|
58
|
+
ChatOpenAI(model="gpt-4.1"),
|
|
59
|
+
tools=[*your_tools, *recall_tools(resume)],
|
|
60
|
+
prompt=(
|
|
61
|
+
"You move the billing service to the v2 API. Keep your working state "
|
|
62
|
+
"current with update_working_state, and call milestone when a step is done."
|
|
63
|
+
),
|
|
64
|
+
pre_model_hook=resume.pre_model_hook,
|
|
65
|
+
post_model_hook=resume.post_model_hook,
|
|
66
|
+
)
|
|
67
|
+
agent.invoke({"messages": [("user", "Carry on with the migration.")]})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Run it, stop it halfway, and run it again: the second run starts from the
|
|
71
|
+
working state, pointers and recent turns the first one wrote.
|
|
72
|
+
|
|
73
|
+
What happens:
|
|
74
|
+
|
|
75
|
+
1. Entering the `with` block resumes the agent. It takes a lease on the id,
|
|
76
|
+
so only one process acts for the agent at a time, and reads back its
|
|
77
|
+
records. The first time an id is used, it starts fresh.
|
|
78
|
+
2. Before every model call, `pre_model_hook` puts one `SystemMessage` in
|
|
79
|
+
front of the messages, the briefing: the working state, pointers to the
|
|
80
|
+
work, relevant memories, and the most recent turns, within
|
|
81
|
+
`token_budget`. It goes to the model as `llm_input_messages`, so the
|
|
82
|
+
graph's `messages` state never holds it.
|
|
83
|
+
3. The hooks record each new message once, in order, as a turn: human
|
|
84
|
+
messages before the model call, the model's reply right after it, and tool
|
|
85
|
+
results before the next call. A reply with tool calls is recorded with the
|
|
86
|
+
calls as JSON text. A turn longer than the output threshold is stored whole
|
|
87
|
+
as an output, and the briefing shows a reference the model can pass to
|
|
88
|
+
`fetch_output`.
|
|
89
|
+
4. The model keeps its working state current through the tools from
|
|
90
|
+
`recall_tools`.
|
|
91
|
+
5. Leaving the block (or calling `release()`) hands the lease over, so the
|
|
92
|
+
next process can resume at once. A process that dies without releasing
|
|
93
|
+
holds the lease until it expires (60 seconds by default).
|
|
94
|
+
|
|
95
|
+
Recall never replays old messages into the state: the briefing already
|
|
96
|
+
carries the recent turns as text, and a replayed tool result without its
|
|
97
|
+
matching tool call would be refused by the model API. On a new `thread_id`,
|
|
98
|
+
the resumed run starts from the briefing alone. On the old `thread_id`, a
|
|
99
|
+
persistent checkpointer restores the old messages as well, and nothing is
|
|
100
|
+
recorded twice: each turn keeps its message id, so the first recording after
|
|
101
|
+
a resume skips every restored message up to the last one Recall already has.
|
|
102
|
+
Messages after that one, such as the caller's new input or a reply the dead
|
|
103
|
+
process never recorded, are recorded as usual. The model then sees the
|
|
104
|
+
restored history and the briefing both; start a new thread if you would
|
|
105
|
+
rather it saw only the briefing.
|
|
106
|
+
|
|
107
|
+
`create_react_agent` is deprecated in LangGraph 1.0 in favor of
|
|
108
|
+
`langchain.agents.create_agent`, but it still ships in `langgraph.prebuilt`
|
|
109
|
+
and the hooks work with it. Use `version="v2"` (the default), since
|
|
110
|
+
`post_model_hook` needs it.
|
|
111
|
+
|
|
112
|
+
## Your own StateGraph
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from langgraph.graph import START, MessagesState, StateGraph
|
|
116
|
+
|
|
117
|
+
def call_model(state: MessagesState):
|
|
118
|
+
return {"messages": [model.invoke(resume.with_briefing(state["messages"]))]}
|
|
119
|
+
|
|
120
|
+
builder = StateGraph(MessagesState)
|
|
121
|
+
builder.add_node("model", call_model)
|
|
122
|
+
builder.add_node("record", resume.record_node)
|
|
123
|
+
builder.add_edge(START, "model")
|
|
124
|
+
builder.add_edge("model", "record")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- `with_briefing(messages)` returns the messages with the briefing in front,
|
|
128
|
+
for the model's input, and leaves the state alone.
|
|
129
|
+
- `record_node` records every message not recorded yet and changes nothing.
|
|
130
|
+
Put it after each node that adds messages. `record(messages)` does the same
|
|
131
|
+
from your own code.
|
|
132
|
+
- `briefing_node` adds the briefing to the `messages` state itself, once per
|
|
133
|
+
thread, if you would rather keep it there. Put it first.
|
|
134
|
+
|
|
135
|
+
The hooks and nodes work with `invoke` and `ainvoke`.
|
|
136
|
+
|
|
137
|
+
## The tools
|
|
138
|
+
|
|
139
|
+
| Tool | What the model uses it for |
|
|
140
|
+
|---|---|
|
|
141
|
+
| `update_working_state` | Save its goal, plan, progress, focus, decisions, open questions and notes. Fields it leaves out are kept. |
|
|
142
|
+
| `milestone` | Declare a durable point, such as tests passing. |
|
|
143
|
+
| `fetch_output` | Read a stored output in full by its ref. |
|
|
144
|
+
| `set_pointer` | Record where a piece of work lives: a git branch or commit, an object, an environment, an external item, or a process. |
|
|
145
|
+
|
|
146
|
+
A failed call comes back to the model as the tool's text. Your own code can
|
|
147
|
+
call `resume.update_working_state`, `resume.milestone`, `resume.fetch_output`
|
|
148
|
+
and `resume.set_pointer`, and `resume.agent` is the underlying
|
|
149
|
+
`polign_recall.ResumedAgent` for everything else (`record_turn`,
|
|
150
|
+
`recent_turns`, `store_output`, `pointers`, `working_state_history`).
|
|
151
|
+
`resume.context` is what the resume returned, and `resume.briefing` its text.
|
|
152
|
+
|
|
153
|
+
## Options
|
|
154
|
+
|
|
155
|
+
| Option | Default | What it does |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| `client` | none | A `polign_recall.Client` opened with `agent=True`, to share one subprocess. Without it, `RecallResume` opens its own and closes it on release. |
|
|
158
|
+
| `local_dir` | none | Keep the database in this directory and run its server (only when `RecallResume` opens its own client) |
|
|
159
|
+
| `env` | process environment | `POLIGN_URL`, `POLIGN_API_KEY` and the rest, for a server you run yourself |
|
|
160
|
+
| `token_budget` | 8000 | Bound on the briefing, in tokens |
|
|
161
|
+
| `lease_ttl` | 60 | Seconds each lease epoch lasts; renewed in the background |
|
|
162
|
+
| `holder` | host, pid and a random suffix | Names this process in lease records |
|
|
163
|
+
| `output_threshold` | 2000 | Turns longer than this many tokens are stored as outputs |
|
|
164
|
+
|
|
165
|
+
## Errors
|
|
166
|
+
|
|
167
|
+
If another process holds the agent, resuming raises
|
|
168
|
+
`polign_recall.RecallError` with code `"lease_held"`. Wait and try again, or
|
|
169
|
+
stop. If another process takes the agent over mid-run, the next record fails
|
|
170
|
+
with code `"lease_lost"`, which stops the graph run; this process should
|
|
171
|
+
stop acting for the agent.
|
|
172
|
+
|
|
173
|
+
Records are append-only. Removing or trimming messages in the graph state
|
|
174
|
+
changes what the model sees, never what was recorded.
|
|
175
|
+
|
|
176
|
+
## Where the records are stored
|
|
177
|
+
|
|
178
|
+
`local_dir="./recall-data"` keeps the database on this machine; the first
|
|
179
|
+
process to open the directory starts a `polign-server` for it in the
|
|
180
|
+
background, and later ones share it. Agents that move between machines need
|
|
181
|
+
one shared server: run `polign-server` where they can all reach it
|
|
182
|
+
([Get started](https://polign.com/developers.html) shows how, including
|
|
183
|
+
storing into S3, GCS or Azure) and pass its address through `env` or the
|
|
184
|
+
environment:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
RecallResume(
|
|
188
|
+
"billing-migrator",
|
|
189
|
+
env={"POLIGN_URL": "http://memory.internal:23000", "POLIGN_API_KEY": key},
|
|
190
|
+
)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
The agent's records live in their own collection next to the memory
|
|
194
|
+
collection (`<collection>_agents`).
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
cd python/recall-langgraph
|
|
200
|
+
python -m pip install -e . pytest pytest-asyncio
|
|
201
|
+
pytest tests/unit_tests -q # a fake Recall client, no network
|
|
202
|
+
pytest tests/integration_tests -v # real polign-server and polign CLI
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The integration tests locate the binaries like the other packages' tests do
|
|
206
|
+
(`POLIGN_SERVER`, `POLIGN_SOURCE`, `POLIGN_SERVER_VERSION`, or the latest
|
|
207
|
+
release download) and skip when none is found or when the CLI has no
|
|
208
|
+
`polign mcp -agent`. Both suites drive real compiled graphs with a scripted
|
|
209
|
+
chat model, so no model API key is needed.
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# recall-langgraph
|
|
2
|
+
|
|
3
|
+
Resume [LangGraph](https://github.com/langchain-ai/langgraph) agents from
|
|
4
|
+
their own records, backed by [Recall by Polign](https://polign.com/recall.html).
|
|
5
|
+
|
|
6
|
+
A long-running agent that crashes, gets rescheduled, or moves to another
|
|
7
|
+
machine usually starts over, or restores an exact snapshot of its state. With
|
|
8
|
+
this package it picks up where it left off from what it wrote down instead:
|
|
9
|
+
while it works, it keeps a working state (its goal, plan, progress and
|
|
10
|
+
decisions) and pointers to where its work lives, and every message of the run
|
|
11
|
+
is recorded. The next process that opens the same agent id gets a fresh
|
|
12
|
+
starting context built from those records, sized to a token budget.
|
|
13
|
+
|
|
14
|
+
This sits beside your checkpointer, not in place of it. LangGraph's
|
|
15
|
+
checkpointer still handles threads and interrupts however you configure it.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install recall-langgraph
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
pip also brings the [`polign_db`](https://pypi.org/project/polign-db/)
|
|
22
|
+
package with the `polign` CLI and `polign-server` binaries for Linux, macOS
|
|
23
|
+
and Windows, so there is no separate database to download.
|
|
24
|
+
|
|
25
|
+
## Usage with create_react_agent
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from langchain_openai import ChatOpenAI
|
|
29
|
+
from langgraph.prebuilt import create_react_agent
|
|
30
|
+
from recall_langgraph import RecallResume, recall_tools
|
|
31
|
+
|
|
32
|
+
with RecallResume("billing-migrator", local_dir="./recall-data") as resume:
|
|
33
|
+
agent = create_react_agent(
|
|
34
|
+
ChatOpenAI(model="gpt-4.1"),
|
|
35
|
+
tools=[*your_tools, *recall_tools(resume)],
|
|
36
|
+
prompt=(
|
|
37
|
+
"You move the billing service to the v2 API. Keep your working state "
|
|
38
|
+
"current with update_working_state, and call milestone when a step is done."
|
|
39
|
+
),
|
|
40
|
+
pre_model_hook=resume.pre_model_hook,
|
|
41
|
+
post_model_hook=resume.post_model_hook,
|
|
42
|
+
)
|
|
43
|
+
agent.invoke({"messages": [("user", "Carry on with the migration.")]})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Run it, stop it halfway, and run it again: the second run starts from the
|
|
47
|
+
working state, pointers and recent turns the first one wrote.
|
|
48
|
+
|
|
49
|
+
What happens:
|
|
50
|
+
|
|
51
|
+
1. Entering the `with` block resumes the agent. It takes a lease on the id,
|
|
52
|
+
so only one process acts for the agent at a time, and reads back its
|
|
53
|
+
records. The first time an id is used, it starts fresh.
|
|
54
|
+
2. Before every model call, `pre_model_hook` puts one `SystemMessage` in
|
|
55
|
+
front of the messages, the briefing: the working state, pointers to the
|
|
56
|
+
work, relevant memories, and the most recent turns, within
|
|
57
|
+
`token_budget`. It goes to the model as `llm_input_messages`, so the
|
|
58
|
+
graph's `messages` state never holds it.
|
|
59
|
+
3. The hooks record each new message once, in order, as a turn: human
|
|
60
|
+
messages before the model call, the model's reply right after it, and tool
|
|
61
|
+
results before the next call. A reply with tool calls is recorded with the
|
|
62
|
+
calls as JSON text. A turn longer than the output threshold is stored whole
|
|
63
|
+
as an output, and the briefing shows a reference the model can pass to
|
|
64
|
+
`fetch_output`.
|
|
65
|
+
4. The model keeps its working state current through the tools from
|
|
66
|
+
`recall_tools`.
|
|
67
|
+
5. Leaving the block (or calling `release()`) hands the lease over, so the
|
|
68
|
+
next process can resume at once. A process that dies without releasing
|
|
69
|
+
holds the lease until it expires (60 seconds by default).
|
|
70
|
+
|
|
71
|
+
Recall never replays old messages into the state: the briefing already
|
|
72
|
+
carries the recent turns as text, and a replayed tool result without its
|
|
73
|
+
matching tool call would be refused by the model API. On a new `thread_id`,
|
|
74
|
+
the resumed run starts from the briefing alone. On the old `thread_id`, a
|
|
75
|
+
persistent checkpointer restores the old messages as well, and nothing is
|
|
76
|
+
recorded twice: each turn keeps its message id, so the first recording after
|
|
77
|
+
a resume skips every restored message up to the last one Recall already has.
|
|
78
|
+
Messages after that one, such as the caller's new input or a reply the dead
|
|
79
|
+
process never recorded, are recorded as usual. The model then sees the
|
|
80
|
+
restored history and the briefing both; start a new thread if you would
|
|
81
|
+
rather it saw only the briefing.
|
|
82
|
+
|
|
83
|
+
`create_react_agent` is deprecated in LangGraph 1.0 in favor of
|
|
84
|
+
`langchain.agents.create_agent`, but it still ships in `langgraph.prebuilt`
|
|
85
|
+
and the hooks work with it. Use `version="v2"` (the default), since
|
|
86
|
+
`post_model_hook` needs it.
|
|
87
|
+
|
|
88
|
+
## Your own StateGraph
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from langgraph.graph import START, MessagesState, StateGraph
|
|
92
|
+
|
|
93
|
+
def call_model(state: MessagesState):
|
|
94
|
+
return {"messages": [model.invoke(resume.with_briefing(state["messages"]))]}
|
|
95
|
+
|
|
96
|
+
builder = StateGraph(MessagesState)
|
|
97
|
+
builder.add_node("model", call_model)
|
|
98
|
+
builder.add_node("record", resume.record_node)
|
|
99
|
+
builder.add_edge(START, "model")
|
|
100
|
+
builder.add_edge("model", "record")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- `with_briefing(messages)` returns the messages with the briefing in front,
|
|
104
|
+
for the model's input, and leaves the state alone.
|
|
105
|
+
- `record_node` records every message not recorded yet and changes nothing.
|
|
106
|
+
Put it after each node that adds messages. `record(messages)` does the same
|
|
107
|
+
from your own code.
|
|
108
|
+
- `briefing_node` adds the briefing to the `messages` state itself, once per
|
|
109
|
+
thread, if you would rather keep it there. Put it first.
|
|
110
|
+
|
|
111
|
+
The hooks and nodes work with `invoke` and `ainvoke`.
|
|
112
|
+
|
|
113
|
+
## The tools
|
|
114
|
+
|
|
115
|
+
| Tool | What the model uses it for |
|
|
116
|
+
|---|---|
|
|
117
|
+
| `update_working_state` | Save its goal, plan, progress, focus, decisions, open questions and notes. Fields it leaves out are kept. |
|
|
118
|
+
| `milestone` | Declare a durable point, such as tests passing. |
|
|
119
|
+
| `fetch_output` | Read a stored output in full by its ref. |
|
|
120
|
+
| `set_pointer` | Record where a piece of work lives: a git branch or commit, an object, an environment, an external item, or a process. |
|
|
121
|
+
|
|
122
|
+
A failed call comes back to the model as the tool's text. Your own code can
|
|
123
|
+
call `resume.update_working_state`, `resume.milestone`, `resume.fetch_output`
|
|
124
|
+
and `resume.set_pointer`, and `resume.agent` is the underlying
|
|
125
|
+
`polign_recall.ResumedAgent` for everything else (`record_turn`,
|
|
126
|
+
`recent_turns`, `store_output`, `pointers`, `working_state_history`).
|
|
127
|
+
`resume.context` is what the resume returned, and `resume.briefing` its text.
|
|
128
|
+
|
|
129
|
+
## Options
|
|
130
|
+
|
|
131
|
+
| Option | Default | What it does |
|
|
132
|
+
|---|---|---|
|
|
133
|
+
| `client` | none | A `polign_recall.Client` opened with `agent=True`, to share one subprocess. Without it, `RecallResume` opens its own and closes it on release. |
|
|
134
|
+
| `local_dir` | none | Keep the database in this directory and run its server (only when `RecallResume` opens its own client) |
|
|
135
|
+
| `env` | process environment | `POLIGN_URL`, `POLIGN_API_KEY` and the rest, for a server you run yourself |
|
|
136
|
+
| `token_budget` | 8000 | Bound on the briefing, in tokens |
|
|
137
|
+
| `lease_ttl` | 60 | Seconds each lease epoch lasts; renewed in the background |
|
|
138
|
+
| `holder` | host, pid and a random suffix | Names this process in lease records |
|
|
139
|
+
| `output_threshold` | 2000 | Turns longer than this many tokens are stored as outputs |
|
|
140
|
+
|
|
141
|
+
## Errors
|
|
142
|
+
|
|
143
|
+
If another process holds the agent, resuming raises
|
|
144
|
+
`polign_recall.RecallError` with code `"lease_held"`. Wait and try again, or
|
|
145
|
+
stop. If another process takes the agent over mid-run, the next record fails
|
|
146
|
+
with code `"lease_lost"`, which stops the graph run; this process should
|
|
147
|
+
stop acting for the agent.
|
|
148
|
+
|
|
149
|
+
Records are append-only. Removing or trimming messages in the graph state
|
|
150
|
+
changes what the model sees, never what was recorded.
|
|
151
|
+
|
|
152
|
+
## Where the records are stored
|
|
153
|
+
|
|
154
|
+
`local_dir="./recall-data"` keeps the database on this machine; the first
|
|
155
|
+
process to open the directory starts a `polign-server` for it in the
|
|
156
|
+
background, and later ones share it. Agents that move between machines need
|
|
157
|
+
one shared server: run `polign-server` where they can all reach it
|
|
158
|
+
([Get started](https://polign.com/developers.html) shows how, including
|
|
159
|
+
storing into S3, GCS or Azure) and pass its address through `env` or the
|
|
160
|
+
environment:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
RecallResume(
|
|
164
|
+
"billing-migrator",
|
|
165
|
+
env={"POLIGN_URL": "http://memory.internal:23000", "POLIGN_API_KEY": key},
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The agent's records live in their own collection next to the memory
|
|
170
|
+
collection (`<collection>_agents`).
|
|
171
|
+
|
|
172
|
+
## Development
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
cd python/recall-langgraph
|
|
176
|
+
python -m pip install -e . pytest pytest-asyncio
|
|
177
|
+
pytest tests/unit_tests -q # a fake Recall client, no network
|
|
178
|
+
pytest tests/integration_tests -v # real polign-server and polign CLI
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The integration tests locate the binaries like the other packages' tests do
|
|
182
|
+
(`POLIGN_SERVER`, `POLIGN_SOURCE`, `POLIGN_SERVER_VERSION`, or the latest
|
|
183
|
+
release download) and skip when none is found or when the CLI has no
|
|
184
|
+
`polign mcp -agent`. Both suites drive real compiled graphs with a scripted
|
|
185
|
+
chat model, so no model API key is needed.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "recall-langgraph"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Resume LangGraph agents from their own records, backed by Recall by Polign"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Polign" }]
|
|
14
|
+
keywords = ["langgraph", "langchain", "agent memory", "resume", "recall", "polign"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"License :: OSI Approved :: Apache Software License",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"polign-recall>=0.4.0",
|
|
25
|
+
"langgraph>=1.0,<2",
|
|
26
|
+
"langchain-core>=1.0,<2",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://polign.com"
|
|
31
|
+
Documentation = "https://polign.com/integrations.html"
|
|
32
|
+
Repository = "https://github.com/Polign/polign"
|
|
33
|
+
Issues = "https://github.com/Polign/polign/issues"
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build]
|
|
36
|
+
ignore-vcs = true
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.sdist]
|
|
39
|
+
include = ["recall_langgraph/", "tests/", "README.md", "LICENSE"]
|
|
40
|
+
exclude = ["**/__pycache__", "**/.pytest_cache"]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["recall_langgraph"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
asyncio_mode = "auto"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Recall by Polign for LangGraph.
|
|
2
|
+
|
|
3
|
+
``RecallResume`` resumes an agent from its own records: its working state,
|
|
4
|
+
pointers to its work, relevant memories and recent turns come back as a
|
|
5
|
+
briefing for the model, and the run's messages are recorded as turns for the
|
|
6
|
+
next resume. ``recall_tools`` gives the model the tools that keep those
|
|
7
|
+
records current. It sits beside your checkpointer; it does not replace it.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .resume import BRIEFING_ID, RecallResume
|
|
11
|
+
from .tools import recall_tools
|
|
12
|
+
|
|
13
|
+
__all__ = ["BRIEFING_ID", "RecallResume", "recall_tools"]
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from importlib.metadata import version as _version
|
|
17
|
+
|
|
18
|
+
__version__ = _version("recall-langgraph")
|
|
19
|
+
except Exception: # pragma: no cover - source checkout without metadata
|
|
20
|
+
__version__ = "0.1.0"
|