feat(tool-result-compaction): add opt-in large tool result compaction#29454
feat(tool-result-compaction): add opt-in large tool result compaction#29454pinguarmy wants to merge 4 commits into
Conversation
8170741 to
e2134a2
Compare
|
This PR is ready for review now. Final cleanup is complete:
The feature is default-off, string-only, LLM-free, and fail-open. The main known tradeoff is that v1 recovery exposes a local raw_result_path; this is documented in the PR body and docs, with a future reference-ID resolver noted as a possible follow-up. I'm not asking to change the P3 priority; just flagging that the branch is now cleaned up and ready whenever someone has review bandwidth. |
|
Noting related work for reviewer context: I found #28098 and #6339 after preparing this PR. #28098 is closest in motivation: it adds plugin-based, terminal-only tool-result compaction. This PR takes a different path: core agent-side compaction for any string tool result, with disk-backed raw-result recovery, quota cleanup, private permissions, and fail-open behavior. #6339 is also related, but focuses on context-window overflow / dynamic budgeting. This PR focuses on reducing repeated tool-result token pressure in long tool-heavy sessions, even before the context window is near overflow. If maintainers prefer the plugin/hook direction from #28098, I'm happy to adapt this PR or split out reusable pieces. |
Hermes Tool Result Compaction
Opt-in string-tool-result compaction with disk-backed raw storage, quota cleanup, documentation, benchmark/replay scripts, and 51 tests passing.
What this PR does
When
tool_result_compaction.enabled: trueis set in~/.hermes/config.yaml, large string tool results above the configured threshold are:~/.hermes/raw_results/<session_id>/<tool_call_id>_<tool_name>_<timestamp>.jsonDisabled by default. No behavior change without explicit opt-in to
config.yaml.Design
DEFAULT_ENABLED = Falseisinstance(..., str)guard0o700; raw JSON files use0o600maybe_persist_tool_result()and_tool_result_content_for_active_model()Files
agent/tool_result_compaction.pyagent/tool_executor.pymessages.append()scripts/benchmark_tool_result_compaction.pyscripts/replay_tool_result_compaction.pydocs/tool-result-compaction.mddocs/tool-result-compaction-review-checklist.mdexamples/tool-result-compaction.config.yamltests/agent/tests/scripts/Config
Benchmarks
Synthetic (10 results @ 50K chars each)
Replay (2 JSONL objects: 50K + small string)
Both are LLM-free, using the same
chars / 4estimate as the compaction module.Verification
Commits (squashed to 4)
Known tradeoffs
raw_result_pathis a local filesystem path embedded in the compacted JSON for model recovery. Works locally; remote/docker modes would need a reference-ID resolver. (Documented in Limitations.)Status
Ready for review. 4 squashed commits, 51 tests passing, all checks green.