Skip to content

fix(memory): pass session and user context to on_turn_start#7789

Open
hughpyle wants to merge 1 commit into
NousResearch:mainfrom
keepnotes-ai:feat/memory-turn-context
Open

fix(memory): pass session and user context to on_turn_start#7789
hughpyle wants to merge 1 commit into
NousResearch:mainfrom
keepnotes-ai:feat/memory-turn-context

Conversation

@hughpyle

@hughpyle hughpyle commented Apr 11, 2026

Copy link
Copy Markdown

Summary

  • External memory providers receive per-turn context (user_id, user_name, session_title, platform) into MemoryManager.on_turn_start (in addition to the existing remaining_tokens/model/tool_count slots).
  • Adds turn_user_id / turn_user_name to run_conversation; gateway forwards source.user_id/source.user_name so multi-user threads attribute correctly.

Fully backward compatible — the base class and all in-tree providers already accept **kwargs, so unknown keys are silently absorbed.

Fixes #7193
Fixes #7781
Fixes #7777

Test plan

  • test_on_turn_start — existing test updated to verify empty kwargs passthrough
  • test_on_turn_start_passes_turn_context — new test: all four context keys reach the provider
  • test_turn_context_reaches_memory_manager_before_prefetch — new test: verifies on_turn_start fires before prefetch_all with correct gateway user override

@hughpyle hughpyle changed the title feat(memory): pass session and user context to on_turn_start fix(memory): pass session and user context to on_turn_start Apr 11, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder tool/memory Memory tool and memory providers comp/plugins Plugin system and bundled plugins labels Apr 29, 2026
@terion-name

Copy link
Copy Markdown

why still unmerged?((

@hughpyle

Copy link
Copy Markdown
Author

Actually I think this is obsoleted by parallel work, will take a look...

Complete the still-open part of PR NousResearch#7789 after upstream separately shipped session_id propagation through sync_turn/prefetch/queue_prefetch and session rotation hooks.

Gateway turns now pass per-message source.user_id and source.user_name into run_conversation so shared-thread messages can override the cached agent user. AIAgent forwards user_id, user_name, platform, and session_title through the existing on_turn_start hook for provider attribution.

This intentionally does not reintroduce session_id threading in on_turn_start; upstream already covers session attribution for writes and recalls. Providers that write during sync_turn can stash attribution received from on_turn_start and reuse it when syncing the completed turn.
@hughpyle hughpyle force-pushed the feat/memory-turn-context branch from d364386 to fc4ac4a Compare May 13, 2026 21:49
@hughpyle

hughpyle commented May 13, 2026

Copy link
Copy Markdown
Author

PR #17409 reworked the session-id to sync_turn etc. But the username and other context is still not available, this PR addresses those gaps.

Updated the descriptions in #7781 and #7777.

#7193 was largely addressed by PR#10619, this closes its remaining ask.

@terion-name

Copy link
Copy Markdown

soooo....?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

3 participants