Skip to main content

Multi-session

Agent allows users to have multiple mutually independent sessions, and the contexts between different sessions do not interfere with each other.

Enabling Multi-session

In the Cloud Development Platform AI+, select the Cloud Development Agent template, and in bot-config.yaml, enable multiConversationEnable: true.

Precautions

Cloud Development Standard Edition or higher is required to enable this feature.

Creating an Agent

Enabling Multi-session

Experience

After enabling multi-session, you can try it out in the preview area on the right.

New Session:

New Session

Session History:

Session History

Integration

Users can integrate the multi-session feature through Agent UI components, SDK, HTTP API, and other methods.

Agent UI

Visual low-code components, Mini Program source code components, and React components all have built-in multi-session capabilities. For specific usage, please refer to the relevant documentation.

SDK Integration

Initialize the SDK:

// In the root directory of the Web project, use npm or yarn to install the required packages:
// npm i @cloudbase/js-sdk

// Import the SDK. Here we import the full clousebase-js-sdk, and it also supports importing by modules.
import cloudbase from "@cloudbase/js-sdk";

const app = cloudbase.init({
env: env: "your-env", // Replace with the actual environment id
});
const auth = app.auth();
await auth.signInAnonymously(); // Or use other login methods.
const ai = app.ai();
// Now you can call the methods provided by the ai module.

New Session:

const res = await ai.bot.createConversation({
botId: "botId-xxx",
title: title: "Conversation Title",
});

When sending a message, include the session ID:

const res = await ai.bot.sendMessage({
botId: "botId-xxx",
history: history: [{ content: "Hello", role: "user" }],
msg: msg: "Hello",
conversationId: "conversation-001",
});

When querying message records, include the session ID:

await ai.bot.getChatRecords({
botId: "botId-xxx",
pageNumber: 1,
pageSize: 10,
sort: "asc",
conversationId: "conversation-001",
});

Obtain session list:

const res = await ai.bot.getConversation({
botId: "botId-xxx",
pageSize: 10,
pageNumber: 1,
});

Delete Session:

await ai.bot.deleteConversation({
botId: "botId-xxx",
conversationId: "conversation-001",
});

For details, refer to AI SDK Documentation

HTTP API Integration

Refer to HTTP API Documentation