iOS SDK quickstart

Add the Askocto Swift package to your app, create an OctoClient and send your first message to an agent in a few minutes.

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

This page takes you from an empty Xcode project to a working reply from your agent. You need the agent id of a published agent and an app that targets iOS 16 or later.

Add the package

  1. In Xcode, open File > Add Package Dependencies.

  2. Paste the package address into the search field.

    https://github.com/askocto/octo-ios
    
  3. Choose the latest version listed in the changelog.

  4. Add the Askocto library to your app target.

You should see Askocto under Package Dependencies in the project navigator. If you build with a Package.swift file, add the same address as a dependency and Askocto as a product of your target.

Create the client

Create one OctoClient for the whole app and reuse it. A property on your app's main type works well.

import Askocto

let octo = OctoClient(agentId: "agt_123")

To find the agent id, open the agent in the dashboard and go to Settings > General.

Send a message

chat is an async function, so call it from a Task or from another async function.

Task {
    do {
        let response = try await octo.chat(text: "Where is my order?")
        print(response.message.content)
    } catch let error as OctoError {
        print("Request failed: \(error.localizedDescription)")
    }
}

Run the app and trigger the call. You should see the agent's answer in the Xcode console. The response.conversationId value identifies the new conversation. Pass it to the next call to continue the same thread.

Try streaming

To show the answer as it is written, loop over streamChat.

for try await event in octo.streamChat(text: "What is your return policy?") {
    if case .messageDelta(let text) = event {
        print(text, terminator: "")
    }
}

Next steps

  • Read Client for every setting of OctoClient.
  • Handle the whole stream in Streaming.
  • Build a screen with SwiftUI.
  • Connect customers to their own history with User identity.
  • Check answers before your users see them with the Playground.

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