Agentforce Conversation Client API
Use the Agentforce Conversation Client (ACC) API to programmatically manage the state of the native Agentforce side panel within the Salesforce Lightning desktop interface.
The ACC API is implemented as a headless LWC module (lightning/accApi) that acts as a router of app-to-panel messages. It enables communication between custom LWC components and Agentforce panel.
With the ACC API, interact with your agent inside Salesforce application programmatically to:
- Open and close a panel
- Execute utterances
Before implementing the API, ensure your environment meets the following requirements:
- Interface: This feature is supported exclusively in the Salesforce Lightning Experience desktop environment.
- Compatibility: This feature is for the default Lightning Experience panel only; other interfaces like Tableau or SentOS are not supported.
- API Version: The lightning/accApi module requires API version 59.0 or later.
- Feature Access: Your Salesforce org must have Agentforce enabled.
Use this API for programmatic control to open, close, or send a text utterance to the native Agentforce side panel from a custom LWC.
To interact with the panel, import the methods from the lightning/accApi module into your custom Lightning web component JavaScript file.
If you do not yet have a custom LWC, please refer to the standard Salesforce Lightning Web Components Developer Guide to initialize your project and create your component first.
To make your custom component available on record and home pages, add targets to the component's meta.xml file:
After adding the targets and deploying your component, you can use the Lightning App Builder to include the component on a record or home page. See Create and Configure Lightning Experience Record Pages.
Communicate directly with the panel from your custom LWC components.
All Panel API methods are asynchronous and return a void promise (Promise<void>).
-
Signature:
export function open(botId?: string): Promise<void>;Description: This function opens the Agentforce chat panel and resolves once the panel is successfully opened. It accepts an optional
botIdto open the panel with a specific agent; if abotIdstring isn't provided, the panel opens using the last used agent.Example: Open with a Specific Agent
JavaScript
-
Signature:
export function close(): Promise<void>;Description: This function hides the Agentforce chat panel and resolves once it is successfully closed. This method requires no parameters.
Example: Close the Panel
JavaScript
The execute method programmatically sends a command to the agent as if the user had typed it into the panel. This method executes the utterance for the provided botID.
-
Signature:
export function execute(utterance: string, botId: string): Promise<void>;Description: Provide a natural language string directly to the
executemethod. This method requires abotIdparameter to execute the utterance for the specific agent. If multiple execute requests are made, they are queued and executed strictly in sequence.Example: Execute a Natural Language Utterance
JavaScript
This example showcases a custom Lightning Web Component (LWC), CustomAgentforceLauncher, that demonstrates the core programmatic control features of the Agentforce Conversation Client API. This component uses methods imported from the lightning/accApi module to manage the native Agentforce side panel. The component includes three asynchronous methods:
handleOpenChat(): Calls theopen()method to display the Agentforce chat panel.handleCloseChat(): Calls theclose()method to hide the Agentforce chat panel.handleSendMessage(): Calls theexecute(utterance, botId)method to programmatically send a natural language utterance, "What is my account balance?", to the agent.
This functional snippet illustrates how custom host applications can communicate directly with the panel to manage its state (open/close) and invoke actions on the agent (execute utterance).
Example
Review these limitations and best practices when building with the ACC API:
- Queueing Behavior: All requests that are made would be queued and executed strictly in sequence. The platform ensures that the next query is only executed after the previous one has completed.
- Executing Actions: Currently, only natural language utterances are supported. You cannot execute an action directly by passing its name.
- Finding the Bot ID: Retrieve the
botIdfor your agents by checking the URL within the Agent Builder in Salesforce Setup. - Multiple Panels: Use the
botIdto explicitly target a specific agent to prevent behavior overlap if multiple agents are active in the same org. - No Return Data: The
executemethod does not return the agent's textual response to your component. - Asynchronous Methods:
open,close, andexecuteare asynchronous and must be handled using standard JavaScript Promise patterns.