Repository navigation
feat: add /compact endpoint and llm-d compaction service example - #8
Merged
Merged
Conversation
Turn context-guru into a standalone compaction service for llm-d-router's request-inline-compaction step: request body in, smaller body of the same shape out, no upstream forward, fail-open. - proxy: POST /compact runs the pipeline and returns the rewritten body without forwarding; OpenAI default, ?provider=anthropic; per-request overrides via ?preset= and x-context-guru-pipeline. - store: configurable enable/disable flag (store.enabled, --store/STORE) and a Nop store; add Store.Persists() so a full marker_mode degrades to an irreversible drop when the store cannot persist, instead of leaving an unresolvable marker (applied in mark, summarize, cmdfilter). - reformat: new deterministic toon component (uniform JSON object-arrays to tabular TOON) with tests. - offload: config-driven model endpoint and credentials in the model block (provider, base_url, api_key, model, auth), shared by extract and summarize; empty api_key falls back to env keys including bearer tokens. - examples/llm-d-service: three configs, build.sh, a dependency-free Go client, a README, and a captured before/after sample run. Assisted-By: Claude (Opus 4.8) Signed-off-by: Osher-Elhadad <[email protected]>
2 tasks done
boazdavid
added a commit
that referenced
this pull request
Nov 3, 2026
The keep-alive and cachesplit columns still came from the legacy rules, and the head-TTL legs had no figure at all. - The proxy passes each ping's usage (PingFacts.Apply), and accountant derives the extent the ping read (accountant PR #8). The live path now gets a rescue. - siblingStore gives EntryFacts.SharedWarm: the prefix another thread of the session kept warm inside the TTL, up to that thread's last breakpoint in the shared prefix. A rescue no longer credits it (R54). - The override fills keepalive_saved_usd and cachesplit_saved_usd from the library's rescue and split effects, and puts the head-TTL legs on the headttl row. TestThePingRescueIsCreditedFromTheUsage fails without the usage-derived extent. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes context-guru usable as a standalone compaction service for
llm-d-router'srequest-inline-compactionstep (PR #1). That step POSTs the raw inferencerequest body to a compaction server and, on
200+ non-empty JSON, swaps thatbody in. Contract: request body in → smaller body of the same shape out.
The proxy was forward-only (routes proxy to OpenAI/Anthropic and return a
completion), so this adds a compact-and-return endpoint plus the pieces needed
to run it cleanly without the store.
Changes
POST /compact(proxy/): runs the pipeline over the requestmessagesand returns the rewritten body without forwarding upstream. OpenAI by default,
?provider=anthropic; per-request overrides via?preset=andx-context-guru-pipeline. Fail-open (bad input → original body,200).store.enabledin YAML, plus--store/STORE. Adds aNopstore andStore.Persists(), so afullmarker_modeautomatically degrades to an irreversible drop when the store can't persist —
instead of leaving an unresolvable
<<cg:HASH>>marker (applied inmark/summarize/cmdfilter).tooncomponent (components/reformat/): deterministic re-encoding ofuniform JSON object-arrays into tabular TOON. Lossless repack; tests included.
model:block onextract/summarizenowtakes
provider/base_url/api_key/model/auth; emptyapi_keyfallsback to env keys (incl.
ANTHROPIC_AUTH_TOKENfor bearer gateways).examples/llm-d-service/: three configs (toon, extract-code, summarize;store off,
marker_mode: off),build.sh, a dependency-free Go clientmirroring the router's call, a self-contained README, and a captured
before/after sample run.
Testing
CGO_ENABLED=1 go build ./...,go vet ./...,go test ./...— all pass;gofmt clean. New tests:
toonencoder + the store-disabled marker degrade.Deterministic
toonreduced a sample request ~46%. The two LLM configs ran areal
claude-haiku-4-5call through a bearer gateway (extractfiltered tothe relevant lines deletion-only;
summarizecollapsed the transcript ~81%),all with the store disabled and no markers in the output.
Note
The commit skips the repo's dnephin
go-vetpre-commit hook (SKIP=go-vet): itpasses individual filenames to
go vet, which errors on a multi-package commit("no Go files in ...").
go vet ./...is clean; all other hooks (gofmt,go-mod-tidy, gitlint, DCO) ran.