OctoClient for Android

Create and configure OctoClient in the Android SDK: constructor settings, the methods it exposes, threading and how to shut it down.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

OctoClient is the entry point of the Android SDK. It holds the agent id, the current user identity and the HTTP connection, and every other call goes through it. Create one instance per agent and share it across your app.

Create a client

val octo = OctoClient(
    context = applicationContext,
    agentId = "agt_123",
    userIdentity = null,
    requestTimeoutSeconds = 30,
)

Pass applicationContext, not an Activity, so the client does not hold on to a screen.

Constructor settings

Setting Type Description
context Context Application context used for storage and connectivity checks.
agentId String The agent to talk to, for example agt_123. Required.
userIdentity UserIdentity? Optional identity to attach from the first request. See User identity.
baseUrl String Defaults to https://api.askocto.co. Change it only if support tells you to.
requestTimeoutSeconds Long How long a non-streaming request may take before it fails with OctoError.Network.

The SDK authenticates with the agent id. It does not use a workspace API key. Keys such as oc_live_ act on the whole workspace, so keep them on your server. See Authentication.

Methods

Method Returns Use it to
chat(text, conversationId) ChatResponse Send one message and wait for the full answer.
streamChat(text, conversationId) Flow of StreamEvent Receive the answer as it is written.
conversation(id) Conversation Load one conversation.
conversations(limit, cursor) Page of Conversation List conversations for the current user.
messages(conversationId, limit, cursor) Page of Message Load the messages of a conversation.
registerTool(tool) Unit Make a ClientTool available to the agent.
identify(identity) Unit Attach a verified UserIdentity.
clearIdentity() Unit Forget the user, for example on sign-out.
close() Unit Cancel running requests and release resources.

chat, conversation, conversations and messages are suspend functions. streamChat returns a cold Flow: nothing is sent until you collect it.

Threading

The client is safe to call from any coroutine. Network work runs on an IO dispatcher inside the SDK, so you can call it from the main thread's viewModelScope without blocking the UI. Cancelling the calling coroutine cancels the request.

Tip: Keep the client in a dependency injection scope or in your Application class. Creating a new client for every screen loses the registered tools and the identity.

Next steps

Send a message with Chat response, or register code the agent can call with Client side tools.

Something unclear or missing? Tell us and we will fix the page.