Loops AI Docs

Quickstart

Open the Loops assistant in a few lines — Compose, Activity, or Fragment.

Open the assistant with your agentId. That's the minimum integration.

import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.foundation.layout.fillMaxSize
import com.loopsai.chat.LoopsAIChatConfig
import com.loopsai.chat.LoopsAIChatView

@Composable
fun MyScreen() {
  var isChatOpen by remember { mutableStateOf(false) }
  val config = LoopsAIChatConfig(agentId = "YOUR_AGENT_ID")

  Button(onClick = { isChatOpen = true }) { Text("Ask the assistant") }

  if (isChatOpen) {
    LoopsAIChatView(
      config = config,
      modifier = Modifier.fillMaxSize(),
      onClose = { isChatOpen = false }
    )
  }
}
import com.loopsai.chat.LoopsAIChat
import com.loopsai.chat.LoopsAIChatConfig

class ProductActivity : AppCompatActivity() {
  fun openChat() {
    val config = LoopsAIChatConfig(agentId = "YOUR_AGENT_ID")
    LoopsAIChat.openAsActivity(this, config)
  }
}
import com.loopsai.chat.LoopsAIChat
import com.loopsai.chat.LoopsAIChatConfig

val config = LoopsAIChatConfig(agentId = "YOUR_AGENT_ID")
LoopsAIChat.open(
  fragmentManager = supportFragmentManager,
  containerId = R.id.container,
  config = config
)

Add product context

On a product page, tell the assistant what the user is looking at so its answers and try-on are relevant:

val config = LoopsAIChatConfig(
  agentId = "YOUR_AGENT_ID",
  initialContext = LoopsAIChatContext(
    productContext = mapOf("productCode" to "SKU123", "productName" to "Linen Shirt")
  )
)
LoopsAIChat.openAsActivity(this, config)

Observe what happens

Pass a LoopsAIChatListener (Activity/Fragment) or the on… lambdas (Compose) to react to chat events:

class ProductActivity : AppCompatActivity(), LoopsAIChatListener {
  fun openChat() {
    LoopsAIChat.openAsActivity(this, config, listener = this)
  }

  override fun onReady(fragment: LoopsAIChatFragment) { /* push context */ }
  override fun onResponding(fragment: LoopsAIChatFragment, isResponding: Boolean) { /* spinner */ }
  override fun onError(fragment: LoopsAIChatFragment, error: LoopsError) { /* log */ }
}

All listener methods have default no-op implementations — onCloseRequested finishes/pops by default, onOpenUrlRequested opens the system browser.

Next: Configuration.

On this page