Share via


AssistantsPlanner class

A Planner that uses the OpenAI Assistants API to generate plans for the AI system.

Remarks

This planner manages conversations through OpenAI's thread-based system, handling:

  • Thread creation and management
  • Message submission
  • Tool/function calling
  • Response processing

Constructors

AssistantsPlanner<TState>(AssistantsPlannerOptions)

Creates a new AssistantsPlanner instance.

Methods

beginTask(TurnContext, TState, AI<TState>)

Starts a new task.

continueTask(TurnContext, TState, AI<TState>)

Continues the current task.

createAssistant(string, AssistantCreateParams, string, AzureClientOptions)

Creates a new assistant using the OpenAI Assistants API.

Constructor Details

AssistantsPlanner<TState>(AssistantsPlannerOptions)

Creates a new AssistantsPlanner instance.

new AssistantsPlanner(options: AssistantsPlannerOptions)

Parameters

options
AssistantsPlannerOptions

Options for configuring the AssistantsPlanner.

Method Details

beginTask(TurnContext, TState, AI<TState>)

Starts a new task.

function beginTask(context: TurnContext, state: TState, ai: AI<TState>): Promise<Plan>

Parameters

context

TurnContext

Context for the current turn of conversation.

state

TState

Application state for the current turn of conversation.

ai

AI<TState>

The AI system that is generating the plan.

Returns

Promise<Plan>

The plan that was generated.

Remarks

This method is called when the AI system is ready to start a new task. It delegates the task handling to the continueTask method. The planner should generate a plan that the AI system will execute. Returning an empty plan signals that there is no work to be performed.

The planner should take the users input from state.temp.input.

continueTask(TurnContext, TState, AI<TState>)

Continues the current task.

function continueTask(context: TurnContext, state: TState, ai: AI<TState>): Promise<Plan>

Parameters

context

TurnContext

Context for the current turn of conversation.

state

TState

Application state for the current turn of conversation.

ai

AI<TState>

The AI system that is generating the plan.

Returns

Promise<Plan>

The plan that was generated.

Remarks

This method is called when the AI system is ready to continue the current task. It handles:

  • Creating a new thread if one doesn't exist
  • Submitting tool outputs if required
  • Waiting for any in-progress runs to complete
  • Submitting user input and creating a new run The method generates a plan that the AI system will execute. Returning an empty plan signals that the task is completed and there is no work to be performed.

The output from the last plan step that was executed is passed to the planner via state.temp.input.

createAssistant(string, AssistantCreateParams, string, AzureClientOptions)

Creates a new assistant using the OpenAI Assistants API.

static function createAssistant(apiKey: string, request: AssistantCreateParams, endpoint?: string, azureClientOptions?: AzureClientOptions): Promise<Assistant>

Parameters

apiKey

string

OpenAI API key.

request

AssistantCreateParams

Definition of the assistant to create.

endpoint

string

Optional. The Azure OpenAI resource endpoint. Required when using Azure OpenAI.

azureClientOptions

AzureClientOptions

Optional. The Azure OpenAI client options.

Returns

Promise<Assistant>

The created assistant.