earcon 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.
- earcon-0.1.0/LICENSE +202 -0
- earcon-0.1.0/PKG-INFO +182 -0
- earcon-0.1.0/README.md +155 -0
- earcon-0.1.0/earcon/__init__.py +10 -0
- earcon-0.1.0/earcon/cli.py +72 -0
- earcon-0.1.0/earcon/core/__init__.py +5 -0
- earcon-0.1.0/earcon/core/advantage.py +51 -0
- earcon-0.1.0/earcon/core/backends.py +148 -0
- earcon-0.1.0/earcon/core/judge.py +67 -0
- earcon-0.1.0/earcon/core/memory.py +94 -0
- earcon-0.1.0/earcon/core/policy.py +62 -0
- earcon-0.1.0/earcon/gateway/__init__.py +316 -0
- earcon-0.1.0/earcon.egg-info/PKG-INFO +182 -0
- earcon-0.1.0/earcon.egg-info/SOURCES.txt +23 -0
- earcon-0.1.0/earcon.egg-info/dependency_links.txt +1 -0
- earcon-0.1.0/earcon.egg-info/entry_points.txt +2 -0
- earcon-0.1.0/earcon.egg-info/requires.txt +10 -0
- earcon-0.1.0/earcon.egg-info/top_level.txt +1 -0
- earcon-0.1.0/pyproject.toml +34 -0
- earcon-0.1.0/setup.cfg +4 -0
- earcon-0.1.0/setup.py +9 -0
- earcon-0.1.0/tests/test_core.py +63 -0
- earcon-0.1.0/tests/test_gateway.py +148 -0
- earcon-0.1.0/tests/test_judge.py +45 -0
- earcon-0.1.0/tests/test_policy.py +64 -0
earcon-0.1.0/LICENSE
ADDED
|
@@ -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.
|
earcon-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: earcon
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A self-evolving memory proxy for OpenAI-compatible clients: any LLM app gets experience-driven learning by changing one baseURL.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Keywords: llm,agents,memory,self-improvement,jitrl,proxy,reinforcement-learning
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Provides-Extra: gateway
|
|
20
|
+
Requires-Dist: fastapi>=0.100; extra == "gateway"
|
|
21
|
+
Requires-Dist: uvicorn>=0.23; extra == "gateway"
|
|
22
|
+
Provides-Extra: openai
|
|
23
|
+
Requires-Dist: openai>=1.0; extra == "openai"
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# earcon
|
|
29
|
+
|
|
30
|
+
**A self-evolving memory proxy for OpenAI-compatible clients.**
|
|
31
|
+
Point your app's `base_url` at earcon, keep working normally - the model
|
|
32
|
+
starts learning from every session, with **zero weight updates** and
|
|
33
|
+
**zero client changes beyond one URL**.
|
|
34
|
+
|
|
35
|
+
- **What it is**: a local proxy that records your LLM sessions, has a
|
|
36
|
+
judge distill them into experience cards (a decision + a score), and
|
|
37
|
+
injects the relevant experience into future similar sessions.
|
|
38
|
+
- **What it is not**: not fine-tuning, not another RAG memory of user
|
|
39
|
+
facts. It stores *behavioral* experience with returns - "this approach
|
|
40
|
+
worked, that one failed" - and changes decisions, not just knowledge.
|
|
41
|
+
- **Lineage**: mechanisms from [JitRL: Just-In-Time Reinforcement
|
|
42
|
+
Learning](https://arxiv.org/abs/2601.18510) (ICML 2026 Spotlight):
|
|
43
|
+
non-parametric experience memory, advantage estimation, and
|
|
44
|
+
experience-driven action reweighting - realized for free-text agents.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
your app (any OpenAI SDK / LangGraph / coding client ...)
|
|
48
|
+
│ change one base_url
|
|
49
|
+
▼
|
|
50
|
+
earcon gateway ──① inject experience──▶ upstream LLM (frozen weights)
|
|
51
|
+
│ ② record every turn
|
|
52
|
+
▼
|
|
53
|
+
③ judge on session close ──▶ ④ SQLite experience cards ──▶ back to ①
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+

|
|
57
|
+
|
|
58
|
+
## Why not just mem0 / Letta / Zep?
|
|
59
|
+
|
|
60
|
+
Those store *facts* ("the user prefers concise answers") and retrieve
|
|
61
|
+
them into context. earcon stores **scored behavior** and follows the
|
|
62
|
+
JitRL loop:
|
|
63
|
+
|
|
64
|
+
| | fact memories (mem0 et al.) | earcon |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| Stored unit | "user likes X" | "decision D on task T scored -3" |
|
|
67
|
+
| Signal | none (storage only) | return / judge credit assignment |
|
|
68
|
+
| Changes decisions? | indirectly, via recall | directly - experience is *retrieved by task similarity and weighted by outcome* |
|
|
69
|
+
| Auditable | depends | one SQLite file, every card inspectable |
|
|
70
|
+
| Intrusive | SDK / API changes | one `base_url` swap |
|
|
71
|
+
|
|
72
|
+
## Quickstart
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# legacy pip (<22) mishandles pyproject-only git installs (UNKNOWN-0.0.0):
|
|
76
|
+
python3 -m pip install --upgrade pip
|
|
77
|
+
|
|
78
|
+
# from GitHub (PyPI coming soon):
|
|
79
|
+
python3 -m pip install "git+https://github.com/370540009gg-cmd/earcon.git"
|
|
80
|
+
# extras: "earcon[gateway,openai]" via pip, or install fastapi/uvicorn yourself
|
|
81
|
+
|
|
82
|
+
# terminal 1: run the gateway against any OpenAI-compatible upstream
|
|
83
|
+
earcon serve --upstream https://api.openai.com/v1 \
|
|
84
|
+
--api-key $OPENAI_API_KEY --judge-model gpt-4o-mini
|
|
85
|
+
|
|
86
|
+
# terminal 2: any OpenAI app, one line changed
|
|
87
|
+
# OpenAI(base_url="http://127.0.0.1:8800/v1", ...)
|
|
88
|
+
python examples/quickstart_client.py
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Work normally. Sessions close (30 min idle, or explicit
|
|
92
|
+
`POST /v1/earcon/session/default/close`), the judge distills cards,
|
|
93
|
+
and future similar requests arrive pre-loaded with your own track
|
|
94
|
+
record:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
curl http://127.0.0.1:8800/v1/earcon/stats
|
|
98
|
+
# {"cards": 14, "sessions_open": 1, "inject": true}
|
|
99
|
+
|
|
100
|
+
sqlite3 earcon_memory.db "SELECT task, action, G FROM cards LIMIT 5"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Start in observation mode** while you assess your judge's card
|
|
104
|
+
quality: `earcon serve ... --no-inject`. The judge is the quality
|
|
105
|
+
ceiling of the whole system.
|
|
106
|
+
|
|
107
|
+
## Does it actually work?
|
|
108
|
+
|
|
109
|
+
The discrete-action path is verified in `examples/treasure_maze/` - a
|
|
110
|
+
toy environment where traps sit on the intuitive routes, so avoiding
|
|
111
|
+
them is *only* knowable through experience:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# control arm (frozen behavior): ~2% win, 4.0 trap falls / episode
|
|
115
|
+
python examples/treasure_maze/run.py --episodes 150 --seed 2 --no-memory
|
|
116
|
+
|
|
117
|
+
# earcon learning arm: ~43% win (up to 100% in late windows),
|
|
118
|
+
python examples/treasure_maze/run.py --episodes 150 --seed 2
|
|
119
|
+
# 1.0 falls/episode, 10.5 steps vs 6 optimal
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The learned advantage at the trap-adjacent cells comes out correctly
|
|
123
|
+
signed - memory, not luck. See `docs/how-it-works.md` for the full
|
|
124
|
+
loop, and the honest list of conditions under which it *won't* work.
|
|
125
|
+
|
|
126
|
+
## How it works
|
|
127
|
+
|
|
128
|
+
1. **Record** - every turn flows through the gateway transparently
|
|
129
|
+
(streaming included) into a session buffer.
|
|
130
|
+
2. **Judge** - on session close, a background judge call distills 1-5
|
|
131
|
+
experience cards ("decision=...; score -3..+3").
|
|
132
|
+
3. **Retrieve & inject** - the next session's first user message is
|
|
133
|
+
matched against past cards; the top matches join the system prompt.
|
|
134
|
+
|
|
135
|
+
For **enumerable action spaces** (agents, tools), `earcon.core`
|
|
136
|
+
implements the paper's full path: per-option logits from `logprobs`,
|
|
137
|
+
advantage `A = Q - V` with small-sample shrinkage, and the closed-form
|
|
138
|
+
update `z' = z + βA`. The maze example runs it end to end.
|
|
139
|
+
|
|
140
|
+
Details and design corrections: `docs/how-it-works.md` · client
|
|
141
|
+
integration guide: `docs/client-integration.md`.
|
|
142
|
+
|
|
143
|
+
## Configuration
|
|
144
|
+
|
|
145
|
+
`earcon serve --upstream URL --judge-model M [--api-key K]
|
|
146
|
+
[--db FILE] [--port 8800] [--no-inject] [--session-timeout 1800]
|
|
147
|
+
[--inject-top-k 5] [--judge-extra-body '{"thinking":{"type":"off"}}']`
|
|
148
|
+
|
|
149
|
+
- Credentials: `EARCON_API_KEY` env var or `--api-key`. The gateway
|
|
150
|
+
rewrites client keys with its own, so clients need no real key.
|
|
151
|
+
- Vendor-private judge parameters (e.g. disabling a reasoning mode for
|
|
152
|
+
the scoring call) go through `--judge-extra-body`; nothing
|
|
153
|
+
non-standard is sent by default.
|
|
154
|
+
|
|
155
|
+
## Honest limitations
|
|
156
|
+
|
|
157
|
+
- **The judge is the ceiling.** A shallow judge produces noisy cards;
|
|
158
|
+
start with `--no-inject` and audit them.
|
|
159
|
+
- **Injection, not logits, on the main path** - most hosted gateways
|
|
160
|
+
don't expose `logprobs`, so free-text learning happens through
|
|
161
|
+
context. The full logit path needs a `logprobs`-capable upstream
|
|
162
|
+
(vLLM etc.) and lives in `earcon.core`.
|
|
163
|
+
- **Cold start requires a working base.** If the model never succeeds,
|
|
164
|
+
there are no positive cards to reinforce (JitRL has the same
|
|
165
|
+
constraint). Rough sweet spot: base success in the 20-60% band.
|
|
166
|
+
- **Single-user, single-process.** No multi-tenant isolation; memory is
|
|
167
|
+
one SQLite file. The session reaper is a background thread, not a
|
|
168
|
+
distributed system.
|
|
169
|
+
- **Task matching is keyword-based.** Deliberately (it beat embeddings
|
|
170
|
+
in our maze experiments and needs no infra), but it's simple.
|
|
171
|
+
|
|
172
|
+
## Roadmap
|
|
173
|
+
|
|
174
|
+
- [ ] Hermes agent `MemoryProvider` adapter
|
|
175
|
+
- [ ] Server-side logit bias via vLLM `logit_bias` (true step-level steering)
|
|
176
|
+
- [ ] Card editor / curation CLI
|
|
177
|
+
- [ ] Multi-namespace memory (per-project, per-tenant)
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
Apache-2.0. Built on the mechanisms of [JitRL](https://arxiv.org/abs/2601.18510)
|
|
182
|
+
(Barrett et al.) - if you use earcon in research, please cite the paper.
|
earcon-0.1.0/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# earcon
|
|
2
|
+
|
|
3
|
+
**A self-evolving memory proxy for OpenAI-compatible clients.**
|
|
4
|
+
Point your app's `base_url` at earcon, keep working normally - the model
|
|
5
|
+
starts learning from every session, with **zero weight updates** and
|
|
6
|
+
**zero client changes beyond one URL**.
|
|
7
|
+
|
|
8
|
+
- **What it is**: a local proxy that records your LLM sessions, has a
|
|
9
|
+
judge distill them into experience cards (a decision + a score), and
|
|
10
|
+
injects the relevant experience into future similar sessions.
|
|
11
|
+
- **What it is not**: not fine-tuning, not another RAG memory of user
|
|
12
|
+
facts. It stores *behavioral* experience with returns - "this approach
|
|
13
|
+
worked, that one failed" - and changes decisions, not just knowledge.
|
|
14
|
+
- **Lineage**: mechanisms from [JitRL: Just-In-Time Reinforcement
|
|
15
|
+
Learning](https://arxiv.org/abs/2601.18510) (ICML 2026 Spotlight):
|
|
16
|
+
non-parametric experience memory, advantage estimation, and
|
|
17
|
+
experience-driven action reweighting - realized for free-text agents.
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
your app (any OpenAI SDK / LangGraph / coding client ...)
|
|
21
|
+
│ change one base_url
|
|
22
|
+
▼
|
|
23
|
+
earcon gateway ──① inject experience──▶ upstream LLM (frozen weights)
|
|
24
|
+
│ ② record every turn
|
|
25
|
+
▼
|
|
26
|
+
③ judge on session close ──▶ ④ SQLite experience cards ──▶ back to ①
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
## Why not just mem0 / Letta / Zep?
|
|
32
|
+
|
|
33
|
+
Those store *facts* ("the user prefers concise answers") and retrieve
|
|
34
|
+
them into context. earcon stores **scored behavior** and follows the
|
|
35
|
+
JitRL loop:
|
|
36
|
+
|
|
37
|
+
| | fact memories (mem0 et al.) | earcon |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| Stored unit | "user likes X" | "decision D on task T scored -3" |
|
|
40
|
+
| Signal | none (storage only) | return / judge credit assignment |
|
|
41
|
+
| Changes decisions? | indirectly, via recall | directly - experience is *retrieved by task similarity and weighted by outcome* |
|
|
42
|
+
| Auditable | depends | one SQLite file, every card inspectable |
|
|
43
|
+
| Intrusive | SDK / API changes | one `base_url` swap |
|
|
44
|
+
|
|
45
|
+
## Quickstart
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# legacy pip (<22) mishandles pyproject-only git installs (UNKNOWN-0.0.0):
|
|
49
|
+
python3 -m pip install --upgrade pip
|
|
50
|
+
|
|
51
|
+
# from GitHub (PyPI coming soon):
|
|
52
|
+
python3 -m pip install "git+https://github.com/370540009gg-cmd/earcon.git"
|
|
53
|
+
# extras: "earcon[gateway,openai]" via pip, or install fastapi/uvicorn yourself
|
|
54
|
+
|
|
55
|
+
# terminal 1: run the gateway against any OpenAI-compatible upstream
|
|
56
|
+
earcon serve --upstream https://api.openai.com/v1 \
|
|
57
|
+
--api-key $OPENAI_API_KEY --judge-model gpt-4o-mini
|
|
58
|
+
|
|
59
|
+
# terminal 2: any OpenAI app, one line changed
|
|
60
|
+
# OpenAI(base_url="http://127.0.0.1:8800/v1", ...)
|
|
61
|
+
python examples/quickstart_client.py
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Work normally. Sessions close (30 min idle, or explicit
|
|
65
|
+
`POST /v1/earcon/session/default/close`), the judge distills cards,
|
|
66
|
+
and future similar requests arrive pre-loaded with your own track
|
|
67
|
+
record:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
curl http://127.0.0.1:8800/v1/earcon/stats
|
|
71
|
+
# {"cards": 14, "sessions_open": 1, "inject": true}
|
|
72
|
+
|
|
73
|
+
sqlite3 earcon_memory.db "SELECT task, action, G FROM cards LIMIT 5"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Start in observation mode** while you assess your judge's card
|
|
77
|
+
quality: `earcon serve ... --no-inject`. The judge is the quality
|
|
78
|
+
ceiling of the whole system.
|
|
79
|
+
|
|
80
|
+
## Does it actually work?
|
|
81
|
+
|
|
82
|
+
The discrete-action path is verified in `examples/treasure_maze/` - a
|
|
83
|
+
toy environment where traps sit on the intuitive routes, so avoiding
|
|
84
|
+
them is *only* knowable through experience:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# control arm (frozen behavior): ~2% win, 4.0 trap falls / episode
|
|
88
|
+
python examples/treasure_maze/run.py --episodes 150 --seed 2 --no-memory
|
|
89
|
+
|
|
90
|
+
# earcon learning arm: ~43% win (up to 100% in late windows),
|
|
91
|
+
python examples/treasure_maze/run.py --episodes 150 --seed 2
|
|
92
|
+
# 1.0 falls/episode, 10.5 steps vs 6 optimal
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The learned advantage at the trap-adjacent cells comes out correctly
|
|
96
|
+
signed - memory, not luck. See `docs/how-it-works.md` for the full
|
|
97
|
+
loop, and the honest list of conditions under which it *won't* work.
|
|
98
|
+
|
|
99
|
+
## How it works
|
|
100
|
+
|
|
101
|
+
1. **Record** - every turn flows through the gateway transparently
|
|
102
|
+
(streaming included) into a session buffer.
|
|
103
|
+
2. **Judge** - on session close, a background judge call distills 1-5
|
|
104
|
+
experience cards ("decision=...; score -3..+3").
|
|
105
|
+
3. **Retrieve & inject** - the next session's first user message is
|
|
106
|
+
matched against past cards; the top matches join the system prompt.
|
|
107
|
+
|
|
108
|
+
For **enumerable action spaces** (agents, tools), `earcon.core`
|
|
109
|
+
implements the paper's full path: per-option logits from `logprobs`,
|
|
110
|
+
advantage `A = Q - V` with small-sample shrinkage, and the closed-form
|
|
111
|
+
update `z' = z + βA`. The maze example runs it end to end.
|
|
112
|
+
|
|
113
|
+
Details and design corrections: `docs/how-it-works.md` · client
|
|
114
|
+
integration guide: `docs/client-integration.md`.
|
|
115
|
+
|
|
116
|
+
## Configuration
|
|
117
|
+
|
|
118
|
+
`earcon serve --upstream URL --judge-model M [--api-key K]
|
|
119
|
+
[--db FILE] [--port 8800] [--no-inject] [--session-timeout 1800]
|
|
120
|
+
[--inject-top-k 5] [--judge-extra-body '{"thinking":{"type":"off"}}']`
|
|
121
|
+
|
|
122
|
+
- Credentials: `EARCON_API_KEY` env var or `--api-key`. The gateway
|
|
123
|
+
rewrites client keys with its own, so clients need no real key.
|
|
124
|
+
- Vendor-private judge parameters (e.g. disabling a reasoning mode for
|
|
125
|
+
the scoring call) go through `--judge-extra-body`; nothing
|
|
126
|
+
non-standard is sent by default.
|
|
127
|
+
|
|
128
|
+
## Honest limitations
|
|
129
|
+
|
|
130
|
+
- **The judge is the ceiling.** A shallow judge produces noisy cards;
|
|
131
|
+
start with `--no-inject` and audit them.
|
|
132
|
+
- **Injection, not logits, on the main path** - most hosted gateways
|
|
133
|
+
don't expose `logprobs`, so free-text learning happens through
|
|
134
|
+
context. The full logit path needs a `logprobs`-capable upstream
|
|
135
|
+
(vLLM etc.) and lives in `earcon.core`.
|
|
136
|
+
- **Cold start requires a working base.** If the model never succeeds,
|
|
137
|
+
there are no positive cards to reinforce (JitRL has the same
|
|
138
|
+
constraint). Rough sweet spot: base success in the 20-60% band.
|
|
139
|
+
- **Single-user, single-process.** No multi-tenant isolation; memory is
|
|
140
|
+
one SQLite file. The session reaper is a background thread, not a
|
|
141
|
+
distributed system.
|
|
142
|
+
- **Task matching is keyword-based.** Deliberately (it beat embeddings
|
|
143
|
+
in our maze experiments and needs no infra), but it's simple.
|
|
144
|
+
|
|
145
|
+
## Roadmap
|
|
146
|
+
|
|
147
|
+
- [ ] Hermes agent `MemoryProvider` adapter
|
|
148
|
+
- [ ] Server-side logit bias via vLLM `logit_bias` (true step-level steering)
|
|
149
|
+
- [ ] Card editor / curation CLI
|
|
150
|
+
- [ ] Multi-namespace memory (per-project, per-tenant)
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
Apache-2.0. Built on the mechanisms of [JitRL](https://arxiv.org/abs/2601.18510)
|
|
155
|
+
(Barrett et al.) - if you use earcon in research, please cite the paper.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Earcon: a self-evolving memory proxy for OpenAI-compatible clients.
|
|
2
|
+
|
|
3
|
+
Any LLM application gets experience-driven learning by changing one
|
|
4
|
+
baseURL. Model weights stay frozen; experience is accumulated,
|
|
5
|
+
adjudicated, and injected as context. See docs/how-it-works.md.
|
|
6
|
+
|
|
7
|
+
Based on the mechanisms of JitRL (arXiv:2601.18510).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""CLI: `earcon serve` starts the learning proxy.
|
|
3
|
+
|
|
4
|
+
Examples:
|
|
5
|
+
earcon serve --upstream https://api.openai.com/v1 --api-key $KEY \
|
|
6
|
+
--judge-model gpt-4o-mini --port 8800
|
|
7
|
+
|
|
8
|
+
# pure observation (no injection) while you assess judge quality:
|
|
9
|
+
earcon serve --upstream ... --no-inject
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def build_parser():
|
|
18
|
+
p = argparse.ArgumentParser(prog="earcon", description=__doc__)
|
|
19
|
+
sub = p.add_subparsers(dest="cmd")
|
|
20
|
+
serve = sub.add_parser("serve", help="run the learning proxy gateway")
|
|
21
|
+
serve.add_argument("--upstream", required=True,
|
|
22
|
+
help="OpenAI-compatible upstream base URL, e.g. "
|
|
23
|
+
"https://api.openai.com/v1 "
|
|
24
|
+
"(env: EARCON_UPSTREAM)")
|
|
25
|
+
serve.add_argument("--api-key", default=os.environ.get("EARCON_API_KEY", ""),
|
|
26
|
+
help="key used for upstream calls; clients' own keys "
|
|
27
|
+
"are ignored (env: EARCON_API_KEY)")
|
|
28
|
+
serve.add_argument("--port", type=int, default=8800)
|
|
29
|
+
serve.add_argument("--db", default="earcon_memory.db")
|
|
30
|
+
serve.add_argument("--judge-model", required=True,
|
|
31
|
+
help="model used for credit assignment")
|
|
32
|
+
serve.add_argument("--no-inject", action="store_true",
|
|
33
|
+
help="record-only mode: judge sessions, never inject")
|
|
34
|
+
serve.add_argument("--judge-extra-body", default=None,
|
|
35
|
+
help="JSON object merged into judge requests, for "
|
|
36
|
+
"vendor-private params (e.g. disabling a "
|
|
37
|
+
"reasoning mode). Never sent to the main path.")
|
|
38
|
+
serve.add_argument("--session-timeout", type=float, default=1800,
|
|
39
|
+
help="seconds of inactivity before a session is "
|
|
40
|
+
"closed and judged (default 1800)")
|
|
41
|
+
serve.add_argument("--inject-top-k", type=int, default=5)
|
|
42
|
+
return p
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main(argv=None):
|
|
46
|
+
p = build_parser()
|
|
47
|
+
args = p.parse_args(argv)
|
|
48
|
+
if args.cmd != "serve":
|
|
49
|
+
p.print_help()
|
|
50
|
+
return 2
|
|
51
|
+
|
|
52
|
+
extra = json.loads(args.judge_extra_body) if args.judge_extra_body else None
|
|
53
|
+
|
|
54
|
+
# local imports so the core library never requires fastapi
|
|
55
|
+
from earcon.gateway import Gateway, create_app
|
|
56
|
+
gw = Gateway(upstream=args.upstream, api_key=args.api_key,
|
|
57
|
+
db_path=args.db, judge_model=args.judge_model,
|
|
58
|
+
inject=not args.no_inject, extra_body=extra,
|
|
59
|
+
config={"session_timeout": args.session_timeout,
|
|
60
|
+
"inject_top_k": args.inject_top_k})
|
|
61
|
+
app = create_app(gw)
|
|
62
|
+
|
|
63
|
+
import uvicorn
|
|
64
|
+
print("earcon gateway: http://127.0.0.1:%d -> %s" % (args.port, args.upstream))
|
|
65
|
+
print("memory: %s | mode: %s" % (args.db,
|
|
66
|
+
"record+inject" if gw.inject else "record-only"))
|
|
67
|
+
uvicorn.run(app, host="127.0.0.1", port=args.port, log_level="warning")
|
|
68
|
+
return 0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
raise SystemExit(main())
|