Skip to main content

Using the SDK

@octavus/server-sdk ships a workforce client for driving an agent with its per-agent key.

Install

bash

Set up the client

Construct OctavusClient with your agent's API key:

ts

Run a task and wait for the result

run() is the all-in-one method: it dispatches a message, polls until the run finishes, and returns the completed thread.

ts

The agent's latest turn is at the end of thread.messages.

Dispatch and poll manually

For more control, dispatch and read the thread yourself:

ts

waitForCompletion() does the polling loop for you until the thread is terminal:

ts

Follow up in the same thread

Continue a thread with another message. It runs after the current turn finishes.

ts

Options

run() and waitForCompletion() accept polling options. Full runs can take several minutes, so the defaults are generous.

OptionTypeDefaultDescription
pollIntervalMsnumber3000Delay between status checks
timeoutMsnumber900000Max time to wait before throwing (15 minutes)
signalAbortSignal-Cancel the wait early

dispatch(), followUp(), and run() also accept files (an array of FileReference) to attach hosted files to the message.

ts

If the timeout elapses first, waitForCompletion() and run() throw. The run keeps going on the server, so you can read it later with getThread().

Result shape

getThread(), waitForCompletion(), and run() return a thread:

FieldTypeDescription
threadIdstringThe thread identifier
statusstringidle, queued, pending, running, completed, failed, or cancelled
failureReasonstring | nullWhy the run failed, when status is failed
messagesUIMessage[]The conversation - text, tool and skill steps, and files (see UIMessage parts)

Use isTerminalThreadStatus(status) to check whether a run has finished.

The same operations are available as plain HTTP - see the API reference.