Cartesiandocs

Android SDK

Headless (core only)

Use cartesian-core to build a completely custom experience, or to run Cartesian from non-UI code.

cartesian-core is plain Kotlin: coroutines, StateFlow and OkHttp. It has no Compose or View dependency, so it also works in a JVM service or a test.

build.gradle.kts
implementation("ai.cogitx.cartesian:cartesian-core:0.1.0")

Create a client

val client = CartesianClient(
    CartesianConfig.builder(Vertical.Grocery, "https://cartesian.yourcompany.com").build(),
    sessionStore = MySessionStore(),       // defaults to InMemorySessionStore()
)
client.signIn(token)
kotlin

Keep one client per backend and close it with client.close() when you're done.

Run a conversation

scope.launch {
    client.chat.state.collect { state ->
        val last = state.messages.lastOrNull() as? AssistantMessage ?: return@collect
        render(last.text, last.products, last.activeStep?.title)
    }
}

client.chat.send("Find whole milk and add the cheapest gallon to my cart")
// …later
client.chat.stop()       // interrupt the running answer
client.chat.newChat()    // start a fresh thread
kotlin

send suspends until the backend accepts the turn. The answer then streams into state. If a turn is already running it throws CartesianException.Busy.

React to events

client.chat.events.collect { event ->
    when (event) {
        is ChatEvent.TurnStarted -> analytics.log("assistant_turn_started")
        is ChatEvent.ProductsShown -> analytics.log("assistant_products", event.products.size)
        is ChatEvent.CartChanged -> refreshMyCartBadge()
        is ChatEvent.TurnFinished -> analytics.log("assistant_answer", event.message.elapsedSeconds)
        is ChatEvent.Error -> Log.w("Cartesian", event.message)
    }
}
kotlin

Follow-up suggestions

After each finished answer, client.chat.suggestions holds up to a handful of follow-up questions written by the backend:

client.chat.suggestions.collect { chips -> showChips(chips) }
kotlin

Cart, wishlist and threads

client.cart.value.itemCount
client.addToCart(product, quantity = 2)
client.setCartQuantity(product.id, 0)
client.save(product)                 // wishlist
client.refreshThreads()              // List<ThreadSummary>
client.chat.open(threadId)           // reopen a past conversation
kotlin

The full surface is in the CartesianClient and ChatSession references.