forkledger 0.4.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.
- forkledger-0.4.0/LICENSE +201 -0
- forkledger-0.4.0/PKG-INFO +432 -0
- forkledger-0.4.0/README.md +375 -0
- forkledger-0.4.0/pyproject.toml +94 -0
- forkledger-0.4.0/setup.cfg +4 -0
- forkledger-0.4.0/src/forkledger/__init__.py +55 -0
- forkledger-0.4.0/src/forkledger/api.py +352 -0
- forkledger-0.4.0/src/forkledger/cli.py +261 -0
- forkledger-0.4.0/src/forkledger/counterfactual.py +163 -0
- forkledger-0.4.0/src/forkledger/engine.py +348 -0
- forkledger-0.4.0/src/forkledger/integrations/__init__.py +1 -0
- forkledger-0.4.0/src/forkledger/integrations/autogen.py +326 -0
- forkledger-0.4.0/src/forkledger/integrations/langchain.py +344 -0
- forkledger-0.4.0/src/forkledger/mcp_server.py +317 -0
- forkledger-0.4.0/src/forkledger/models.py +93 -0
- forkledger-0.4.0/src/forkledger/policy.py +196 -0
- forkledger-0.4.0/src/forkledger/retrieval.py +389 -0
- forkledger-0.4.0/src/forkledger/storage.py +404 -0
- forkledger-0.4.0/src/forkledger/storage_pg.py +190 -0
- forkledger-0.4.0/src/forkledger.egg-info/PKG-INFO +432 -0
- forkledger-0.4.0/src/forkledger.egg-info/SOURCES.txt +24 -0
- forkledger-0.4.0/src/forkledger.egg-info/dependency_links.txt +1 -0
- forkledger-0.4.0/src/forkledger.egg-info/entry_points.txt +2 -0
- forkledger-0.4.0/src/forkledger.egg-info/requires.txt +40 -0
- forkledger-0.4.0/src/forkledger.egg-info/top_level.txt +1 -0
- forkledger-0.4.0/tests/test_engine.py +408 -0
forkledger-0.4.0/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 [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: forkledger
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Branch-based decision memory for AI agents — stores choices, alternatives, and regret.
|
|
5
|
+
Author: sliper82
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/sliper82/forkledger
|
|
8
|
+
Project-URL: Documentation, https://github.com/sliper82/forkledger#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/sliper82/forkledger
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/sliper82/forkledger/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/sliper82/forkledger/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: rust,performance,fts,ai,memory,agents,decision-engine,counterfactuals,regret,sqlite,fastapi,mcp,langchain,llm
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
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.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: api
|
|
25
|
+
Requires-Dist: fastapi>=0.110; extra == "api"
|
|
26
|
+
Requires-Dist: uvicorn[standard]>=0.29; extra == "api"
|
|
27
|
+
Requires-Dist: pydantic>=2.0; extra == "api"
|
|
28
|
+
Provides-Extra: embeddings
|
|
29
|
+
Requires-Dist: sentence-transformers>=2.7; extra == "embeddings"
|
|
30
|
+
Requires-Dist: numpy>=1.26; extra == "embeddings"
|
|
31
|
+
Provides-Extra: mcp
|
|
32
|
+
Requires-Dist: mcp>=1.0; extra == "mcp"
|
|
33
|
+
Requires-Dist: fastmcp>=0.1; extra == "mcp"
|
|
34
|
+
Provides-Extra: faiss
|
|
35
|
+
Requires-Dist: faiss-cpu>=1.7; extra == "faiss"
|
|
36
|
+
Provides-Extra: postgres
|
|
37
|
+
Requires-Dist: psycopg2-binary>=2.9; extra == "postgres"
|
|
38
|
+
Provides-Extra: dashboard
|
|
39
|
+
Requires-Dist: streamlit>=1.35; extra == "dashboard"
|
|
40
|
+
Requires-Dist: pandas>=2.0; extra == "dashboard"
|
|
41
|
+
Requires-Dist: altair>=5.0; extra == "dashboard"
|
|
42
|
+
Provides-Extra: all
|
|
43
|
+
Requires-Dist: fastapi>=0.110; extra == "all"
|
|
44
|
+
Requires-Dist: uvicorn[standard]>=0.29; extra == "all"
|
|
45
|
+
Requires-Dist: pydantic>=2.0; extra == "all"
|
|
46
|
+
Requires-Dist: sentence-transformers>=2.7; extra == "all"
|
|
47
|
+
Requires-Dist: numpy>=1.26; extra == "all"
|
|
48
|
+
Requires-Dist: mcp>=1.0; extra == "all"
|
|
49
|
+
Requires-Dist: fastmcp>=0.1; extra == "all"
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
52
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
53
|
+
Requires-Dist: fastapi>=0.110; extra == "dev"
|
|
54
|
+
Requires-Dist: pydantic>=2.0; extra == "dev"
|
|
55
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
56
|
+
Dynamic: license-file
|
|
57
|
+
|
|
58
|
+
<p align="center">
|
|
59
|
+
<img src=".github/assets/logo.png" width="720" alt="ForkLedger" />
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
<p align="center">
|
|
63
|
+
<a href="https://github.com/sliper82/forkledger/actions"><img src="https://github.com/sliper82/forkledger/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
|
|
64
|
+
<a href="https://github.com/sliper82/forkledger/releases"><img src="https://img.shields.io/github/v/release/sliper82/forkledger?color=40c8ff&label=version" alt="Version" /></a>
|
|
65
|
+
<img src="https://img.shields.io/badge/python-3.10%2B-blue" alt="Python 3.10+" />
|
|
66
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue" alt="License" /></a>
|
|
67
|
+
<a href="https://github.com/sliper82/forkledger/blob/main/COMPARISON.md"><img src="https://img.shields.io/badge/vs-Mem0%20%7C%20Hindsight%20%7C%20LangMem-555" alt="Comparison" /></a>
|
|
68
|
+
</p>
|
|
69
|
+
|
|
70
|
+
<p align="center">
|
|
71
|
+
<b>The memory layer your AI agents actually need.</b><br/>
|
|
72
|
+
Not what was said — but what was chosen, what it cost, and what to do differently next time.
|
|
73
|
+
</p>
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## The problem with AI memory today
|
|
78
|
+
|
|
79
|
+
Every major memory system stores **what happened**: messages, chunks, embeddings, facts.
|
|
80
|
+
|
|
81
|
+
None of them store **why a decision was made** — or what it cost.
|
|
82
|
+
|
|
83
|
+
That means every time your agent faces the same situation, it starts from zero. It can't learn from its own mistakes. It has no way to say: *"Last time I chose this, it cost me 3 points. Don't do it again."*
|
|
84
|
+
|
|
85
|
+
**ForkLedger fixes this.**
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## What ForkLedger stores
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
situation before the choice
|
|
93
|
+
↓
|
|
94
|
+
[ branch A ] [ branch B ✓ chosen ] [ branch C ]
|
|
95
|
+
↓
|
|
96
|
+
observed outcome
|
|
97
|
+
↓
|
|
98
|
+
regret vector — what each path cost relative to the best
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Over time, ForkLedger learns which branches produce the lowest regret under similar conditions — and surfaces that knowledge when it matters.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Install
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install forkledger # core — zero dependencies
|
|
109
|
+
pip install forkledger[mcp] # + MCP server (Claude Desktop, Cursor, VS Code)
|
|
110
|
+
pip install forkledger[api] # + REST API (FastAPI)
|
|
111
|
+
pip install forkledger[embeddings] # + semantic similarity
|
|
112
|
+
pip install forkledger[all] # everything
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 60-second demo
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from forkledger import ForkLedgerEngine, ForkRecord, Branch, OutcomeEstimate
|
|
121
|
+
|
|
122
|
+
engine = ForkLedgerEngine("decisions.db", backend="sqlite")
|
|
123
|
+
|
|
124
|
+
# Record a decision and its outcome
|
|
125
|
+
engine.add_record(ForkRecord(
|
|
126
|
+
fork_id = "trade-001",
|
|
127
|
+
pre_state = {"market": "BTC", "signal": "breakout", "volume": "high"},
|
|
128
|
+
trigger = "RSI crossed 70 with volume confirmation",
|
|
129
|
+
possible_branches = [Branch("enter"), Branch("wait"), Branch("short")],
|
|
130
|
+
chosen_branch = "enter",
|
|
131
|
+
realized_value = 2.4,
|
|
132
|
+
estimated_outcomes = [
|
|
133
|
+
OutcomeEstimate("wait", estimated_value=0.0),
|
|
134
|
+
OutcomeEstimate("short", estimated_value=-1.5),
|
|
135
|
+
],
|
|
136
|
+
confidence = 0.8,
|
|
137
|
+
tags = ["crypto", "momentum"],
|
|
138
|
+
))
|
|
139
|
+
|
|
140
|
+
# Update with actual result after the fact
|
|
141
|
+
engine.update_outcome("trade-001", realized_value=1.9)
|
|
142
|
+
|
|
143
|
+
# Ask: given this new situation, what should I do?
|
|
144
|
+
recs = engine.recommend(
|
|
145
|
+
current_state = {"market": "ETH", "signal": "breakout", "volume": "high"},
|
|
146
|
+
)
|
|
147
|
+
# → [{"branch": "enter", "score": 0.82}, ...]
|
|
148
|
+
|
|
149
|
+
# What patterns have emerged from repeated decisions?
|
|
150
|
+
policies = engine.policies()
|
|
151
|
+
# → [{"recommended_branch": "enter", "win_rate": {"enter": 0.72}, ...}]
|
|
152
|
+
|
|
153
|
+
# Win rates across all historical decisions
|
|
154
|
+
win_rates = engine.win_rates()
|
|
155
|
+
|
|
156
|
+
# CFR-style accumulated regret (time-decay weighted)
|
|
157
|
+
regret = engine.accumulated_regret()
|
|
158
|
+
|
|
159
|
+
# Full audit trail with effective weights
|
|
160
|
+
trail = engine.audit_trail()
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## MCP Server — works with Claude Desktop, Cursor, VS Code
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
pip install forkledger[mcp]
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Add to your Claude Desktop config (`~/.config/claude/claude_desktop_config.json`):
|
|
172
|
+
|
|
173
|
+
```json
|
|
174
|
+
{
|
|
175
|
+
"mcpServers": {
|
|
176
|
+
"forkledger": {
|
|
177
|
+
"command": "forkledger",
|
|
178
|
+
"args": ["mcp", "--store", "/path/to/decisions.db", "--backend", "sqlite"]
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Your Claude agent can now:
|
|
185
|
+
- `record_decision(...)` — store a decision with alternatives and outcome
|
|
186
|
+
- `get_recommendation(...)` — ask what worked in similar past situations
|
|
187
|
+
- `update_outcome(...)` — update realized value after observing results
|
|
188
|
+
- `get_policies(...)` — see distilled patterns from repeated decisions
|
|
189
|
+
- `list_decisions(...)` — browse decision history
|
|
190
|
+
- `memory_stats()` — store health and statistics
|
|
191
|
+
|
|
192
|
+
**No code required. Works with any MCP-compatible client.**
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## REST API
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
pip install forkledger[api]
|
|
200
|
+
forkledger serve --backend sqlite --store decisions.db
|
|
201
|
+
# → http://localhost:8000/docs (Swagger UI)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
| Method | Path | Description |
|
|
205
|
+
|--------|------|-------------|
|
|
206
|
+
| `GET` | `/health` | Health check |
|
|
207
|
+
| `GET` | `/stats` | Store statistics |
|
|
208
|
+
| `GET` | `/forks` | List (filterable by tags, confidence) |
|
|
209
|
+
| `POST` | `/forks` | Add one fork |
|
|
210
|
+
| `POST` | `/forks/bulk` | Bulk add |
|
|
211
|
+
| `PATCH` | `/forks/{id}/outcome` | Update realized value |
|
|
212
|
+
| `DELETE` | `/forks/{id}` | Delete |
|
|
213
|
+
| `DELETE` | `/forks/expired` | Purge expired |
|
|
214
|
+
| `POST` | `/recommend` | Get branch recommendations |
|
|
215
|
+
| `POST` | `/rank` | Rank forks by similarity |
|
|
216
|
+
| `GET` | `/policies` | Distilled policies |
|
|
217
|
+
| `GET` | `/win-rates` | Win rates per branch |
|
|
218
|
+
| `GET` | `/audit` | Decision audit trail |
|
|
219
|
+
| `GET` | `/export` | Export all as JSON |
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Docker
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
docker run -p 8000:8000 -v $(pwd)/data:/data \
|
|
227
|
+
ghcr.io/sliper82/forkledger:latest
|
|
228
|
+
|
|
229
|
+
# or with compose:
|
|
230
|
+
docker compose up
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Dashboard
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
pip install forkledger[dashboard]
|
|
239
|
+
forkledger dashboard --store decisions.db --backend sqlite
|
|
240
|
+
# → http://localhost:8501
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Visualize decision history, win rates, accumulated regret, and policies.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## CLI
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
forkledger add decisions.json # load from file
|
|
251
|
+
forkledger recommend --state '{"signal":"breakout"}' # get recommendation
|
|
252
|
+
forkledger update-outcome trade-001 1.9 # update outcome
|
|
253
|
+
forkledger policies --min-support 3 # distilled patterns
|
|
254
|
+
forkledger win-rates # branch win rates
|
|
255
|
+
forkledger accumulated-regret # CFR-weighted regret
|
|
256
|
+
forkledger audit --limit 20 # decision trail
|
|
257
|
+
forkledger stats # store health
|
|
258
|
+
forkledger serve --backend sqlite --port 8000 # REST API
|
|
259
|
+
forkledger mcp --backend sqlite # MCP server
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## What's unique about ForkLedger
|
|
265
|
+
|
|
266
|
+
| Concept | Description |
|
|
267
|
+
|---------|-------------|
|
|
268
|
+
| **Regret vector** | Computed automatically. `regret(branch) = best_value − branch_value`. Zero = best choice. |
|
|
269
|
+
| **Fuzzy policy clustering** | Groups similar (not just identical) states. Real-world agent states are never perfectly equal. |
|
|
270
|
+
| **Confidence decay** | Exponential time-weighting. Old evidence fades. Configurable half-life. |
|
|
271
|
+
| **CFR-style accumulation** | Weighted regret accumulates across history per branch, similar to Counterfactual Regret Minimization. |
|
|
272
|
+
| **Branch win rates** | How often each branch was the best available choice. |
|
|
273
|
+
| **Outcome update** | Update realized values after observing results. Regret is recomputed automatically. |
|
|
274
|
+
| **Zero dependencies** | Core library requires nothing. SQLite is stdlib. All extras are opt-in. |
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## How it compares
|
|
279
|
+
|
|
280
|
+
→ See [COMPARISON.md](COMPARISON.md) for a full side-by-side with Mem0, Hindsight, LangMem, and mcp-memory.
|
|
281
|
+
|
|
282
|
+
**Short version:** ForkLedger does not compete with those systems — it complements them. They store facts. ForkLedger stores decisions.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Architecture
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
ForkLedgerEngine
|
|
290
|
+
├── storage/
|
|
291
|
+
│ ├── JsonForkStore — flat file, zero deps
|
|
292
|
+
│ ├── SqliteForkStore — indexed, atomic, production
|
|
293
|
+
│ └── PostgresForkStore — cloud-native, pgvector
|
|
294
|
+
├── counterfactual.py — regret + decay + CFR accumulation
|
|
295
|
+
├── retrieval.py — scoring + optional embeddings
|
|
296
|
+
├── policy.py — fuzzy + exact policy distillation
|
|
297
|
+
├── mcp_server.py — MCP server (8 tools)
|
|
298
|
+
├── api.py — FastAPI REST (14 endpoints)
|
|
299
|
+
├── cli.py — CLI (18 commands)
|
|
300
|
+
└── dashboard/app.py — Streamlit UI
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**Retrieval scoring:**
|
|
304
|
+
|
|
305
|
+
| Signal | Weight |
|
|
306
|
+
|--------|--------|
|
|
307
|
+
| State similarity | 45% |
|
|
308
|
+
| Constraint match | 20% |
|
|
309
|
+
| Recency | 15% |
|
|
310
|
+
| Confidence | 10% |
|
|
311
|
+
| Regret salience | 10% |
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Benchmark results
|
|
316
|
+
|
|
317
|
+
```
|
|
318
|
+
ForkLedger Benchmark — 300 records, 80 queries
|
|
319
|
+
Load: 2.19s (137 rec/s)
|
|
320
|
+
Latency: p50=5.6ms p95=25.9ms
|
|
321
|
+
Precision@1: 100.0%
|
|
322
|
+
Policy accuracy: 4/4 = 100.0%
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Run yourself:
|
|
326
|
+
```bash
|
|
327
|
+
python benchmarks/locomo_benchmark.py --records 500 --queries 100
|
|
328
|
+
```
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## Integrations
|
|
332
|
+
|
|
333
|
+
### LangChain
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
pip install forkledger[langchain]
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
```python
|
|
340
|
+
from forkledger.integrations.langchain import ForkLedgerMemory
|
|
341
|
+
|
|
342
|
+
memory = ForkLedgerMemory(
|
|
343
|
+
store_path="decisions.db",
|
|
344
|
+
backend="sqlite",
|
|
345
|
+
agent_id="my-agent",
|
|
346
|
+
domain="research", # pre-tuned scoring weights
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
# Record decisions manually
|
|
350
|
+
memory.record_decision(
|
|
351
|
+
fork_id="dec-001",
|
|
352
|
+
situation={"task": "research", "signal": "mixed"},
|
|
353
|
+
trigger="Conflicting sources",
|
|
354
|
+
chosen="verify",
|
|
355
|
+
alternatives=["fast-publish", "wait"],
|
|
356
|
+
outcome=1.8,
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
# Or use as drop-in with ConversationChain
|
|
360
|
+
from langchain.chains import ConversationChain
|
|
361
|
+
chain = ConversationChain(llm=llm, memory=memory)
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### AutoGen
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
pip install forkledger[autogen]
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
from autogen import AssistantAgent
|
|
372
|
+
from forkledger.integrations.autogen import ForkLedgerHook
|
|
373
|
+
|
|
374
|
+
hook = ForkLedgerHook(
|
|
375
|
+
store_path="decisions.db",
|
|
376
|
+
backend="sqlite",
|
|
377
|
+
agent_id="assistant",
|
|
378
|
+
domain="code",
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
# Attach to any AutoGen agent
|
|
382
|
+
assistant = AssistantAgent("assistant", llm_config=llm_config)
|
|
383
|
+
hook.attach(assistant) # injects decision context into every message
|
|
384
|
+
|
|
385
|
+
# Or use standalone
|
|
386
|
+
hook.record(
|
|
387
|
+
situation={"task": "web_research", "sources": "multiple"},
|
|
388
|
+
trigger="Conflicting data",
|
|
389
|
+
chosen="verify_cross_reference",
|
|
390
|
+
alternatives=["use_first", "skip"],
|
|
391
|
+
outcome=2.1,
|
|
392
|
+
)
|
|
393
|
+
recs = hook.recommend({"task": "web_research", "sources": "multiple"})
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## Roadmap
|
|
400
|
+
|
|
401
|
+
- [x] SQLite + JSON backends
|
|
402
|
+
- [x] REST API (FastAPI)
|
|
403
|
+
- [x] MCP server (Claude Desktop, Cursor, VS Code)
|
|
404
|
+
- [x] Fuzzy policy clustering
|
|
405
|
+
- [x] Confidence decay + CFR-style accumulation
|
|
406
|
+
- [x] Branch win rates + audit trail
|
|
407
|
+
- [x] PostgreSQL + pgvector backend
|
|
408
|
+
- [x] Streamlit dashboard
|
|
409
|
+
- [x] Benchmark suite
|
|
410
|
+
- [x] LangChain official memory adapter (`ForkLedgerMemory`)
|
|
411
|
+
- [x] AutoGen integration (`ForkLedgerHook`, `ForkLedgerGroupChatManager`)
|
|
412
|
+
- [x] PyPI release — `pip install forkledger`
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## Contributing
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
git clone https://github.com/sliper82/forkledger
|
|
420
|
+
cd forkledger
|
|
421
|
+
pip install -e ".[dev]"
|
|
422
|
+
pytest
|
|
423
|
+
python benchmarks/locomo_benchmark.py
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
Issues, PRs, and ideas welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
## License
|
|
431
|
+
|
|
432
|
+
[Apache 2.0](LICENSE)
|