Use Full UI

This guide shows you how to use the prebuilt UI components to quickly integrate Agentforce chat functionality into your Android app.

AgentforceLauncherContainer 

Use the AgentforceLauncherContainer Composable in your screen. It displays a Floating Action Button (FAB) that, when tapped, presents the full chat container.

1import androidx.compose.runtime.Composable
2import com.salesforce.android.agentforcesdk.ui.AgentforceLauncherContainer
3import androidx.lifecycle.viewmodel.compose.viewModel
4
5@Composable
6fun MyScreen(viewModel: MyViewModel = viewModel()) {
7    // ... Your existing screen content (e.g., inside a Scaffold)
8
9    // Add the Agentforce Launcher
10    AgentforceLauncherContainer(client = viewModel.agentforceClient)
11}

AgentforceConversationContainer 

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.

First, create an AgentforceConversation object:

1// Create the conversation object
2val conversation = AgentforceConversation(
3    configuration = configuration,
4    conversationService = agentforceClient.conversationService
5)

Then use the AgentforceConversationContainer Composable:

1import androidx.compose.runtime.Composable
2import com.salesforce.android.agentforcesdkimpl.AgentforceConversation
3
4@Composable
5fun MyChatScreen(conversation: AgentforceConversation, agentforceClient: AgentforceClient) {
6    agentforceClient.AgentforceConversationContainer(
7        conversation = conversation,
8        onClose = {
9            // Handle chat view close
10        }
11    )
12}

The AgentforceConversationContainer Composable takes the following parameters:

  • conversation: The AgentforceConversation object that you created
  • onClose: A lambda that will be called when the user closes the chat view

Full Activity Example 

The following example shows a complete Activity implementation that integrates the Agentforce chat UI:

1class MyActivity : ComponentActivity() {
2
3    private var agentforceClient: AgentforceClient? = null
4    private var conversation: AgentforceConversation? = null
5
6    override fun onCreate(savedInstanceState: Bundle?) {
7        super.onCreate(savedInstanceState)
8
9        // Initialize the Agentforce client and start a conversation
10        initializeAgentforce()
11
12        setContent {
13            var showChat by rememberSaveable { mutableStateOf(false) }
14
15            Box(Modifier.fillMaxSize()) {
16                // Your app content
17                Button(onClick = { showChat = true }) {
18                    Text("Open Chat")
19                }
20
21                // Show chat overlay
22                if (showChat) {
23                    conversation?.let { conv ->
24                        agentforceClient?.AgentforceConversationContainer(
25                            conversation = conv,
26                            onClose = { showChat = false }
27                        )
28                    }
29                }
30            }
31        }
32    }
33
34    private fun initializeAgentforce() {
35        val authProvider = MyAuthCredentialProvider()
36
37        val configuration = AgentforceConfiguration.builder(
38            authCredentialProvider = authProvider
39        )
40            .setApplication(application)
41            .setSalesforceDomain("https://your-instance.salesforce.com")
42            .build()
43
44        val mode = AgentforceMode.FullConfig(configuration)
45
46        agentforceClient = AgentforceClient().also {
47            it.init(
48                authCredentialProvider = authProvider,
49                agentforceMode = mode,
50                application = application
51            )
52        }
53        conversation = agentforceClient?.startAgentforceConversation()
54    }
55}

Handle UI Events 

To handle UI events, implement the AgentforceUIDelegate interface. This interface provides callbacks for modifying messages before sending, handling sent messages, and managing agent switches.

1class YourActivity : AgentforceUIDelegate {
2   override suspend fun modifyUtteranceBeforeSending(utterance: AgentforceUtterance): AgentforceUtterance {
3      // Modify the utterance if needed
4      return utterance
5   }
6
7   override fun didSendUtterance(utterance: AgentforceUtterance) {
8      // Handle sent utterance
9   }
10
11   override fun userDidSwitchAgents(newConversation: AgentforceConversation) {
12      // Handle agent switch
13   }
14}

The AgentforceUIDelegate interface provides the following methods:

  • modifyUtteranceBeforeSending(utterance: AgentforceUtterance): Called before an utterance is sent to the agent. Allows you to modify the utterance before it is sent.
  • didSendUtterance(utterance: AgentforceUtterance): Called after an utterance has been sent to the agent.
  • userDidSwitchAgents(newConversation: AgentforceConversation): Called when the user switches to a different agent.

Next Steps