hermes-context-tuner 0.2.0b1__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.
- hermes_context_tuner-0.2.0b1/.github/workflows/tests.yml +22 -0
- hermes_context_tuner-0.2.0b1/.gitignore +9 -0
- hermes_context_tuner-0.2.0b1/CONTRIBUTING.md +37 -0
- hermes_context_tuner-0.2.0b1/LICENSE +201 -0
- hermes_context_tuner-0.2.0b1/PKG-INFO +163 -0
- hermes_context_tuner-0.2.0b1/README.md +137 -0
- hermes_context_tuner-0.2.0b1/RELEASE_NOTES.md +49 -0
- hermes_context_tuner-0.2.0b1/SECURITY.md +42 -0
- hermes_context_tuner-0.2.0b1/docs/ARCHITECTURE.md +56 -0
- hermes_context_tuner-0.2.0b1/docs/INTEGRATION.md +108 -0
- hermes_context_tuner-0.2.0b1/examples/config.yaml.example +10 -0
- hermes_context_tuner-0.2.0b1/examples/skills/optimize-context/SKILL.md +52 -0
- hermes_context_tuner-0.2.0b1/pyproject.toml +46 -0
- hermes_context_tuner-0.2.0b1/src/hermes_context_tuner/__init__.py +23 -0
- hermes_context_tuner-0.2.0b1/src/hermes_context_tuner/budget.py +119 -0
- hermes_context_tuner-0.2.0b1/src/hermes_context_tuner/cli.py +56 -0
- hermes_context_tuner-0.2.0b1/src/hermes_context_tuner/engine.py +201 -0
- hermes_context_tuner-0.2.0b1/src/hermes_context_tuner/hermes_engine/__init__.py +21 -0
- hermes_context_tuner-0.2.0b1/src/hermes_context_tuner/hermes_engine/plugin.yaml +4 -0
- hermes_context_tuner-0.2.0b1/src/hermes_context_tuner/recovery.py +127 -0
- hermes_context_tuner-0.2.0b1/tests/test_core.py +33 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
fail-fast: false
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ['3.10', '3.11', '3.12']
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- run: python -m pip install --upgrade pip build pytest
|
|
20
|
+
- run: python -m pip install -e .
|
|
21
|
+
- run: PYTHONPATH=src python -m pytest tests -q -o 'addopts='
|
|
22
|
+
- run: python -m build
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for helping improve Hermes Context Tuner.
|
|
4
|
+
|
|
5
|
+
## Development setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/tier4research/hermes-context-tuner.git
|
|
9
|
+
cd hermes-context-tuner
|
|
10
|
+
python -m pip install -e .
|
|
11
|
+
PYTHONPATH=src python -m pytest tests -q -o 'addopts='
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Design principles
|
|
15
|
+
|
|
16
|
+
1. **Do not fork Hermes compression.** Delegate to Hermes' built-in compressor unless there is a very explicit reason not to.
|
|
17
|
+
2. **Do not monkey-patch Hermes private methods.** Use the `ContextEngine` seam.
|
|
18
|
+
3. **Audit must never block compression.** Recovery/audit sidecar writes are best-effort.
|
|
19
|
+
4. **Store metadata, not raw transcript content.** Raw session data belongs to Hermes `state.db`.
|
|
20
|
+
5. **Prefer upgrade resilience over cleverness.** A small shim that can be reinstalled after updates is better than a broad core patch.
|
|
21
|
+
|
|
22
|
+
## Tests
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
PYTHONPATH=src python -m pytest tests -q -o 'addopts='
|
|
26
|
+
python -m build
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Commit style
|
|
30
|
+
|
|
31
|
+
Use short conventional-ish messages:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
feat: add recovery pointer listing
|
|
35
|
+
fix: keep audit failures non-blocking
|
|
36
|
+
docs: clarify Hermes integration
|
|
37
|
+
```
|
|
@@ -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,163 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hermes-context-tuner
|
|
3
|
+
Version: 0.2.0b1
|
|
4
|
+
Summary: Audit trail and token-budget planning for LLM context compression. See what your agent summarized away and where to find it.
|
|
5
|
+
Project-URL: Homepage, https://github.com/tier4research/hermes-context-tuner
|
|
6
|
+
Project-URL: Documentation, https://github.com/tier4research/hermes-context-tuner#readme
|
|
7
|
+
Project-URL: Source, https://github.com/tier4research/hermes-context-tuner
|
|
8
|
+
Project-URL: Changelog, https://github.com/tier4research/hermes-context-tuner/blob/main/RELEASE_NOTES.md
|
|
9
|
+
Project-URL: Issues, https://github.com/tier4research/hermes-context-tuner/issues
|
|
10
|
+
Author-email: Tier 4 Research <mjohnson@novacoresystems.com>
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: agent-tools,ai-agents,audit-log,context-compression,context-management,context-window,hermes-agent,llm,observability,python,sqlite,token-budget
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# Hermes Context Tuner
|
|
28
|
+
|
|
29
|
+
[](https://github.com/tier4research/hermes-context-tuner/actions/workflows/tests.yml)
|
|
30
|
+
[](https://www.python.org/downloads/)
|
|
31
|
+
[](LICENSE)
|
|
32
|
+
[](RELEASE_NOTES.md)
|
|
33
|
+
|
|
34
|
+
**Know what your agent's compressor threw away.**
|
|
35
|
+
|
|
36
|
+
[Hermes Agent](https://hermes-agent.nousresearch.com) is an open-source agent framework. Like every long-running agent, it compresses session history when context gets tight — and like every compressor, it sometimes summarizes away the wrong thing. A key instruction, a project spec, a user preference. Then the agent starts answering confidently wrong, and you have no record of what was dropped.
|
|
37
|
+
|
|
38
|
+
Context Tuner doesn't replace that compressor. It wraps it and writes down what it did: which messages were kept raw, which were summarized, which were flagged as oversized tool output, and which session each compressed segment came from. Then it exposes that history to you *and to the agent itself*, so the agent can check its own context hygiene mid-run.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install hermes-context-tuner
|
|
42
|
+
hermes-context-tuner install-hermes --set-config
|
|
43
|
+
hermes gateway restart
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then, inside any session:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
/context-tuner
|
|
50
|
+
|
|
51
|
+
Hermes Context Tuner recent compression events:
|
|
52
|
+
- #1 messages 120 -> 24; ~182000 tokens; externalize_hint=8, keep_raw=12, summarize=100
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## What "recovery" means here — and what it doesn't
|
|
58
|
+
|
|
59
|
+
Context Tuner's sidecar stores metadata and pointers, not message text. For each compression event it records the counts, the token estimates, the per-message decision, and the source session ID.
|
|
60
|
+
|
|
61
|
+
So it can tell you that messages 40–90 were summarized in session `abc123`, and it can point you at that session. It does **not** restore the original text into your context automatically, and it is **not** a backup of your conversation. If you need the raw messages, you go read the session log — Context Tuner tells you which one and which range.
|
|
62
|
+
|
|
63
|
+
That's a narrower promise than "recoverable memory," and it's the one the tool actually keeps. The audit trail is the product; the pointers are a convenience on top of it.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## What it adds
|
|
68
|
+
|
|
69
|
+
**A budget plan you can inspect before compression happens.** Protect the first N messages, protect the last M tokens, mark large tool outputs for externalization, flag the middle for summarization. The plan is advisory — it shows what would happen before it does.
|
|
70
|
+
|
|
71
|
+
**An audit trail.** Every compression event lands in a SQLite sidecar with per-message decisions and reasons. Writes are best-effort: if the audit DB fails, compression still succeeds. Observability never blocks the agent.
|
|
72
|
+
|
|
73
|
+
**Something the agent can operate itself.** The `context_tuner_status` tool and the `/context-tuner` command let the agent inspect its own compression history. The bundled `optimize-context` skill gives it a procedure: audit → compress targeted → verify → hand off. No external dashboard.
|
|
74
|
+
|
|
75
|
+
**No monkey-patching.** Context Tuner attaches through Hermes' official `ContextEngine` interface and introspects the live compressor's constructor at runtime, passing only the kwargs it supports. A Hermes upgrade that changes that signature doesn't break you; one that removes the shim needs a single reinstall command.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Upgrade resilience
|
|
80
|
+
|
|
81
|
+
| Risk | Mitigation |
|
|
82
|
+
|------|------------|
|
|
83
|
+
| Hermes update changes compressor constructor | Introspects live signature, passes only supported kwargs |
|
|
84
|
+
| Hermes update changes compression internals | Delegates through public `compress()` contract |
|
|
85
|
+
| Hermes update removes shim | Rerun `hermes-context-tuner install-hermes --set-config` |
|
|
86
|
+
| Audit DB failure | Compression succeeds; audit is best-effort |
|
|
87
|
+
| ContextEngine API breaks | Failure at import/startup — explicit, not silent |
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## How it works
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
┌─────────────────────────────────────────────────────┐
|
|
95
|
+
│ Context Tuner │
|
|
96
|
+
│ ┌──────────────┐ ┌──────────────┐ ┌───────────┐ │
|
|
97
|
+
│ │ Budget Plan │ │ Compression │ │ Recovery │ │
|
|
98
|
+
│ │ (advisory) │──▶│ (delegated │──▶│ Store │ │
|
|
99
|
+
│ │ │ │ to Hermes) │ │ (audit) │ │
|
|
100
|
+
│ └──────────────┘ └──────────────┘ └───────────┘ │
|
|
101
|
+
│ │ │
|
|
102
|
+
│ ▼ │
|
|
103
|
+
│ ┌──────────────┐ │
|
|
104
|
+
│ │ Status Tool │ │
|
|
105
|
+
│ │ /command │ │
|
|
106
|
+
│ └──────────────┘ │
|
|
107
|
+
└─────────────────────────────────────────────────────┘
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
1. Build an advisory `BudgetPlan` — protected head + tail, summarize middle, externalize large tool outputs
|
|
111
|
+
2. Delegate actual compression to Hermes' built-in `ContextCompressor`
|
|
112
|
+
3. Record decisions in the recovery sidecar (best-effort, never blocks compression)
|
|
113
|
+
4. Expose status via `/context-tuner` command and `context_tuner_status` tool
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Developer use
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from hermes_context_tuner.engine import ContextTunerEngine
|
|
121
|
+
|
|
122
|
+
engine = ContextTunerEngine()
|
|
123
|
+
engine.on_session_start(session_id="example")
|
|
124
|
+
|
|
125
|
+
if engine.should_compress(prompt_tokens):
|
|
126
|
+
messages = engine.compress(messages, current_tokens=prompt_tokens)
|
|
127
|
+
|
|
128
|
+
print(engine.get_status())
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Status
|
|
134
|
+
|
|
135
|
+
**Beta** (v0.2.0-beta.1). Budget planning, the audit trail, status commands, and the Hermes integration are working and tested. Recovery is currently pointer-level only. Tested against Hermes v0.4.x — a CI matrix across versions is planned, so compatibility with other releases is unverified. 7 commits, 0 external stars.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## FAQ
|
|
140
|
+
|
|
141
|
+
### What is Hermes Context Tuner?
|
|
142
|
+
Hermes Context Tuner is a Python library that wraps an agent's context compressor and records what it did: which messages were kept raw, which were summarized, and which session each compressed segment came from. It provides an audit trail, a token-budget planner, and a status tool the agent can call itself.
|
|
143
|
+
|
|
144
|
+
### Does Context Tuner replace the built-in compressor?
|
|
145
|
+
No. It delegates compression to the agent's native `ContextCompressor`. What it adds is observability: a budget plan you inspect beforehand, an audit trail afterward, and recovery pointers to the original session logs.
|
|
146
|
+
|
|
147
|
+
### Can Context Tuner recover compressed messages?
|
|
148
|
+
It provides pointers — session ID and message range — not the raw text. If you need the original messages, you read the session log that Context Tuner points to.
|
|
149
|
+
|
|
150
|
+
### Does it break when Hermes updates?
|
|
151
|
+
This is explicitly designed not to. Context Tuner introspects the live compressor's constructor at runtime and passes only the kwargs it supports. If a Hermes update changes the interface, the tool fails at import/startup rather than silently corrupting the session.
|
|
152
|
+
|
|
153
|
+
### Does it work with agents other than Hermes?
|
|
154
|
+
Not currently. The integration is through Hermes' `ContextEngine` interface. A generic `ContextTunerEngine` core is feasible — the audit trail, budget planner, and recovery store are agent-agnostic — but the adapter layer is Hermes-specific today.
|
|
155
|
+
|
|
156
|
+
### What's the relationship with Memorant?
|
|
157
|
+
[Memorant](https://github.com/tier4research/memorant) is a separate project for *long-term* agent memory: claims with provenance, trust tiers, and atomic corrections in a single SQLite file. Context Tuner handles *short-term* working context compression. [Expectation Ledger](https://github.com/tier4research/expectation-ledger) is a circuit breaker for agent control loops — predict, compare, and self-block on divergence. All three are designed to complement each other — see the [Memorant suite workflow](https://github.com/tier4research/memorant#suite-workflow).
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
Apache License 2.0.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Hermes Context Tuner
|
|
2
|
+
|
|
3
|
+
[](https://github.com/tier4research/hermes-context-tuner/actions/workflows/tests.yml)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](RELEASE_NOTES.md)
|
|
7
|
+
|
|
8
|
+
**Know what your agent's compressor threw away.**
|
|
9
|
+
|
|
10
|
+
[Hermes Agent](https://hermes-agent.nousresearch.com) is an open-source agent framework. Like every long-running agent, it compresses session history when context gets tight — and like every compressor, it sometimes summarizes away the wrong thing. A key instruction, a project spec, a user preference. Then the agent starts answering confidently wrong, and you have no record of what was dropped.
|
|
11
|
+
|
|
12
|
+
Context Tuner doesn't replace that compressor. It wraps it and writes down what it did: which messages were kept raw, which were summarized, which were flagged as oversized tool output, and which session each compressed segment came from. Then it exposes that history to you *and to the agent itself*, so the agent can check its own context hygiene mid-run.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install hermes-context-tuner
|
|
16
|
+
hermes-context-tuner install-hermes --set-config
|
|
17
|
+
hermes gateway restart
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then, inside any session:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
/context-tuner
|
|
24
|
+
|
|
25
|
+
Hermes Context Tuner recent compression events:
|
|
26
|
+
- #1 messages 120 -> 24; ~182000 tokens; externalize_hint=8, keep_raw=12, summarize=100
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## What "recovery" means here — and what it doesn't
|
|
32
|
+
|
|
33
|
+
Context Tuner's sidecar stores metadata and pointers, not message text. For each compression event it records the counts, the token estimates, the per-message decision, and the source session ID.
|
|
34
|
+
|
|
35
|
+
So it can tell you that messages 40–90 were summarized in session `abc123`, and it can point you at that session. It does **not** restore the original text into your context automatically, and it is **not** a backup of your conversation. If you need the raw messages, you go read the session log — Context Tuner tells you which one and which range.
|
|
36
|
+
|
|
37
|
+
That's a narrower promise than "recoverable memory," and it's the one the tool actually keeps. The audit trail is the product; the pointers are a convenience on top of it.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## What it adds
|
|
42
|
+
|
|
43
|
+
**A budget plan you can inspect before compression happens.** Protect the first N messages, protect the last M tokens, mark large tool outputs for externalization, flag the middle for summarization. The plan is advisory — it shows what would happen before it does.
|
|
44
|
+
|
|
45
|
+
**An audit trail.** Every compression event lands in a SQLite sidecar with per-message decisions and reasons. Writes are best-effort: if the audit DB fails, compression still succeeds. Observability never blocks the agent.
|
|
46
|
+
|
|
47
|
+
**Something the agent can operate itself.** The `context_tuner_status` tool and the `/context-tuner` command let the agent inspect its own compression history. The bundled `optimize-context` skill gives it a procedure: audit → compress targeted → verify → hand off. No external dashboard.
|
|
48
|
+
|
|
49
|
+
**No monkey-patching.** Context Tuner attaches through Hermes' official `ContextEngine` interface and introspects the live compressor's constructor at runtime, passing only the kwargs it supports. A Hermes upgrade that changes that signature doesn't break you; one that removes the shim needs a single reinstall command.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Upgrade resilience
|
|
54
|
+
|
|
55
|
+
| Risk | Mitigation |
|
|
56
|
+
|------|------------|
|
|
57
|
+
| Hermes update changes compressor constructor | Introspects live signature, passes only supported kwargs |
|
|
58
|
+
| Hermes update changes compression internals | Delegates through public `compress()` contract |
|
|
59
|
+
| Hermes update removes shim | Rerun `hermes-context-tuner install-hermes --set-config` |
|
|
60
|
+
| Audit DB failure | Compression succeeds; audit is best-effort |
|
|
61
|
+
| ContextEngine API breaks | Failure at import/startup — explicit, not silent |
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## How it works
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
┌─────────────────────────────────────────────────────┐
|
|
69
|
+
│ Context Tuner │
|
|
70
|
+
│ ┌──────────────┐ ┌──────────────┐ ┌───────────┐ │
|
|
71
|
+
│ │ Budget Plan │ │ Compression │ │ Recovery │ │
|
|
72
|
+
│ │ (advisory) │──▶│ (delegated │──▶│ Store │ │
|
|
73
|
+
│ │ │ │ to Hermes) │ │ (audit) │ │
|
|
74
|
+
│ └──────────────┘ └──────────────┘ └───────────┘ │
|
|
75
|
+
│ │ │
|
|
76
|
+
│ ▼ │
|
|
77
|
+
│ ┌──────────────┐ │
|
|
78
|
+
│ │ Status Tool │ │
|
|
79
|
+
│ │ /command │ │
|
|
80
|
+
│ └──────────────┘ │
|
|
81
|
+
└─────────────────────────────────────────────────────┘
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
1. Build an advisory `BudgetPlan` — protected head + tail, summarize middle, externalize large tool outputs
|
|
85
|
+
2. Delegate actual compression to Hermes' built-in `ContextCompressor`
|
|
86
|
+
3. Record decisions in the recovery sidecar (best-effort, never blocks compression)
|
|
87
|
+
4. Expose status via `/context-tuner` command and `context_tuner_status` tool
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Developer use
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from hermes_context_tuner.engine import ContextTunerEngine
|
|
95
|
+
|
|
96
|
+
engine = ContextTunerEngine()
|
|
97
|
+
engine.on_session_start(session_id="example")
|
|
98
|
+
|
|
99
|
+
if engine.should_compress(prompt_tokens):
|
|
100
|
+
messages = engine.compress(messages, current_tokens=prompt_tokens)
|
|
101
|
+
|
|
102
|
+
print(engine.get_status())
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Status
|
|
108
|
+
|
|
109
|
+
**Beta** (v0.2.0-beta.1). Budget planning, the audit trail, status commands, and the Hermes integration are working and tested. Recovery is currently pointer-level only. Tested against Hermes v0.4.x — a CI matrix across versions is planned, so compatibility with other releases is unverified. 7 commits, 0 external stars.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## FAQ
|
|
114
|
+
|
|
115
|
+
### What is Hermes Context Tuner?
|
|
116
|
+
Hermes Context Tuner is a Python library that wraps an agent's context compressor and records what it did: which messages were kept raw, which were summarized, and which session each compressed segment came from. It provides an audit trail, a token-budget planner, and a status tool the agent can call itself.
|
|
117
|
+
|
|
118
|
+
### Does Context Tuner replace the built-in compressor?
|
|
119
|
+
No. It delegates compression to the agent's native `ContextCompressor`. What it adds is observability: a budget plan you inspect beforehand, an audit trail afterward, and recovery pointers to the original session logs.
|
|
120
|
+
|
|
121
|
+
### Can Context Tuner recover compressed messages?
|
|
122
|
+
It provides pointers — session ID and message range — not the raw text. If you need the original messages, you read the session log that Context Tuner points to.
|
|
123
|
+
|
|
124
|
+
### Does it break when Hermes updates?
|
|
125
|
+
This is explicitly designed not to. Context Tuner introspects the live compressor's constructor at runtime and passes only the kwargs it supports. If a Hermes update changes the interface, the tool fails at import/startup rather than silently corrupting the session.
|
|
126
|
+
|
|
127
|
+
### Does it work with agents other than Hermes?
|
|
128
|
+
Not currently. The integration is through Hermes' `ContextEngine` interface. A generic `ContextTunerEngine` core is feasible — the audit trail, budget planner, and recovery store are agent-agnostic — but the adapter layer is Hermes-specific today.
|
|
129
|
+
|
|
130
|
+
### What's the relationship with Memorant?
|
|
131
|
+
[Memorant](https://github.com/tier4research/memorant) is a separate project for *long-term* agent memory: claims with provenance, trust tiers, and atomic corrections in a single SQLite file. Context Tuner handles *short-term* working context compression. [Expectation Ledger](https://github.com/tier4research/expectation-ledger) is a circuit breaker for agent control loops — predict, compare, and self-block on divergence. All three are designed to complement each other — see the [Memorant suite workflow](https://github.com/tier4research/memorant#suite-workflow).
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
Apache License 2.0.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# v0.2.0-beta.1
|
|
2
|
+
|
|
3
|
+
Context compression audit, recovery pointers, and agent-operable context hygiene — stable beta.
|
|
4
|
+
|
|
5
|
+
## What's new since alpha
|
|
6
|
+
|
|
7
|
+
- **Sales-forward README.** Rewritten to lead with the problem (invisible compression, no recovery path, blind token pressure) and highlight what makes it different: budget-aware packing plans, compression audit trail, agent-operable commands, and upgrade resilience.
|
|
8
|
+
- **Stability improvements.** Recovery store hardened against SQLite lock contention from concurrent cron sessions. Context engine tool schema aligned with Hermes' `agent_init` contract (no double-wrapped function schemas).
|
|
9
|
+
- **Production data available.** 78 real compression events recorded across daily use, 10,565 recovery pointers — decision distribution: `keep_raw=6789`, `summarize=3592`, `externalize_hint=184`.
|
|
10
|
+
|
|
11
|
+
## Known limitations
|
|
12
|
+
|
|
13
|
+
- No CI matrix against multiple Hermes versions yet — currently tested against Hermes main.
|
|
14
|
+
- Externalization hints for large tool outputs are advisory only; actual pruning depends on the Hermes built-in compressor.
|
|
15
|
+
- Recovery pointer store is a sidecar SQLite file, not yet integrated with Hermes' session DB.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# v0.1.0-alpha.1
|
|
20
|
+
|
|
21
|
+
Initial public alpha of Hermes Context Tuner.
|
|
22
|
+
|
|
23
|
+
## What it is
|
|
24
|
+
|
|
25
|
+
Hermes Context Tuner is an upgrade-resilient wrapper around Hermes Agent's built-in context compressor. It keeps standard Hermes compression, but adds the operational pieces agents need during long sessions:
|
|
26
|
+
|
|
27
|
+
- budget-aware context pack plans
|
|
28
|
+
- compression/recovery audit metadata
|
|
29
|
+
- `context_tuner_status` context-engine tool
|
|
30
|
+
- `/context-tuner` command
|
|
31
|
+
- `optimize-context` skill example
|
|
32
|
+
- reinstallable Hermes context-engine shim
|
|
33
|
+
|
|
34
|
+
## Included
|
|
35
|
+
|
|
36
|
+
- `hermes_context_tuner.budget` advisory budget-plan library
|
|
37
|
+
- `RecoveryPointerStore` SQLite sidecar for compression audit/recovery metadata
|
|
38
|
+
- `ContextTunerEngine`, an official Hermes `ContextEngine` wrapper that delegates to the live built-in compressor
|
|
39
|
+
- `hermes-context-tuner install-hermes --set-config` installer for the Hermes context-engine shim
|
|
40
|
+
- `examples/skills/optimize-context/SKILL.md`
|
|
41
|
+
- integration and architecture docs
|
|
42
|
+
|
|
43
|
+
## Upgrade posture
|
|
44
|
+
|
|
45
|
+
The package does not patch Hermes core or monkey-patch private methods. It uses the official context-engine seam and can be reinstalled after Hermes updates by rerunning:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
hermes-context-tuner install-hermes --set-config
|
|
49
|
+
```
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
Hermes Context Tuner is a local Hermes Agent context-engine wrapper. It does not make network calls and does not execute tools by itself.
|
|
4
|
+
|
|
5
|
+
## Data handling
|
|
6
|
+
|
|
7
|
+
Context Tuner writes audit/recovery metadata to:
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
~/.hermes/context_tuner/recovery.sqlite
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The sidecar database records metadata such as:
|
|
14
|
+
|
|
15
|
+
- session IDs
|
|
16
|
+
- message counts
|
|
17
|
+
- rough token estimates
|
|
18
|
+
- budget-plan decisions
|
|
19
|
+
|
|
20
|
+
It should not store raw message contents, API keys, tokens, passwords, or tool outputs.
|
|
21
|
+
|
|
22
|
+
## Reporting issues
|
|
23
|
+
|
|
24
|
+
For public issues, avoid posting:
|
|
25
|
+
|
|
26
|
+
- API keys
|
|
27
|
+
- auth tokens
|
|
28
|
+
- private `config.yaml` or `.env` content
|
|
29
|
+
- raw transcripts containing sensitive data
|
|
30
|
+
|
|
31
|
+
Open a GitHub issue with a sanitized reproduction, Hermes version, Context Tuner version, and the relevant traceback.
|
|
32
|
+
|
|
33
|
+
## Threat model
|
|
34
|
+
|
|
35
|
+
This package is designed to be low-risk:
|
|
36
|
+
|
|
37
|
+
- no network calls
|
|
38
|
+
- no shell execution except the explicit installer command
|
|
39
|
+
- no raw transcript storage
|
|
40
|
+
- audit writes are best-effort and non-blocking
|
|
41
|
+
|
|
42
|
+
The main security risk is accidental leakage through bug reports or logs. Sanitize before sharing.
|