@cloudbase/aiagent-framework
    Preparing search index...

    Class BotCore

    BotCore - 空白基类,实现了基本的初始化逻辑,配合 IBot 使用

    import { BotCore, IBot } from '@cloudbase/aiagent-framework'
    class Bot extends BotBase implements IBot {
    实现 IBot 定义的方法
    }
    Index

    Constructors

    • context - TCB 函数的上下文

      Parameters

      • context: TcbContext
      • Optionaloption: { chatRecordDataModelKey?: string }

      Returns BotCore

    Properties

    chatRecordDataModelKey: string
    context: TcbContext
    sseSender: BotCoreSseSender

    sseSender - 用于发送 Server-Sent Events

    tools: AITools

    Accessors

    • get botId(): string

      botId - botId

      Returns string

    • get botTag(): string

      botTag - botTag

      Returns string

    • get chatRecord(): ChatRecordDataModel

      Returns ChatRecordDataModel

    • get tcb(): CloudBase

      Returns CloudBase

    Methods

    • 创建一个 Agent 聊天记录

      Parameters

      • __namedParameters: { record: PickRequired<ChatRecord, "record_id"> }

      Returns ChatRecord

    • 创建一对 用户 - Agent 的聊天记录,并存到数据模型中。 返回值中提供更新 Agent 聊天记录的方法。

      Parameters

      • __namedParameters: { userContent: string }

      Returns Promise<
          {
              botRecord: ChatRecord;
              updateBotRecord: (
                  data: PickRequired<ChatRecord, "content">,
              ) => Promise<MethodResponse<UpdateResponse<ChatRecord>>>;
              userRecord: ChatRecord;
          },
      >

    • 创建一个用户聊天记录

      Parameters

      • __namedParameters: { record: PickRequired<ChatRecord, "content" | "reply"> }

      Returns ChatRecord

    • 获取聊天记录,并加以整理,保证:

      • 列表中,最旧的聊天记录在第一位,最新的在最后一位
      • 聊天记录以用户的消息开头
      • 用户的消息与 Agent 的消息交替出现
      • 默认情况下保证以 Agent 的消息结尾

      Parameters

      • Optionaloption: { removeLastUser?: boolean; size?: number }

      Returns Promise<
          (
              { content: string; role: "assistant"
              | "user" } & {
                  botId?: string;
                  content?: string;
                  conversation?: string;
                  createTime?: string;
                  image?: string;
                  recordId?: string;
                  reply?: string;
                  replyTo?: string;
                  role?: string;
                  triggerSrc?: string;
                  type?: string;
              }
          )[],
      >