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 notes and examples into agent context memory. Injects memory context directly into the supplied conversation messages array.

      Parameters

      • input: string

        The user input text for semantic search

      • agent: MJAIAgentEntityExtended

        The agent configuration entity

      • OptionaluserId: string

        Optional user ID for scoping

      • OptionalcompanyId: string

        Optional company ID for scoping

      • OptionalcontextUser: UserInfo

        User context

      • OptionalconversationMessages: ChatMessage[]

        The conversation messages array to inject into

      • OptionalprimaryScopeEntityId: string

        Optional primary scope entity ID for multi-tenant filtering

      • OptionalprimaryScopeRecordId: string

        Optional primary scope record ID for multi-tenant filtering

      • OptionalsecondaryScopes: Record<string, SecondaryScopeValue>

        Optional secondary scope dimensions for multi-tenant filtering

      • OptionalsecondaryScopeConfig: SecondaryScopeConfig

        Optional agent-level scope config for per-dimension inheritance

      • Optionalobservability: AgentMemoryObservability

        Optional observability context for run-step tracking

      • OptionallogStatus: AgentMemoryStatusLogger

        Optional verbose-aware status logger

      • OptionalsharedOnly: boolean

        Inject only shared notes and examples (no UserID): set when the run has an audience that adds a reader (ExecuteAgentParams.Audience), so one user's memory is not shown to a room

      Returns Promise<{ examples: MJAIAgentExampleEntity[]; notes: MJAIAgentNoteEntity[] }>

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

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

      • OptionalactiveSkillIDs: string[]

        The skills active for this run; a lone active skill is the search's skill principal.

      • OptionalaudienceReaders: UserInfo[]

        The run's audience readers beyond the caller (hydrated users): each must pass the scope gate, and the search keeps only results every one of them may read. Empty or omitted: no audience.

      Returns Promise<AgentPreExecutionRAGResult>

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