feat: add per-model promptCompression config #36

Merged
sam merged 2 commits from feat/prompt-compression into main 2026-10-19 19:30:02 +00:00
Collaborator

Adds an opt-in promptCompression flag on each model in brainless.json (default false). When enabled, the model's system prompt carries a compacted copy of the honey-for-devs AGENTS.md ruleset (less code, less prose, denser agent-to-agent messages), embedded from internal/harness/honey_compressed.txt via go:embed.

How it works

  • The flag is parsed per model in internal/config/config.go (promptCompression, default false, omitzero).
  • selectorModel.GenerateContent (where the active model is resolved per prompt) appends the compacted text to the request's system instruction when the model's flag is on — the base agentInstruction stays untouched, and the per-model prompt prefix remains cache-stable.
  • Models without the flag keep the current prompt byte-for-byte.

Compacted prompt

A distilled copy of https://github.com/Green-PT/honey-for-devs/blob/main/AGENTS.md (~7.4 KB → ~2.9 KB): the three levers (less code, less prose, denser agent-to-agent messages), intensity modes, the Lever-1 code ladder, the "never cut" safety list, Lever 2 (say less, keep exact), Lever 3 (agent-to-agent compression), Lever 3b (request less input), and loop pacing.

Verification

  • go build ./..., go vet ./..., golangci-lint run (0 issues)
  • go test ./internal/config ./internal/harness — new tests: TestLoadParsesPromptCompression (config round-trip + default false) and TestSelectorModelPromptCompression (instruction appended only for enabled models)

Docs

  • README.md: new promptCompression bullet under model config
  • brainless.json.example: flag shown on the flash model
Adds an opt-in `promptCompression` flag on each model in `brainless.json` (default false). When enabled, the model's system prompt carries a compacted copy of the honey-for-devs AGENTS.md ruleset (less code, less prose, denser agent-to-agent messages), embedded from `internal/harness/honey_compressed.txt` via `go:embed`. ## How it works - The flag is parsed per model in `internal/config/config.go` (`promptCompression`, default false, `omitzero`). - `selectorModel.GenerateContent` (where the active model is resolved per prompt) appends the compacted text to the request's system instruction when the model's flag is on — the base `agentInstruction` stays untouched, and the per-model prompt prefix remains cache-stable. - Models without the flag keep the current prompt byte-for-byte. ## Compacted prompt A distilled copy of https://github.com/Green-PT/honey-for-devs/blob/main/AGENTS.md (~7.4 KB → ~2.9 KB): the three levers (less code, less prose, denser agent-to-agent messages), intensity modes, the Lever-1 code ladder, the "never cut" safety list, Lever 2 (say less, keep exact), Lever 3 (agent-to-agent compression), Lever 3b (request less input), and loop pacing. ## Verification - `go build ./...`, `go vet ./...`, `golangci-lint run` (0 issues) - `go test ./internal/config ./internal/harness` — new tests: `TestLoadParsesPromptCompression` (config round-trip + default false) and `TestSelectorModelPromptCompression` (instruction appended only for enabled models) ## Docs - `README.md`: new `promptCompression` bullet under model config - `brainless.json.example`: flag shown on the flash model
feat: add per-model promptCompression config
All checks were successful
code-review / Agent review (pull_request) Successful in 11s
8b31de09ee
Add an opt-in promptCompression flag on each model in brainless.json
(default false). When enabled, the model's system prompt carries a
compacted copy of the honey-for-devs AGENTS.md ruleset (less code, less
prose, denser agent-to-agent messages), embedded from
internal/harness/honey_compressed.txt.

The text is appended to the request's system instruction inside
selectorModel.GenerateContent, where the active model is resolved, so
the base agentInstruction stays untouched and the per-model prompt
prefix remains cache-stable. Models without the flag keep the current
prompt byte-for-byte.

Adds config parsing, README/example documentation, and tests for both
the config round-trip and the selector's per-model append.
pi-reviewer left a comment

Skill-guided review (code-style, naming, docs, error-handling, safety, concurrency, security, dependency-management, testing, performance, observability, modernize) of head 8b31de0 vs base 99487eb.

Verification run in this session:

  • go build ./... exit 0, go vet ./... exit 0, gofmt -l clean
  • go test ./... all packages ok; go test -race ./internal/config ./internal/harness ok
  • go tool cover -func → appendSystemInstruction 53.8%
  • go doc google.golang.org/genai NewContentFromText / NewPartFromText → signatures match the call sites
  • ADK v2.5.0 source: utils.AppendInstructions (internal/utils/utils.go:138) is unexported, so the local mirror is justified and faithful; base_flow.go:749 constructs a fresh *model.LLMRequest per step and generateContent (base_flow.go:1069) invokes the model exactly once, so the append runs exactly once per call — no double-append, no shared-request race; the instruction processor runs in preprocess before GenerateContent, so the static agentInstruction is always installed and the compressed text lands after it
  • turnclock annotate writes to req.Contents (user role), not SystemInstruction — no interaction with the append, cache-stability claim holds
  • git diff -- go.mod go.sum = 0 lines: no dependency changes; upstream AGENTS.md link resolves and the embedded copy is a faithful distillation

