openclaw - 💡(How to fix) Fix [Feature]: `ContextEngine.assemble` should fire per LLM call, not per user prompt [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#73437Fetched 2026-04-29 06:19:54
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
0
Timeline (top)
commented ×1labeled ×1

ContextEngine.assemble should fire per LLM call, not per user prompt

Current 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 before activeSession.prompt(), which contains the agentic loop. Once the loop starts executing multiple LLM calls, assemble is never invoked again.

Why installContextEngineLoopHook is insufficient

transformContext's call frequency does not guarantee invocation before every LLM call — it fires at specific internal transition points.

Related

  • PR #57585 (closed)

Root Cause

ContextEngine.assemble should fire per LLM call, not per user prompt

Current 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 before activeSession.prompt(), which contains the agentic loop. Once the loop starts executing multiple LLM calls, assemble is never invoked again.

Why installContextEngineLoopHook is insufficient

transformContext's call frequency does not guarantee invocation before every LLM call — it fires at specific internal transition points.

Related

  • PR #57585 (closed)
RAW_BUFFERClick to expand / collapse

Summary

ContextEngine.assemble should fire per LLM call, not per user prompt

Current 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 before activeSession.prompt(), which contains the agentic loop. Once the loop starts executing multiple LLM calls, assemble is never invoked again.

Why installContextEngineLoopHook is insufficient

transformContext's call frequency does not guarantee invocation before every LLM call — it fires at specific internal transition points.

Related

  • PR #57585 (closed)

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_context hook that fires before each LLM call within the agentic loop. Two approaches:

  1. New transform_context hook type — conservative, doesn't change existing assemble semantics
  2. Make assemble fire at each LLM call boundary — simpler but may have backward-compatibility implications Option 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

extent analysis

TL;DR

Implement a transform_context hook that fires before each LLM call within the agentic loop to ensure ContextEngine.assemble() runs per LLM call, not just per user prompt.

Guidance

  • Identify the agentic loop in activeSession.prompt() and determine the best point to invoke the transform_context hook before each LLM call.
  • Consider the two proposed approaches: adding a new transform_context hook type or making assemble fire at each LLM call boundary, and evaluate their potential impact on existing functionality.
  • Assess the trade-offs between the conservative approach (new hook type) and the simpler approach (modifying assemble invocation), focusing on backward compatibility and potential side effects.
  • Evaluate the feasibility of integrating the proposed solution with the existing installContextEngineLoopHook mechanism.

Example

No code example is provided due to the lack of specific implementation details in the issue.

Notes

The solution's effectiveness depends on correctly identifying the LLM call boundaries within the agentic loop and ensuring the transform_context hook is invoked at the appropriate times. The choice between the two proposed approaches should be based on a thorough analysis of the potential impact on existing functionality and backward compatibility.

Recommendation

Apply the workaround by implementing a transform_context hook, as it is the recommended safer path, allowing for the invocation of ContextEngine.assemble() before each LLM call without altering the existing assemble semantics.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Feature]: `ContextEngine.assemble` should fire per LLM call, not per user prompt [1 comments, 2 participants]