Member Junction
    Preparing search index...

    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 BaseAgent methods). The system-message side effects are applied to the supplied conversationMessages array, exactly as before.

    Index

    Constructors

    Methods

    • 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).

      Parameters

      • lastUserMessage: string

        The most recent user message text.

      • agent: MJAIAgentEntityExtended

        The agent being executed.

      • contextUser: UserInfo

        Calling user (threaded to SearchEngine + Metadata).

      • conversationMessages: ChatMessage[]

        The mutated message array that flows to the LLM (system msg is unshifted here).

      • originalMessages: ChatMessage[]

        The unmodified messages array (for template recentMessages).

      • OptionalprimaryScopeEntityId: string

        Multi-tenant primary scope entity ID.

      • OptionalprimaryScopeRecordId: string

        Multi-tenant primary scope record ID.

      • OptionalsecondaryScopes: Record<string, SecondaryScopeValue>

        Multi-tenant secondary scope dimensions.

      • Optionalpayload: unknown

        The agent's current payload (for template rendering).

      • OptionallogStatus: AgentMemoryStatusLogger

        Optional verbose-aware status logger.

      • OptionallogError: AgentMemoryErrorLogger

        Optional error logger (used when RAG injection fails non-fatally).

      Returns Promise<AgentPreExecutionRAGResult>

      The structured RAG result, or null if no scopes produced results.