Skip to content

feat(openclaw): add recallInjectionPosition config to preserve prompt cache#710

Merged
nicoloboschi merged 2 commits intomainfrom
feat/openclaw-recall-injection-position
Mar 26, 2026
Merged

feat(openclaw): add recallInjectionPosition config to preserve prompt cache#710
nicoloboschi merged 2 commits intomainfrom
feat/openclaw-recall-injection-position

Conversation

@nicoloboschi
Copy link
Collaborator

Summary

  • Adds recallInjectionPosition config option to control where recalled memories are injected in the prompt
  • Fixes 10x cost increase caused by prompt cache misses when dynamic memory content is prepended to system prompts with large static prefixes (e.g., SOUL.md, MEMORY.md)
  • Options: prepend (default, unchanged behavior), append (preserves prefix cache), user (inject before user message)

Closes #703

Test plan

  • Verify default behavior unchanged (no config = prepend)
  • Test recallInjectionPosition: "append" returns { appendSystemContext }
  • Test recallInjectionPosition: "user" returns { prependContext }
  • Validate prompt cache hit rate improves with append on Anthropic/Google providers

… cache

Add configurable injection position for recalled memories to avoid
breaking prefix-based prompt caching (Anthropic/Google) when agents
have large static system prompts.

Options: 'prepend' (default, current behavior), 'append' (end of
system prompt, preserves cache), 'user' (before user message).

Closes #703
@nicoloboschi nicoloboschi force-pushed the feat/openclaw-recall-injection-position branch from b905af2 to 3e56ed0 Compare March 26, 2026 14:51
Add missing config options to the OpenClaw docs: recallTopK,
recallTypes, recallContextTurns, recallMaxQueryChars,
recallPromptPreamble, recallInjectionPosition, recallRoles,
retainEveryNTurns, retainOverlapTurns, and debug.
@nicoloboschi nicoloboschi merged commit 200bab2 into main Mar 26, 2026
34 of 36 checks passed
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.

[OpenClaw Plugin] Add recallInjectionPosition config to preserve prompt cache

1 participant