Context
Pass product and user context to the assistant, and update it live.
Context tells the assistant what the user is looking at and what you know about them, so answers, recommendations, and try-on are relevant.
data class LoopsAIChatContext(
val productContext: Map<String, String>? = null,
val userContext: Map<String, String>? = null,
)At launch
val config = LoopsAIChatConfig(
agentId = "YOUR_AGENT_ID",
initialContext = LoopsAIChatContext(
productContext = mapOf("productCode" to "SKU123", "productName" to "Linen Shirt"),
userContext = mapOf("firstName" to "Ada", "loyaltyTier" to "gold")
)
)Live updates
Hold the fragment and update context as the user navigates (e.g. swiping between products):
val fragment = LoopsAIChat.newFragment(config)
// later, when the visible product changes:
fragment.updateContext(
LoopsAIChatContext(productContext = mapOf("productCode" to "SKU999"))
)In Compose, set initialContext for the first launch; for live updates drive the
flow-mode methods (see Flow modes) or
recompose with new context.
Field conventions
| Context | Common keys |
|---|---|
productContext | productCode, productName, price, currency, actionType |
userContext | firstName, email, userId, plus any custom attributes |
Pass only what the assistant needs. userContext is forwarded to the runtime —
avoid sensitive fields you would not want in conversation logs or analytics.
Next: Flow modes.