The loop appends step/start before system/message and the entered user messages. Capturing nodes at step/start therefore omits inputs already included in the provider's successful usage, then adds those inputs back as a positive surface delta. Prompt replacement can also incorrectly add or subtract the difference from the prior prompt on a completed call. Snapshot the current priced surface immediately before assistant/message commits. Keep provider output separate from the durable assistant node so listener rewrites retain their signed delta. The invariant is zero delta immediately after an unchanged successful output: provider usage already includes every admitted prompt input. Later appends/replacements still produce signed deltas, and low or absent usage keeps heuristic fallback. Delete stepStart.nodes rather than adding prompt-specific corrections or another request snapshot: the existing transactional surface fold already contains the successful request inputs, including replacements made during same-step retry recovery. Keep turn/step state and all overlap, mismatch, and late-assistant lifecycle validation. Retry attempts are log-only and request middleware changes configuration; injected messages remain queued until admission. No loop, event format, projection, or retry policy changes. Exercise the real loop with reported usage and initial, growing, shrinking, and empty prompts; same-step failed attempt plus retry prompt replacement; request middleware; eager observation and fresh seeded replay. The two regressions fail before the fix with spurious deltas of +48 and +18 tokens. Retain existing durable-output rewrite, route repricing, missing/low usage, transactional failure, and lifecycle tests. Update README EN/ZH and the existing system-prompt surface-node Agent Note, including pairing records. Validation (dedicated worktree, no full unit suite): - pnpm exec vitest run packages/llm/token-meter/tests packages/compaction/compaction-basic/tests/compaction-loop-repro.spec.ts --coverage --coverage.include='packages/llm/token-meter/src/index.ts' 118 passed; exact changed runtime file 100% statements/branches/functions/lines. - pnpm exec vitest run packages/core/agent-loop/tests/request-reconstruction.spec.ts packages/compaction/compaction-basic/tests/compaction-basic.spec.ts packages/compaction/compaction-basic/tests/loader-composition.spec.ts 118 passed, including retry reconstruction and real Loader composition. - pnpm run doc-sync: 33 gates passed. - pnpm run test:docs: 15 gates passed. - pnpm run lint: passed, 0 warnings/errors. - git diff --cached --check: passed. Baseline normalize.ts comment conflict marker is intentionally untouched.
description, kind
| description | kind |
|---|---|
| The LLM capability group: a provider-neutral model-call service, the DeepSeek and pi-ai provider adapters, request-retry execution, and replay-aware token measurement. | package-group |
llm/ — LLM capability family
English | 中文
Summary
The llm group provides the harness's model-call capability: one provider-neutral service through which any composition streams requests to a model provider, plus adapters, provider-specific request metadata, retry execution, and measurement. The core llm package defines the message, content-block, and stream-chunk vocabulary every plugin and the session log use; provider adapters translate a provider's wire format into that vocabulary; DeepSeek request-extension plugins contribute lifecycle-owned metadata outside model input; llm-retry re-runs failed requests at durable agent-step boundaries; and token-meter measures request and context pressure from the durable log. This page maps the group; each package README owns its per-package contract.
Table of Contents
Packages
| Package | Role | ctx key |
|---|---|---|
llm/ |
Streams one model call through a registered provider adapter and shares the harness message, block, and chunk vocabulary | ctx.llm |
llm-deepseek/ |
Serves the deepseek-official route with direct DeepSeek chat-completions, thinking, and image input |
registers on ctx.llm |
llm-pi-ai/ |
Serves configured provider routes through pi-ai catalogs and wire protocols, including hand-declared gateways | registers on ctx.llm |
deepseek-llm-api-extensions/ |
Registers lifecycle-owned top-level fields on official DeepSeek requests | ctx.deepseekLlmApiExtensions |
plugin-package-inventory-deepseek/ |
Contributes the active Loader package inventory to official DeepSeek requests | contributes dsh_plugin_packages |
llm-retry/ |
Retries failed model requests under each provider's policy at durable agent-step boundaries | listens to agent/request-error |
token-meter/ |
Measures request and context pressure from the durable session log with a fixed heuristic | ctx.tokenMeter |
Related documentation
- LLM streaming subsystem — the message and block types, the assembled model request, the
StreamChunkprotocol, and the adapter contract. - Token meter subsystem — the measurement semantics behind
ctx.tokenMeter. - Twin LLM adapters — why the DeepSeek route ships two structurally different adapters.
- Routed model context — how the loop routes model requests and compacts context.
Dev Note
None.