feat: prompt-aware context assembly with BM25-lite relevance scoring#180
Open
GodsBoy wants to merge 2 commits intoMartian-Engineering:mainfrom
Open
feat: prompt-aware context assembly with BM25-lite relevance scoring#180GodsBoy wants to merge 2 commits intoMartian-Engineering:mainfrom
GodsBoy wants to merge 2 commits intoMartian-Engineering:mainfrom
Conversation
When the token budget is exceeded during context assembly, evictable items are now scored by relevance to the current user prompt (BM25-lite TF keyword scoring) rather than dropped in strict chronological order. This means summaries matching the user's active query are preserved over irrelevant but more recent content. - Add `prompt?: string` to AssembleContextInput and LcmContextEngine.assemble() - Add `text: string` to ResolvedItem for pre-extracted scoring content - Implement scoreRelevance() using TF-based keyword overlap (no deps, no LLM) - Fall back to existing chronological eviction when prompt is absent or empty - Add 6 integration tests covering prompt-aware eviction, fallback, and edge cases Refs OpenClaw PR #50848. Zero cost increase, fully backwards compatible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refs OpenClaw PR #50848 (merged 21 Mar 2026). Adds lightweight relevance scoring during eviction so summaries matching the user's prompt are preferred over chronological order. Zero cost (no LLM calls), fully backwards compatible.
What changed
AssembleContextInputgainsprompt?: stringLcmContextEngine.assemble()params gainsprompt?: stringand threads it to the assemblerResolvedItemgainstext: string(pre-extracted plain text for scoring, set during resolution)scoreRelevance()pure function: BM25-lite TF keyword overlap, no external depspromptis set and non-empty, items are scored and filled greedily (highest score first); output is re-sorted by ordinal to preserve chronological order. Empty/absent prompt → existing chronological behavior unchanged.Tests
6 new integration tests in
test/lcm-integration.test.ts:All 213 existing tests pass. The 11 pre-existing failures are unrelated (missing
@sinclair/typebox/@mariozechner/pi-coding-agentpackages).Post-Deploy Monitoring & Validation
No additional operational monitoring required: this is a pure in-process algorithm change with no DB writes, no external calls, and no persistent state. The
promptparameter is optional — all existing callers are unaffected.