11# Agentforce Mobile SDK - Integration Guide
22
3+ > ** Note** : This documentation reflects the latest SDK version with significant API updates. If you're migrating from an earlier version, please review the changes carefully.
4+
5+ Full integration guide available in the [ Agentforce Mobile SDK Developer Guide] ( https://developer.salesforce.com/docs/ai/agentforce/guide/agent-sdk.html )
6+
37## Getting Started with Agentforce
48
59The Agentforce Mobile SDK empowers you to integrate Salesforce's feature-rich, trusted AI platform directly into your native iOS and Android mobile applications. By leveraging the Agentforce Mobile SDK, you can deliver cutting-edge, intelligent, and conversational AI experiences to your mobile users, enhancing engagement and providing seamless access to information and actions.
@@ -82,6 +86,7 @@ dependencyResolutionManagement {
8286 mavenCentral()
8387 maven { url = uri(" https://jitpack.io" ) }
8488 maven { url = uri(" https://opensource.salesforce.com/AgentforceMobileSDK-Android/agentforce-sdk-repository" ) }
89+ maven { url = uri(" https://s3.amazonaws.com/inapp.salesforce.com/public/android" ) }
8590 maven { url = uri(" https://s3.amazonaws.com/salesforce-async-messaging-experimental/public/android" ) }
8691 }
8792}
@@ -100,13 +105,32 @@ plugins {
100105```
101106
102107#### Dependencies
108+
109+ Add the following to your module's ` build.gradle.kts ` :
110+
103111``` kotlin
104- // app/build.gradle.kts
105112dependencies {
106113 // Agentforce SDK Dependencies
107- api(" com.salesforce.android.agentforcesdk:agentforce-sdk:14.0.0" )
114+ api(" com.salesforce.android.agentforcesdk:agentforce-sdk:14.97.1" )
115+ }
116+ ```
117+
118+ ##### Core Library Desugaring
119+
120+ If your module doesn't already have core library desugaring configured, add the following to your ` build.gradle.kts ` :
121+
122+ ``` kotlin
123+ android {
124+ compileOptions {
125+ isCoreLibraryDesugaringEnabled = true
126+ }
127+ }
128+
129+ dependencies {
130+ coreLibraryDesugaring(" com.android.tools:desugar_jdk_libs:2.1.5" )
108131}
109132```
133+
110134After adding the dependencies, sync your project with the Gradle files.
111135
112136### Implement Core Service Interfaces
@@ -252,121 +276,211 @@ Optional components include:
252276- ` permission ` : For permission handling
253277
254278#### 2. Initialize the SDK and Build the View
255- Instantiate ` AgentforceClient ` and add the ` AgentforceLauncherContainer ` to your Composable UI.
256279
257- ##### Instantiate ` AgentforceClient `
258- 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.
280+ ##### Implement an Auth Credential Provider
259281
260- ``` kotlin
261- import androidx.lifecycle.ViewModel
262- import com.salesforce.android.agentforcesdkimpl.AgentforceClient
263- import com.salesforce.android.agentforceservice.AgentforceServiceProvider
282+ Create an implementation of ` AgentforceAuthCredentialProvider ` to supply authentication credentials to the SDK.
264283
265- class MyViewModel : ViewModel () {
266- // Retain the client in a ViewModel
267- val agentforceClient: AgentforceClient
284+ ** For Employee Agents (OAuth):**
268285
269- init {
270- // Assume you have access to your config and interface implementations
271- val serviceProvider = AgentforceServiceProvider (
272- network = MyAppNetwork (okHttpClient), // Your implementation
273- credentialProvider = MyAppCredentialProvider (userSession) // Your implementation
274- // Pass optional implementations here (logger, delegate, etc.)
275- )
286+ ``` kotlin
287+ import com.salesforce.android.agentforceservice.AgentforceAuthCredentialProvider
288+ import com.salesforce.android.agentforceservice.AgentforceAuthCredentials
276289
277- agentforceClient = AgentforceClient (
278- configuration = agentforceConfig, // Your config from the previous step
279- serviceProvider = serviceProvider
280- )
281- }
290+ class MyAuthCredentialProvider : AgentforceAuthCredentialProvider {
291+ override fun getAuthCredentials (): AgentforceAuthCredentials {
292+ return AgentforceAuthCredentials .OAuth (
293+ authToken = " your-oauth-token" ,
294+ orgId = " your-org-id" ,
295+ userId = " your-user-id"
296+ )
297+ }
282298}
283299```
284300
285- ##### Build and Present the View
286- Use the ` AgentforceLauncherContainer ` Composable in your screen. It displays a Floating Action Button (FAB) that, when tapped, presents the full chat container.
301+ ** For Service Agents (Guest / Unauthenticated):**
287302
288303``` kotlin
289- import androidx.compose.runtime.Composable
290- import com.salesforce.android.agentforcesdk.ui.AgentforceLauncherContainer
291- import androidx.lifecycle.viewmodel.compose.viewModel
292-
293- @Composable
294- fun MyScreen (viewModel : MyViewModel = viewModel()) {
295- // ... Your existing screen content (e.g., inside a Scaffold)
296-
297- // Add the Agentforce Launcher
298- AgentforceLauncherContainer (client = viewModel.agentforceClient)
304+ class MyGuestCredentialProvider : AgentforceAuthCredentialProvider {
305+ override fun getAuthCredentials (): AgentforceAuthCredentials {
306+ return AgentforceAuthCredentials .Guest (url = " https://your-instance.salesforce.com" )
307+ }
299308}
300309```
301310
302- ##### Starting a Conversation
311+ ##### Build the Configuration
303312
304- Once you have initialized the ` AgentforceClient ` , you can start a conversation with an agent using the ` startAgentforceConversation ` method.
313+ Use ` AgentforceConfiguration.builder() ` to create a configuration with your auth provider:
305314
306315``` kotlin
307- // Start the conversation
308- agentforceClient.startAgentforceConversation()
309-
310- // Option 1: Get the conversation session using fetchAgentforceSession
311- val session = agentforceClient.fetchAgentforceSession(YOUR_AGENT_ID )
316+ import com.salesforce.android.agentforcesdkimpl.configuration.AgentforceConfiguration
312317
313- // Option 2: Create a new AgentforceConversation object
314- val conversation = AgentforceConversation (
315- configuration = configuration,
316- conversationService = agentforceClient.conversationService
318+ val configuration = AgentforceConfiguration .builder(
319+ authCredentialProvider = myAuthCredentialProvider
317320)
321+ .setApplication(application)
322+ .setSalesforceDomain(" https://your-instance.salesforce.com" )
323+ .setThemeManager(createCustomAgentforceThemeManager(themeMode = AgentforceThemeMode .SYSTEM ))
324+ .setLogger(myLogger) // optional
325+ .setViewProvider(myViewProvider) // optional: register custom component renderers
326+ .build()
318327```
319328
320- Both approaches start a conversation and provide access to an ` AgentforceConversation ` object, which represents a single conversation with an agent. You can use this session/conversation to interact with the agent and manage the conversation state.
329+ ##### Create an AgentforceMode
330+
331+ The SDK supports two primary modes:
332+
333+ ** Employee Agent (FullConfig):**
334+
335+ ``` kotlin
336+ import com.salesforce.android.agentforcesdkimpl.configuration.AgentforceMode
337+
338+ val agentforceMode = AgentforceMode .FullConfig (configuration)
339+ ```
321340
322- ##### Displaying the Chat UI
341+ ** Service Agent: **
323342
324- To display the chat UI, you can use the ` AgentforceConversationContainer ` Composable. This Composable provides the complete chat interface that you can integrate into your app.
343+ ``` kotlin
344+ import com.salesforce.android.agentforcesdkimpl.configuration.AgentforceMode
345+ import com.salesforce.android.agentforcesdkimpl.configuration.ServiceAgentConfiguration
346+ import com.salesforce.android.agentforceservice.miaw.AuthorizationContext
347+ import com.salesforce.android.agentforceservice.miaw.AuthorizationMethod
348+
349+ val serviceAgentConfig = ServiceAgentConfiguration .builder(
350+ serviceApiURL = " https://your-service-api-url" ,
351+ organizationId = " your-org-id" ,
352+ esDeveloperName = " your-es-developer-name" ,
353+ authorizationContext = AuthorizationContext (
354+ authorizationMethod = AuthorizationMethod .UNVERIFIED
355+ )
356+ ).build()
357+
358+ val agentforceMode = AgentforceMode .ServiceAgent (
359+ serviceAgentConfiguration = serviceAgentConfig,
360+ agentforceConfiguration = configuration // optional: pass configuration for theming, logger, etc.
361+ )
362+ ```
325363
326- First, create an ` AgentforceConversation ` object:
364+ ##### Initialize the Client and Start a Conversation
327365
328366``` kotlin
329- // Create the conversation object
330- val conversation = AgentforceConversation (
331- configuration = configuration,
332- conversationService = agentforceClient.conversationService
367+ import com.salesforce.android.agentforcesdkimpl.AgentforceClient
368+
369+ val agentforceClient = AgentforceClient ()
370+ agentforceClient.init (
371+ authCredentialProvider = configuration.authCredentialProvider,
372+ agentforceMode = agentforceMode,
373+ application = application
333374)
375+
376+ // Start a conversation (optionally pass an agentId)
377+ val conversation = agentforceClient.startAgentforceConversation()
378+ // or with a specific agent:
379+ // val conversation = agentforceClient.startAgentforceConversation(agentId = "your-agent-id")
334380```
335381
336- Then use the ` AgentforceConversationContainer ` Composable:
382+ ##### Display the Chat UI
383+
384+ Use the ` AgentforceConversationContainer ` Composable provided by ` AgentforceClient ` :
337385
338386``` kotlin
339387import androidx.compose.runtime.Composable
388+ import com.salesforce.android.agentforcesdkimpl.AgentforceClient
340389import com.salesforce.android.agentforcesdkimpl.AgentforceConversation
341390
342391@Composable
343- fun MyChatScreen (conversation : AgentforceConversation , agentforceClient : AgentforceClient ) {
344- agentforceClient.AgentforceConversationContainer (
345- conversation = conversation,
346- onClose = {
347- // Handle chat view close
348- }
349- )
392+ fun MyChatScreen (
393+ agentforceClient : AgentforceClient ,
394+ conversation : AgentforceConversation ,
395+ onClose : () -> Unit
396+ ) {
397+ agentforceClient.AgentforceConversationContainer (
398+ conversation = conversation,
399+ onClose = onClose
400+ )
350401}
351402```
352403
353- The ` AgentforceConversationContainer ` Composable takes the following parameters:
404+ The ` AgentforceConversationContainer ` Composable renders the full chat interface including the top app bar, message list, and input field. The ` onClose ` callback is invoked when the user closes the chat view.
354405
355- - ` conversation ` : The ` AgentforceConversation ` object that you created
356- - ` onClose ` : A lambda that will be called when the user closes the chat view
406+ ##### Full Example (Activity)
357407
358- You can also use the ` AgentforceLauncherContainer ` for a floating action button approach :
408+ Below is a minimal Activity that shows/hides the chat UI :
359409
360410``` kotlin
361- @Composable
362- fun MyScreen () {
363- // Your existing screen content
411+ class MyActivity : ComponentActivity () {
412+
413+ private var agentforceClient: AgentforceClient ? = null
414+ private var conversation: AgentforceConversation ? = null
415+
416+ override fun onCreate (savedInstanceState : Bundle ? ) {
417+ super .onCreate(savedInstanceState)
418+
419+ // Initialize the Agentforce client and start a conversation
420+ initializeAgentforce()
421+
422+ setContent {
423+ var showChat by rememberSaveable { mutableStateOf(false ) }
424+
425+ Box (Modifier .fillMaxSize()) {
426+ // Your app content
427+ Button (onClick = { showChat = true }) {
428+ Text (" Open Chat" )
429+ }
430+
431+ // Show chat overlay
432+ if (showChat) {
433+ conversation?.let { conv ->
434+ agentforceClient?.AgentforceConversationContainer (
435+ conversation = conv,
436+ onClose = { showChat = false }
437+ )
438+ }
439+ }
440+ }
441+ }
442+ }
443+
444+ private fun initializeAgentforce () {
445+ val authProvider = MyAuthCredentialProvider ()
364446
365- // Add the Agentforce Launcher (FAB)
366- AgentforceLauncherContainer (client = agentforceClient)
447+ val configuration = AgentforceConfiguration .builder(
448+ authCredentialProvider = authProvider
449+ )
450+ .setApplication(application)
451+ .setSalesforceDomain(" https://your-instance.salesforce.com" )
452+ .build()
453+
454+ val mode = AgentforceMode .FullConfig (configuration)
455+
456+ agentforceClient = AgentforceClient ().also {
457+ it.init (
458+ authCredentialProvider = authProvider,
459+ agentforceMode = mode,
460+ application = application
461+ )
462+ }
463+ conversation = agentforceClient?.startAgentforceConversation()
464+ }
367465}
368466```
369467
468+ ##### Optional: Customize the Theme
469+
470+ Use ` createCustomAgentforceThemeManager ` to customize colors, typography, and theme mode:
471+
472+ ``` kotlin
473+ import com.salesforce.android.agentforcesdk.components.theme.createCustomAgentforceThemeManager
474+ import com.salesforce.android.agentforcesdk.components.theme.AgentforceThemeMode
475+
476+ val themeManager = createCustomAgentforceThemeManager(
477+ themeMode = AgentforceThemeMode .SYSTEM // or LIGHT / DARK
478+ )
479+
480+ // Pass to configuration builder:
481+ // .setThemeManager(themeManager)
482+ ```
483+
370484## Basic Use Cases
371485
372486### Sending a Message
0 commit comments