Longbridge OpenAPI SDK
    Preparing search index...

    Class AgentContext

    AI Agent conversation context.

    Reference: https://open.longbridge.com/en/docs/ai/chat/conversation

    Index
    • List the Workspaces the current account belongs to.

      const { Config, AgentContext } = require('longbridge');

      const ctx = AgentContext.new(config);
      const resp = await ctx.workspaces();
      console.log(resp);

      Returns Promise<WorkspacesResponse>

    • List the Agents in the specified Workspace.

      page/limit control pagination; name fuzzy-searches by Agent name. All three are optional.

      const { Config, AgentContext } = require('longbridge');

      const ctx = AgentContext.new(config);
      const resp = await ctx.agents(workspaceId);
      console.log(resp);

      Parameters

      • workspaceId: string
      • Optionalpage: number | null
      • Optionallimit: number | null
      • Optionalname: string | null

      Returns Promise<AgentsResponse>

    • List all publicly available Agents on the platform (the Explore catalog). Not scoped to a Workspace.

      Parameters

      • Optionalpage: number | null
      • Optionallimit: number | null
      • Optionalname: string | null

      Returns Promise<AgentsResponse>

    • Start a conversation with the specified Agent, blocking until the run succeeds, is interrupted, or fails.

      parentMessageId is the messageId from a previous response. Pass it when asking a follow-up in an existing conversation to attach the new message after the specified one, keeping the message stream in order. It is only valid together with chatUid, the parent message must belong to that conversation, and it must not be set for a new conversation.

      const { Config, AgentContext } = require('longbridge');

      const ctx = AgentContext.new(config);
      const resp = await ctx.conversation(agentId, "How has Tesla stock performed recently?");
      console.log(resp);

      Parameters

      • agentId: string
      • query: string
      • OptionalchatUid: string | null
      • OptionalparentMessageId: string | null

      Returns Promise<ConversationResponse>

    • Resume an interrupted conversation, blocking until the run succeeds, is interrupted again, or fails.

      answersByToolCall is keyed by toolCallId (see Interrupt), each value being a map of question text to answer.

      Parameters

      • agentId: string
      • chatUid: string
      • messageId: string
      • answersByToolCall: Record<string, Record<string, string>>

      Returns Promise<ConversationResponse>

    • Start a conversation with the specified Agent, invoking callback for every progress event observed over SSE, and resolving to the final ConversationResponse once the run finishes (this is the same shape conversation returns).

      const { Config, AgentContext } = require('longbridge');

      const ctx = AgentContext.new(config);
      const resp = await ctx.conversationStreamed(
      agentId,
      "How has Tesla stock performed recently?",
      undefined,
      undefined,
      (err, event) => console.log(event),
      );
      console.log(resp);

      parentMessageId behaves as in conversation.

      Parameters

      • agentId: string
      • query: string
      • chatUid: string | null | undefined
      • parentMessageId: string | null | undefined
      • callback: (err: Error | null, event: ConversationStreamEvent) => void

      Returns Promise<ConversationResponse>

    • Resume an interrupted conversation, invoking callback for every progress event observed over SSE, and resolving to the final ConversationResponse once the run finishes.

      answersByToolCall is keyed by toolCallId (see Interrupt), each value being a map of question text to answer.

      Parameters

      • agentId: string
      • chatUid: string
      • messageId: string
      • answersByToolCall: Record<string, Record<string, string>>
      • callback: (err: Error | null, event: ConversationStreamEvent) => void

      Returns Promise<ConversationResponse>