---
schema_version: "1"
id: 60d644dbc62fa7d6b92a9e4491b2d0b96910d491891b8092faaa5b89ccc3c313
title: Build a Headless Experience
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/genai/agentforce-mobile-sdk/guides/android/agentforce-mobile-sdk-android-headless.md
canonical_url: https://developer.salesforce.com/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-android-headless.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 48d1bc623d954b69fa95dbaa6c024677c33635838e5e9c2956ac5cd4d8881e01
products:
  - Agentforce Mobile SDK
  - Agentforce and Einstein Generative AI
---
# Build a Headless Experience

This approach is for developers who want to build a completely custom UI or run agent interactions in the background. The `AgentforceService` handles the communication and state, emitting events via Kotlin Flows that your app uses to update its own UI or trigger logic.

## Instantiate AgentforceService

Use the `AgentforceServiceProvider` to create an `AgentforceService` instance for a specific agent.

```kotlin
import com.salesforce.android.agentforceservice.AgentforceServiceProvider
import com.salesforce.android.agentforceservice.AgentforceService

// Create the service provider with required dependencies
val serviceProvider = AgentforceServiceProvider(
    configurationLocale = Locale.getDefault(),
    domain = "https://your-domain.my.salesforce.com",
    network = MyAppNetwork(okHttpClient),
    credentialProvider = MyAppCredentialProvider(userSession),
    instrumentationHandler = myInstrumentationHandler, // Optional
    logger = myLogger // Optional
)

// Get the service for your specific agent
val agentId = "YOUR_AGENT_ID"
val agentforceService: AgentforceService = serviceProvider.getAgentforceService(agentId)
```

## Send Messages

To send a message to the agent programmatically, you can use a method like `sendUtterance` on your `AgentforceConversation` object:

```kotlin
// Example: Sending a message with an optional attachment
conversation.sendUtterance(
    utterance = "Hello, world!",
    attachment = null // or provide an AgentforceAttachment object
)
```

## Receive Messages

To receive messages from the agent, you can use the `conversationManager` property on the `AgentforceConversation` object:

```kotlin
// Example: Using conversationManager to send and receive messages
val responseChannel = conversation.conversationManager.sendMessage(
    inputRepresentation = ConversationInputRepresentation("Hello, world!"),
    agentforceAttachment = null, // Optional attachment
    file = null // Optional file
)
```

## Next Steps

- **Customization**: See [Branding and Theming](https://developer.salesforce.com/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-android-branding-theming.md) for visual customization
