Skip to content

Add RTK request compression#119

Open
dat-lequoc wants to merge 1 commit into
Quorinex:mainfrom
dat-lequoc:rtk-token-saver
Open

Add RTK request compression#119
dat-lequoc wants to merge 1 commit into
Quorinex:mainfrom
dat-lequoc:rtk-token-saver

Conversation

@dat-lequoc

@dat-lequoc dat-lequoc commented Jun 9, 2026

Copy link
Copy Markdown

Summary

  • add a standalone RTK request-compression package for tool-result payloads
  • enable RTK by default for Claude messages, Claude count_tokens, OpenAI chat completions, and OpenAI responses before request validation/translation
  • keep the integration isolated from persisted config/admin UI; optional env overrides are KIRO_GO_RTK, KIRO_GO_RTK_MIN_BYTES, and KIRO_GO_RTK_MAX_BYTES

Verification

  • go test ./rtk -v
  • go test ./proxy -run TestRTKCompressesClaudeToolResultBeforeUpstreamKiroRequest -v
  • go test ./proxy -run 'TestRTKCompresses(ClaudeToolResult|MultiTurnClaudeCodeSession|MultiTurnOpenAIChatSession)BeforeUpstreamKiroRequest' -v -count=1
  • KIRO_GO_RTK_ARTIFACT_DIR=/tmp/kiro-go-rtk-live go test ./proxy -run 'TestRTKCompresses(ClaudeToolResult|MultiTurnClaudeCodeSession|MultiTurnOpenAIChatSession)BeforeUpstreamKiroRequest' -v -count=1
  • go test ./rtk ./proxy -run 'TestRTK|TestTransformJSON' -count=1
  • go test ./... currently fails on upstream-main tests TestClaudeToolResultMixedTextAndImage and TestOpenAIToolResultImageCarriedWhenFollowedByUser; reproduced unchanged in a clean upstream/main worktree at a2e3971

Live Capture

The integration tests capture same-shape upstream Kiro request JSON with RTK disabled and enabled.

Captured cases:

  • single-turn Claude tool result: 4550B to 1049B, 76.9% saved, filter=grep
  • multi-turn Claude-Code-style session: 3 tool-result hits, 10351B to 2397B across compressed tool outputs, 76.8% saved, filters=build-output,grep
  • multi-turn Codex/OpenAI-chat-style session: 3 tool-result hits, 10001B to 2387B across compressed tool outputs, 76.1% saved, filters=build-output,grep

Artifacts written under KIRO_GO_RTK_ARTIFACT_DIR include raw and normalized before/after Kiro request JSON plus current-tool-result and history text extracts for the single-turn, Claude multi-turn, and Codex multi-turn cases.

@dat-lequoc

Copy link
Copy Markdown
Author

RTK request-capture artifacts for commit 6532de8:

https://gist.github.com/dat-lequoc/61bdf0655172318f230ebf1de60dfb3b

Included files:

  • claude-request-before.json
  • kiro-upstream-before.json
  • kiro-upstream-after.json
  • kiro-upstream-before.normalized.json
  • kiro-upstream-after.normalized.json
  • tool-result-before.txt
  • tool-result-after.txt

The normalized Kiro JSON files remove generated agentContinuationId noise so the diff focuses on the RTK payload change. This capture compresses the tool result from 4550B to 1049B, saving 76.9%.

@dat-lequoc

Copy link
Copy Markdown
Author

Expanded RTK request-capture artifacts for commit c1bc512:

https://gist.github.com/dat-lequoc/17c00628be1e583a1183b2481b5626e3

New multi-turn coverage included:

  • Claude-Code-style /v1/messages session with prior search output, prior build/test output, and current active tool result. RTK saved 7954B / 10351B, 76.8%, filters=build-output,grep, hits=3.
  • Codex/OpenAI-chat-style /v1/chat/completions session with prior search output, prior build/test output, and current active tool result. RTK saved 7614B / 10001B, 76.1%, filters=build-output,grep, hits=3.

The normalized Kiro JSON captures keep the active final tool turn structured while showing older history tool results compressed into Kiro history text. The artifact scan found no credential-looking strings.

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