Skip to content

feat(kagent): compact long homelab-agent chats on qwen - #2240

Merged
myoung34 merged 1 commit into
mainfrom
myoung34/kagent-go-compaction
Oct 15, 2026
Merged

myoung34 merged 1 commit into
mainfrom
myoung34/kagent-go-compaction

Conversation

@myoung34

Copy link
Copy Markdown
Owner

Problem

A long homelab-agent chat on qwen grows until it hits the 131k context. Ollama then keeps 4 tokens plus the newest ~65k and silently drops the system prompt and tool definitions. kagent supports spec.declarative.context.compaction, but the 0.10.3 Go runtime ignores it. The controller still writes the settings into the agent config and only reports them as "ignored" in the UnsupportedFeatures condition.

Solution

  • images/kagent-adk: add kagent-pr2791.patch, the agent-code part of kagent#2791, an open backport of #2790 (merged on main). It wires compaction into the Go runtime and bumps google.golang.org/adk/v2 2.1.0 → 2.3.0 (session/compaction) and a2a-go/v2 2.3.1 → 2.5.0.
  • On a2a-go v2.5.0, Update Helm release argo-cd to v6.7.13 #414 applies unmodified, so a2a-go-pr414.patch is now the upstream diff with no backport edit.
  • homelab-agent: context.compaction with tokenThreshold: 70000 and eventRetentionSize: 24. After a turn whose prompt reached 70k tokens, everything but the last 24 events folds into one rolling summary written by qwen (ADK's default prompt).
  • Tag 0.10.3-a2a414-cap-compact. Also corrects the agent's stale "tools eat ~64k" comment: the measured fixed cost is ~31k.

Notes

  • Compaction runs only after a turn ends (ADK runner.go:319), so it can't rescue one long turn. The tool-result cap covers that.
  • Verified locally: amd64 and arm64 -full images build after the trailing-whitespace hook. Inside the build, a2a-go's queue tests (with -race) and the wedge repro pass on v2.5.0, along with kagent's adk/pkg/a2a, agent (including #2791's compaction tests) and runner. kustomize build --enable-helm renders the tag and the compaction block.
  • Not yet exercised end to end. After merge, a long session should log Context compaction enabled at startup and append a compaction summary event once a turn passes 70k.
  • Draft: bigger dependency bump than fix(kagent): stop one stalled chat stream from wedging every agent task #2234. Drop kagent-pr2791.patch once a kagent release includes #2790/#2791.

Backport kagent-dev/kagent#2791 (Go-runtime context compaction) into our
agent runtime build, which moves a2a-go to v2.5.0 where #414 applies
unmodified. homelab-agent folds all but its last 24 events into a rolling
summary after any turn whose prompt reached 70k tokens.
@myoung34
myoung34 marked this pull request as ready for review October 15, 2026 18:04
@myoung34
myoung34 merged commit b4ab00f into main Oct 15, 2026
4 checks passed
@myoung34
myoung34 deleted the myoung34/kagent-go-compaction branch October 15, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant