Assemble the context supplied to the ai

Before every call to the AI/LLM Service — Auto Reply or Copilot — the system assembles a bounded request context: the current message, recent conversation history, permitted customer-profile fields, retrieved source passages, configured rules, channel restrictions and any channel-specific reply context, all limited to the requesting your visibility scope and never crossing tenants.

When this happens: An Auto Reply gate pass or a Copilot request (UC-28.15 – UC-28.17).

How it works

  • Resolves the requesting scope: for Auto Reply, the conversation and its own customer only; for Copilot, the requesting operator's visibility scope — the request is rejected before context assembly if the operator cannot access the conversation.
  • Includes the current inbound message (or, for Rephrase, the operator's draft text).
  • Includes bounded conversation history: the most recent messages of the conversation, up to a configurable cap (default 20), oldest-first, tenant- and conversation-scoped only.
  • Includes the customer profile fields the requesting party may see — the field-access policy (FR-02) applied the same as in the UI, never fields hidden from that party.
  • Retrieves the top-matching passages from the company's active, indexed AiSource rows for the current message.
  • Includes the configured rules: Instructions, Persona, ToneOfVoice, AnswerBeyondSources, active AiHandoverRules and active AiForbiddenTopics.
  • Includes the sending channel's capability declaration (content types, size limits, window state — FR-16 – FR-22) so the AI does not draft a reply the channel cannot deliver.
  • If the current or replied-to message carries ExternalContext (the Instagram/Facebook Story, Reel or Post it responds to; the Telegram message it replies to; the Live Chat page URL — UC-17.14, UC-18.14, UC-19.8, UC-22.22), includes it.
  • Passes the assembled context to IAiCompletionClient.

Other paths

No sources match

If no source passage clears the retrieval relevance floor. Context is assembled without source passages; the AI's reply will fail groundedness unless .

If something goes wrong

Requesting operator cannot access the conversation

If the conversation falls outside the requesting operator's visibility scope. The Copilot request is rejected before any context is built or any provider call is made — EasyCrm:Ai:Disabled is not the code here; the standard 403 authorization rejection applies, exactly as it would for opening the conversation itself.

Good to know

  • Context is bounded by the requesting your visibility scope (ADR-012); a company's AI never uses another company's information — sources, settings and retrieval are tenant-scoped.
  • History is bounded, never the entire conversation without limit — this keeps requests within provider token limits and keeps context assembly deterministic and testable.
  • Context assembly depends on the same data-access filter as every other query; changes to that filter must be tested against AI paths too (ADR-012).