Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Agent SDK

Run a Qore agent from your own TypeScript code, in Node or in the browser, with @uptiqai/agent-sdk.

The Agent SDK is a TypeScript package, @uptiqai/agent-sdk, for running Qore agents from your own code. The same package works in a Node backend and in the browser.

It calls an agent that already exists. You build the agent in the Agent Builder; the SDK starts runs, uploads documents, and reads conversations.

When you select TypeScript SDK as the Client on the agent's Agent API tab, the generated code sample uses this package. See Integrate Agent.

Which SDK is this?

SDK
Package
What it is for
Runs in

Agent SDK

@uptiqai/agent-sdk

Running an agent from your code: start runs, upload documents, read conversations

Node or browser

Widgets SDK

@uptiqai/widgets-sdk

Dropping a prebuilt chat interface into your web app

Browser

Headless Agent JS SDK

@uptiqai/widgets-sdk

Building your own chat UI, with sockets and events handled for you

Browser

The Widgets SDK and the Headless Agent JS SDK are documented on Integrate Agent.

Install

npm install @uptiqai/agent-sdk

Create a client

Create one AgentClient with your server URL and one set of credentials. baseUrl is required. The code sample on the Agent API tab fills it in.

For server-to-server calls. Keep the secret server-side.

import { AgentClient } from '@uptiqai/agent-sdk';

const client = new AgentClient({
    apiKey: process.env.AGENT_API_KEY!,
    apiSecret: process.env.AGENT_API_SECRET!,
    baseUrl: 'https://api.example.com'
});

Sent as the x-api-key and x-api-key-secret headers.

For the browser. A widget key works only from a whitelisted domain. Never ship the API secret to a browser.

const client = new AgentClient({ widgetKey: '...', baseUrl: 'https://api.example.com' });

Sent as the x-widget-key header.

To act as a logged-in user, pass their access token instead of a key. Requests then carry that user's own permissions, so an action a key could perform may still be denied. projectId is required.

// Node: the refresh token stays server-side.
const client = new AgentClient({
    accessToken,
    refreshToken,
    projectId: 'my-project',
    baseUrl: 'https://api.example.com',
    onTokenRefreshed: ({ accessToken }) => saveToken(accessToken)
});

// Browser: the host app owns the session. Never ship a refresh token.
const client = new AgentClient({
    accessToken: session.accessToken,
    getAccessToken: () => session.getFreshAccessToken(),
    projectId: 'my-project',
    baseUrl: 'https://api.example.com'
});

Access tokens expire after an hour. On a 401, the SDK gets a new token, from getAccessToken if you gave one and otherwise by using the refresh token, and retries the request once. Without either option, a rejected token raises AuthenticationError.

The socket does the same. If the connection is rejected because the token expired, the SDK refreshes the token and reconnects once. If the refresh fails, connect() rejects with AuthenticationError.

From a browser, the token's origin claim must match the page's origin, or the request is rejected.

Sent as Authorization: Bearer with a project-id header.

Other client options

Option
What it does

agentExecutorVersion

The agent executor version, for example '1.3'. Added to the request path.

authToken

The end user's identity-provider token, for an agent with caller authentication. See below.

timeout

Request timeout in milliseconds. Defaults to 60000.

defaultHeaders

Extra headers added to every request.

transport

'rest' (the default) or 'socket'. 'socket' also opens the shared socket when the client is created. The REST methods work in both.

Authenticate the end user to the agent

For an agent with caller authentication turned on, pass the end user's identity-provider token, such as a Microsoft Entra, Google or Okta access token, as authToken. It's sent with every run and socket message. The agent verifies it and passes it to its MCP connections as $auth.token. Agents without authentication ignore it.

authToken is separate from accessToken, which signs the SDK in to the platform. The token is fixed for the client's lifetime, so create one client per user, and a new one when the token is refreshed.

Upload documents

If you already have a signed URL, skip the upload and pass it to run:

Run an agent

Waits for the agent and returns its result.

Returns at once. The result is sent to your webhooks.

webhooks is a list of { url, metadata? }. The platform POSTs the execution result to each url and echoes your metadata back in the payload.

Streams each conversation element as the agent produces it.

session.run() also returns when any agent in the conversation asks a question or a permission, such as an agent the Operator delegated to. It doesn't wait for that agent to finish. Read the request's metadata.elicitationRequestId and answer it with respondToElicitation.

Documents can be passed as the refs from documents.upload(), as { signedUrl }, or as { documentId }.

On agent executor 1.4 and later, run also returns a conversationId. It identifies the whole thread: the main execution plus one per sub-agent. Pass it to conversations.getConversation to read the thread, or to client.socket.createSession({ agentId, conversationId, executionId }) to stream a run you started in async mode.

Run options

Pass options to agents.run() or session.run() to set how one run behaves. Every field is optional, and none of them changes the agent's saved setup.

Option
What it sets

mode

The run mode: advanced, balanced, qa, custom or flash.

effort

The reasoning effort: minimal, low, medium or high.

interactionMode

copilot, or auto. With auto the agent doesn't ask questions.

maxReplans

The most times the agent may replan.

runInlineEvaluation

Whether to run an evaluation inline with the run.

modelName

The model to use for the run.

planningModelId, executionModelId

The planning and execution models.

planningModelConfig, executionModelConfig

Sampling settings for those models.

strategyConfig

Strategy settings, as an object.

runWithA2A and poolAgentIds are top-level fields of run, not options. See Run sub-agents over A2A and choose the agent pool.

Cancel a queued message

Messages sent to one execution are processed in order. To cancel one that is still pending, pass its messageId:

If the message isn't pending, because it is already running or isn't in the queue, the call throws NotFoundError.

Verify a webhook

Each webhook carries an X-Webhook-Signature header: a hex-encoded RSA-SHA256 signature of the raw body. verifyWebhookSignature checks it against the public key shown on the agent's Agent API tab, and throws WebhookVerificationError when it doesn't match. Verify against the raw body bytes, because parsing and re-serializing the JSON can change the signature.

Read conversations

On agent executor 1.4 and later, pass conversationId. Earlier executor versions address the thread by executionId.

Errors

Every failure is a typed subclass of AgentSDKError: AuthenticationError, NotFoundError, RateLimitError, BadRequestError, InternalServerError or APIConnectionError. Each carries .status, .headers and .body. verifyWebhookSignature throws WebhookVerificationError.

  • Integrate Agent: API keys, widget keys, whitelisted domains, and the generated code samples.

  • Custom skills: adding your own skill to an agent.

Last updated

Was this helpful?