Skip to content

feat: absorb tool for instant tool-result compression (issue #14) - #213

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-08-23_absorb-tool
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-08-23_absorb-tool

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Aug 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #605 — tracking issue for this PR.

What

Adapts the proxy to acp-kernel 0.0.45's new absorb pipeline (kernel PR #139, merged) — closes #14 on the companion billion-context-pi tracker direction: 小上下文场景下, 工具调用后模型立即复述关键结果, 原始工具输出下一轮隐藏.

  • src/absorb.ts (new): absorbEnabled / applyAbsorbConfig (settings → kernel Config.absorb, percent parsing for contextThresholdPct) and executeAbsorb. The wire result carries the model's summary verbatim inside <absorbed-summary> — the absorb tool_use is rewritten to text on the wire, so that text is the only durable record of the original output.
  • Injection: absorb tool + system-prompt section for anthropic / openai / responses (streaming loops included), gated on absorb being enabled in compress settings. Plugin manifest and MCP tool list now advertise absorb (5 tools); plugin tool API executes it under the session lock.

Kernel 0.0.31 → 0.0.45 upgrade fallout (fixed here)

  1. openaiToCore now hoists the leading system/developer prefix out of the fold space. prepareOpenai re-injects systemText (restoring a developer head role) — without this the host system prompt is silently dropped from every rebuilt request.
  2. Kernel KEEP_LAST_ORPHANED=2 (issue release v0.1.2 #9 fix) keeps the newest two orphaned compress calls visible. In plugin mode the wire echo of an executed compress carries a host id that never matches the block's plugin_* call id → permanent orphan → stays visible. hidePluginEchoCompressCalls drops the consumed tail pair before the turn.
  3. Pinned acp-kernel to exact 0.0.45-pr.160.14 (the npm preview of kernel release PR refactor: adopt acp-kernel/wire — codecs move to the kernel #160). Follow-up commit flips this to 0.0.45 once the kernel release lands on npm — merge this PR after that.

Tests

518/518 pass (node --import tsx --test), tsc --noEmit --project tsconfig.build.json clean, tsup build clean:

  • roundtrip tests adapted to the hoist contract (systemText + injectOpenaiSystem)
  • manifest / MCP tool lists now expect 5 tools
  • plugin fold test passes again (echo pair hidden, range folded, summary retrievable via search_context)
  • 6 new unit tests for absorbEnabled / applyAbsorbConfig / executeAbsorb (disabled fast-fail, missing-summary guidance, success records + hides + verbatim summary, idempotency, unknown ref)

Merge is human-only per AGENTS.md.

Adapts the proxy to acp-kernel 0.0.45's absorb pipeline:

- src/absorb.ts: absorb settings resolution (absorbEnabled,
  applyAbsorbConfig with percent parsing) and executeAbsorb — the wire
  result text carries the model's summary verbatim inside
  <absorbed-summary> (the absorb tool_use is rewritten to text, so this
  is the only durable record).
- Tool injection for all three protocols (anthropic/openai/responses,
  streaming loops included), plugin manifest + MCP tool list now
  advertise absorb; plugin tool API can execute it.
- Kernel 0.0.31 -> 0.0.45-pr.160.14 (exact pin; flips to 0.0.45 when
  kernel release PR #160 merges):
  - openaiToCore now hoists the leading system/developer prefix out of
    the fold space: prepareOpenai re-injects systemText (and restores a
    developer head role) or the host system prompt is silently lost.
  - KEEP_LAST_ORPHANED=2 changed hide-consumed semantics: plugin-mode
    wire echoes of executed compress calls are orphans that stay
    visible; hidePluginEchoCompressCalls drops the consumed tail pair.
- Tests: roundtrip hoist contract, manifest/MCP 5-tool lists, 6 new
  absorb unit tests. 518/518 pass.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Review vs master 3cd85b6 (kernel 0.0.56): ❌ superseded in approach — do not merge; use as design reference (#605).

Two blockers:

  1. Kernel pin is a PR-preview tag: "acp-kernel": "0.0.45-pr.160.14" — a pr-160 dist-tag artifact, not a stable release. Not installable in CI reproducibly.
  2. Kernel now ships the absorb API natively — verified exports in 0.0.56: ABSORB_TOOL, ABSORB_TOOL_OPENAI, ABSORB_TOOL_NAME, ABSORB_TOOL_DESCRIPTION, ABSORB_PROMPT_MARKER, DEFAULT_ABSORB_CONFIG, appendAbsorbPrompts, applyAbsorb, buildAbsorbPrompt, buildAbsorbSystemPrompt, parseAbsorbInput, hideAbsorbedMessages, isAbsorbCandidate, resolveAbsorbConfig. This PR's host-side reimplementation (17 files, +344) predates that and would fork the logic.

Rework direction (#605): wire the kernel API the same way search_context was wired (kernel-owned semantics, host = thin injection + execution + hide). Concretely: inject ABSORB_TOOL(_OPENAI) alongside the compress tools, execute applyAbsorb server-side, call hideAbsorbedMessages in the wire rebuild, honor resolveAbsorbConfig/DEFAULT_ABSORB_CONFIG. The PR's tests (roundtrip coverage) remain a useful spec for behavior.

(tracking: #605)

@ranxianglei

Copy link
Copy Markdown
Owner Author

Superseded by PR #615 (full kernel-absorb wiring, tracked in #605/#616).

PR #615 完整实现了本 PR 的意图, 且基于 kernel 0.0.56 的官方 absorb API (ABSORB_TOOL/applyAbsorb/parseAbsorbInput/hideAbsorbedMessages/appendAbsorbPrompts/DEFAULT_ABSORB_CONFIG), 而不是 host 侧重造:

关闭本 PR, 保留其原始设计价值作为 #605 spec 的参考。感谢提交!

@ranxianglei ranxianglei closed this Sep 7, 2026
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.

wire the kernel absorb API: instant tool-result compression

1 participant