Web Chat Agents
Overview
This document describes the two supported paths that invoke POSTAIResponse, the current gap for web chat instructions, and the refactor plan to align web chat with the Salesforce Apex path while enforcing strict security rules.
Invocation Paths
Salesforce managed package path
../sfdc/src/classes/AIAssistantController.clsbuildssystemMessageviaAIModel.getSystemPrompt(RunContext.Chat)and sends the request through../sfdc/src/classes/AIDialogueAction.cls.../sfdc/src/classes/AIDialogueAction.clsposts to/orgs/{orgId}/ai/responsevia../sfdc/src/classes/API.cls.src/main/java/api/routes/APIRoutes.javaroutes/orgs/{orgid}/ai/responsetosrc/main/java/api/ai/openai/responses/POSTAIResponse.java.- The Apex system prompt includes
<include type="skill" ... />tags, plus prompts, record context, knowledge, and memory sections as defined in../sfdc/src/classes/AIModel.cls.
Public web chat path
knowledge/public/presentation/page.pebembeds a JS widget that posts a minimalAIChatRequesttohttps://api.idialogue.app/v1/chat.src/main/java/api/routes/web/WebAPIRoutes.javaroutes/v1/chattosrc/main/java/api/routes/web/POSTWebChat.java.POSTWebChatsetsisWebChat=true, loads the published agent, and forwards the request toPOSTAIResponse.
Verified Handler Behavior
POSTAIResponseonly usessystemMessagefor initial requests; subsequent turns reuseDialogue.instructions.- When a
systemAgentis present,POSTAIResponsereplaces the system agent placeholder withAIAgent.getSystemPrompt(...)and continues. - When
systemMessageis present on an initial request,DialogueScriptProcessorexpands tool include tags into tool definitions andAIAgent.applyToolDefinitions(...)attaches the tools.
Web Chat Security Rule
Web chat must never accept client-provided instructions.
- Any
systemMessagefrom a web chat payload is ignored. - The initial web chat
systemMessageis always derived from the retrieved agent viaAIAgent.getSystemPrompt(...). - The
systemAgentbranch remains a separate request path and is not modified by this change.
How Tool Descriptions Are Injected For Web Chat
AIAgent.getSystemPrompt(...)appends<include type="skill" primitive="..." />tags for each skill on the agent.POSTAIResponserunsDialogueScriptProcessoron the initial request whensystemMessageis non-blank.DialogueScriptProcessorresolves those include tags into tool definitions andAIAgent.applyToolDefinitions(...)registers them for the Response API call.
Refactor Plan (TDD First)
- Add tests that prove web chat clears client
systemMessageand replaces it withAIAgent.getSystemPrompt(...)for initial requests. - Add tests that the web chat flow does not override system agent requests.
- Implement
POSTAIResponselogic to enforce the web chat security rule before parsing dialogue scripts. - Keep
systemAgentbehavior unchanged.
Alignment Notes (Apex vs Java)
AIAgent.buildSystemPrompt() is not yet feature-parity with the Apex AIModel.getSystemPrompt(...).
- Apex includes flow outputs, inline knowledge, memory blocks, and record context sections.
- Java
AIAgent.buildSystemPrompt()currently includes the basesystemPrompt, systemAIPromptblocks, and<include type="skill" ... />tags. - To fully align, extend the Java prompt builder to incorporate knowledge, memory, and record/file context as a separate, incremental follow-on change.