No blocking or important findings. One suggestion (inline on registry.go: appendSystemInstruction's edge branches are untested; a table test pins the ADK mirror against version drift).

Skill-guided review (code-style, naming, docs, error-handling, safety, concurrency, security, dependency-management, testing, performance, observability, modernize) of head 8b31de0 vs base 99487eb. Verification run in this session: - `go build ./...` exit 0, `go vet ./...` exit 0, `gofmt -l` clean - `go test ./...` all packages ok; `go test -race ./internal/config ./internal/harness` ok - `go tool cover -func` → appendSystemInstruction 53.8% - `go doc google.golang.org/genai NewContentFromText / NewPartFromText` → signatures match the call sites - ADK v2.5.0 source: utils.AppendInstructions (internal/utils/utils.go:138) is unexported, so the local mirror is justified and faithful; base_flow.go:749 constructs a fresh *model.LLMRequest per step and generateContent (base_flow.go:1069) invokes the model exactly once, so the append runs exactly once per call — no double-append, no shared-request race; the instruction processor runs in preprocess before GenerateContent, so the static agentInstruction is always installed and the compressed text lands after it - turnclock annotate writes to req.Contents (user role), not SystemInstruction — no interaction with the append, cache-stability claim holds - `git diff -- go.mod go.sum` = 0 lines: no dependency changes; upstream AGENTS.md link resolves and the embedded copy is a faithful distillation No blocking or important findings. One suggestion (inline on registry.go: appendSystemInstruction's edge branches are untested; a table test pins the ADK mirror against version drift).
@ -646,0 +658,4 @@
// appendSystemInstruction appends text to the request's system instruction,
// mirroring ADK's internal AppendInstructions (the selector runs after the
// instruction request processor has installed the static agentInstruction).
func appendSystemInstruction(req *model.LLMRequest, text string) {
Collaborator

🟡 SUGGESTION — appendSystemInstruction is at 53.8% coverage (go tool cover -func on this head): the nil-Config, nil-SystemInstruction, empty-Parts, and empty-last-part branches are untested. TestSelectorModelPromptCompression only exercises the selector path, where ADK always installs the agent instruction first (instruction_processor.go runs in preprocess), so those branches stay dead in production — but this helper is a hand-mirror of ADK's unexported utils.AppendInstructions (internal/utils/utils.go:138, adk v2.5.0), and the mirror has no test pinning its exact behavior. When the ADK version bumps and AppendInstructions changes shape, only a direct table test on the helper catches the drift. Fix: add a small table-driven test calling appendSystemInstruction directly (nil Config, nil SystemInstruction, empty Parts, non-text last part) asserting the resulting Parts layout.

🟡 SUGGESTION — appendSystemInstruction is at 53.8% coverage (`go tool cover -func` on this head): the nil-Config, nil-SystemInstruction, empty-Parts, and empty-last-part branches are untested. TestSelectorModelPromptCompression only exercises the selector path, where ADK always installs the agent instruction first (instruction_processor.go runs in preprocess), so those branches stay dead in production — but this helper is a hand-mirror of ADK's unexported utils.AppendInstructions (internal/utils/utils.go:138, adk v2.5.0), and the mirror has no test pinning its exact behavior. When the ADK version bumps and AppendInstructions changes shape, only a direct table test on the helper catches the drift. Fix: add a small table-driven test calling appendSystemInstruction directly (nil Config, nil SystemInstruction, empty Parts, non-text last part) asserting the resulting Parts layout.
Review finding (PR #36, review 64): the hand-mirror of ADK's unexported
utils.AppendInstructions had untested edge branches. Add a table test
covering nil Config, nil SystemInstruction, non-empty last text part,
empty Parts, and a non-text last part, asserting the exact resulting
Parts layout. appendSystemInstruction coverage 53.8% -> 100%.
Author
Collaborator

Resolved in 3b1d7fb: added TestAppendSystemInstruction, a table test covering every branch of the ADK mirror — nil Config, nil SystemInstruction, non-empty last text part (absorbs the append), empty Parts (new part), and a non-text last part (keeps its place, new text part appended). Asserts the exact resulting Parts layout. appendSystemInstruction coverage went 53.8% → 100%; build/vet/lint/tests all green.

Resolved in 3b1d7fb: added `TestAppendSystemInstruction`, a table test covering every branch of the ADK mirror — nil Config, nil SystemInstruction, non-empty last text part (absorbs the append), empty Parts (new part), and a non-text last part (keeps its place, new text part appended). Asserts the exact resulting Parts layout. `appendSystemInstruction` coverage went 53.8% → 100%; build/vet/lint/tests all green.
sam merged commit 52d5b78192 into main 2026-10-19 19:30:02 +00:00
sam deleted branch feat/prompt-compression 2026-10-19 19:30:02 +00:00
Sign in to join this conversation.
No reviewers
No labels
code-review
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sam/brainless!36
No description provided.