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.
public struct LoopsAIChatContext {
let productContext: [String: String]?
let userContext: [String: String]?
}At launch
let config = LoopsAIChatConfig(
agentId: "YOUR_AGENT_ID",
initialContext: LoopsAIChatContext(
productContext: ["productCode": "SKU123", "productName": "Linen Shirt"],
userContext: ["firstName": "Ada", "loyaltyTier": "gold"]
)
)Live updates
Hold the returned view controller and update context as the user navigates (e.g. swiping between products):
let vc = LoopsAIChat.present(from: self, config: config)
// later, when the visible product changes:
vc.updateContext(
LoopsAIChatContext(productContext: ["productCode": "SKU999"])
)In SwiftUI, set initialContext for the first launch; for live updates drive the
flow-mode methods (see Flow modes) or
re-present 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.