Inject notes and examples into agent context memory. Injects memory context directly into the supplied conversation messages array.
The user input text for semantic search
The agent configuration entity
OptionaluserId: stringOptional user ID for scoping
OptionalcompanyId: stringOptional company ID for scoping
OptionalcontextUser: UserInfoUser context
OptionalconversationMessages: ChatMessage[]The conversation messages array to inject into
OptionalprimaryScopeEntityId: stringOptional primary scope entity ID for multi-tenant filtering
OptionalprimaryScopeRecordId: stringOptional primary scope record ID for multi-tenant filtering
OptionalsecondaryScopes: Record<string, SecondaryScopeValue>Optional secondary scope dimensions for multi-tenant filtering
OptionalsecondaryScopeConfig: SecondaryScopeConfigOptional agent-level scope config for per-dimension inheritance
Optionalobservability: AgentMemoryObservabilityOptional observability context for run-step tracking
OptionallogStatus: AgentMemoryStatusLoggerOptional verbose-aware status logger
Object containing injected notes and examples
Inject pre-execution RAG context for this agent using scoped search.
Loads the agent's AIAgentSearchScope rows (Phase IN 'PreExecution'|'Both'), renders any
per-scope query templates, calls SearchEngine.Search() per scope, cross-scope RRF fuses
the results when multiple scopes contributed, and unshifts a <retrieved_context> system
message onto conversationMessages.
When the agent has no active pre-execution scopes (or all scopes returned zero results),
this method is a no-op — no system message is injected and null is returned.
See plans/search-scopes-rag-plus.md §4 (Agent Integration — Pre-Execution RAG).
The most recent user message text.
The agent being executed.
Calling user (threaded to SearchEngine + Metadata).
The mutated message array that flows to the LLM (system msg is unshifted here).
The unmodified messages array (for template recentMessages).
OptionalprimaryScopeEntityId: stringMulti-tenant primary scope entity ID.
OptionalprimaryScopeRecordId: stringMulti-tenant primary scope record ID.
OptionalsecondaryScopes: Record<string, SecondaryScopeValue>Multi-tenant secondary scope dimensions.
Optionalpayload: unknownThe agent's current payload (for template rendering).
OptionallogStatus: AgentMemoryStatusLoggerOptional verbose-aware status logger.
OptionallogError: AgentMemoryErrorLoggerOptional error logger (used when RAG injection fails non-fatally).
The structured RAG result, or null if no scopes produced results.
Shared helper that orchestrates context-memory and pre-execution RAG injection for an agent.
Stateless: every method receives all required inputs as parameters and returns the data the caller needs to persist (matching the original return shapes of the
BaseAgentmethods). The system-message side effects are applied to the suppliedconversationMessagesarray, exactly as before.