The Agentforce Mobile SDK is designed for flexibility and delegates several core responsibilities to the host application. You must create concrete implementations for the following interfaces:
AgentforceAuthCredentialProvider: Supplies the SDK with the authentication token (e.g., OAuth 2.0 access token) required to communicate securely with Salesforce APIs.
AgentforceInstrumentation: A handler for the SDK to emit instrumentation and telemetry data into your app’s analytics system.
For authentication, create a credential provider using one of the supported authentication methods.
In order to use the Agentforce SDK you must first identify the agent type you are targeting: Employee Agent or Service Agent. A single app may target each, but requires configuration and instantiation of separate Agentforce clients. To learn more, see Create an Agent from a Template in Salesforce Help.
For guidance on gathering information for the agent configuration object, see Agent Type Setup in Before You Begin.
Tip
The following snippets illustrate how to configure your agent for each agent type.
Create and retain an instance of AgentforceClient. It’s best to hold this in a lifecycle-aware component, like a ViewModel, to ensure the conversation state persists across configuration changes.
Start a Conversation
Once you’ve initialized the AgentforceClient, you can start a conversation with an agent using the startAgentforceConversation method.
Start Conversation
1// Start the conversation2agentforceClient.startAgentforceConversation()34// Get the conversation session5val session = agentforceClient.fetchAgentforceSession(YOUR_AGENT_ID)
This method returns an AgentforceConversation object, which represents a single conversation with an agent.
Next Steps
Prebuilt UI: See Use Prebuilt UI for ready-to-use chat interface