-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
[Feature]: ContextEngine.assemble should fire per LLM call, not per user prompt #73437
Copy link
Copy link
Closed
Closed
Copy link
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.enhancementNew feature or requestNew feature or requestimpact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.enhancementNew feature or requestNew feature or requestimpact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Type
Fields
Priority
None yet
Summary
ContextEngine.assembleshould fire per LLM call, not per user promptCurrent behavior
User prompt
→ assembleAttemptContextEngine() ← fires ONCE
→ activeSession.prompt() ← agentic loop
LLM call 1 ← ✅ assemble ran before this
→ tool result
→ LLM call 2 ← ❌ no assemble before this
→ tool result
→ LLM call 3 ← ❌ no assemble before this
→ final response
In
attempt.ts:1904,assembleAttemptContextEngine()is called beforeactiveSession.prompt(), which contains the agentic loop. Once the loop starts executing multiple LLM calls,assembleis never invoked again.Why
installContextEngineLoopHookis insufficienttransformContext's call frequency does not guarantee invocation before every LLM call — it fires at specific internal transition points.Related
Problem to solve
ContextEngine.assemble()currently fires once per user prompt (per attempt), not per LLM call within the agentic loop. Context engines — especially those doing context compression — cannot make informed decisions about the message array before subsequent LLM calls in a multi-turn tool loop.Proposed solution
Add a
transform_contexthook that fires before each LLM call within the agentic loop. Two approaches:transform_contexthook type — conservative, doesn't change existingassemblesemanticsassemblefire at each LLM call boundary — simpler but may have backward-compatibility implicationsOption 1 is recommended as the safer path.
Alternatives considered
No response
Impact
Context overflow on long agentic loops, stale context in subsequent LLM calls, inability to implement smart trimming strategies.
Evidence/examples
No response
Additional information
No response