Nhảy tới nội dung

Class: OpenAIAgentWorker

OpenAI agent worker. This class is responsible for running the agent.

Implements

Constructors

constructor

new OpenAIAgentWorker(«destructured»): OpenAIAgentWorker

Initialize.

Parameters

NameType
«destructured»OpenAIAgentWorkerParams

Returns

OpenAIAgentWorker

Defined in

packages/core/src/agent/openai/worker.ts:108

Properties

_getTools

Private _getTools: (input: string) => Promise<BaseTool[]>

Type declaration

▸ (input): Promise<BaseTool[]>

Parameters
NameType
inputstring
Returns

Promise<BaseTool[]>

Defined in

packages/core/src/agent/openai/worker.ts:103


callbackManager

callbackManager: undefined | CallbackManager

Defined in

packages/core/src/agent/openai/worker.ts:101


llm

Private llm: OpenAI

Defined in

packages/core/src/agent/openai/worker.ts:96


maxFunctionCalls

Private maxFunctionCalls: number

Defined in

packages/core/src/agent/openai/worker.ts:98


prefixMessages

prefixMessages: ChatMessage[]

Defined in

packages/core/src/agent/openai/worker.ts:100


verbose

Private verbose: boolean

Defined in

packages/core/src/agent/openai/worker.ts:97

Methods

_getAgentResponse

_getAgentResponse(task, mode, llmChatKwargs): Promise<AgentChatResponse | StreamingAgentChatResponse>

Get agent response.

Parameters

NameType
taskTask
modeChatResponseMode
llmChatKwargsany

Returns

Promise<AgentChatResponse | StreamingAgentChatResponse>

Defined in

packages/core/src/agent/openai/worker.ts:237


_getLlmChatKwargs

_getLlmChatKwargs(task, openaiTools, toolChoice?): Object

Parameters

NameTypeDefault value
taskTaskundefined
openaiTools{ [key: string]: any; }[]undefined
toolChoicestring | { [key: string]: any; }"auto"

Returns

Object

Defined in

packages/core/src/agent/openai/worker.ts:170


_getStreamAiResponse

_getStreamAiResponse(task, llmChatKwargs): Promise<StreamingAgentChatResponse>

Parameters

NameType
taskTask
llmChatKwargsany

Returns

Promise<StreamingAgentChatResponse>

Defined in

packages/core/src/agent/openai/worker.ts:203


_processMessage

_processMessage(task, chatResponse): AgentChatResponse

Process message.

Parameters

NameType
taskTask
chatResponseChatResponse

Returns

AgentChatResponse

Defined in

packages/core/src/agent/openai/worker.ts:193


_runStep

_runStep(step, task, mode?, toolChoice?): Promise<TaskStepOutput>

Parameters

NameTypeDefault value
stepTaskStepundefined
taskTaskundefined
modeChatResponseModeChatResponseMode.WAIT
toolChoicestring | { [key: string]: any; }"auto"

Returns

Promise<TaskStepOutput>

Defined in

packages/core/src/agent/openai/worker.ts:340


_shouldContinue

_shouldContinue(toolCalls, nFunctionCalls): boolean

Should continue.

Parameters

NameType
toolCallsnull | ChatCompletionMessageToolCall[]
nFunctionCallsnumber

Returns

boolean

Defined in

packages/core/src/agent/openai/worker.ts:316


callFunction

callFunction(tools, toolCall): Promise<CallFunctionOutput>

Call function.

Parameters

NameType
toolsBaseTool[]
toolCallChatCompletionMessageToolCall

Returns

Promise<CallFunctionOutput>

Defined in

packages/core/src/agent/openai/worker.ts:264


finalizeTask

finalizeTask(task, kwargs?): void

Finalize task.

Parameters

NameType
taskTask
kwargs?any

Returns

void

Implementation of

AgentWorker.finalizeTask

Defined in

packages/core/src/agent/openai/worker.ts:436


getAllMessages

getAllMessages(task): ChatMessage[]

Get all messages.

Parameters

NameType
taskTask

Returns

ChatMessage[]

Defined in

packages/core/src/agent/openai/worker.ts:140


getLatestToolCalls

getLatestToolCalls(task): null | ChatCompletionMessageToolCall[]

Get latest tool calls.

Parameters

NameType
taskTask

Returns

null | ChatCompletionMessageToolCall[]

Defined in

packages/core/src/agent/openai/worker.ts:153


getTools

getTools(input): Promise<BaseTool[]>

Get tools.

Parameters

NameType
inputstring

Returns

Promise<BaseTool[]>

Defined in

packages/core/src/agent/openai/worker.ts:336


initializeStep

initializeStep(task, kwargs?): TaskStep

Initialize step.

Parameters

NameType
taskTask
kwargs?any

Returns

TaskStep

Implementation of

AgentWorker.initializeStep

Defined in

packages/core/src/agent/openai/worker.ts:291


runStep

runStep(step, task, kwargs?): Promise<TaskStepOutput>

Run step.

Parameters

NameType
stepTaskStep
taskTask
kwargs?any

Returns

Promise<TaskStepOutput>

Implementation of

AgentWorker.runStep

Defined in

packages/core/src/agent/openai/worker.ts:405


streamStep

streamStep(step, task, kwargs?): Promise<TaskStepOutput>

Stream step.

Parameters

NameType
stepTaskStep
taskTask
kwargs?any

Returns

Promise<TaskStepOutput>

Implementation of

AgentWorker.streamStep

Defined in

packages/core/src/agent/openai/worker.ts:421