Class OpenAIAgent

Class representing an agent for the OpenAI chat model in LangChain. It extends the Agent class and provides additional functionality specific to the OpenAIAgent type.

Hierarchy

Constructors

Properties

ToolType: StructuredTool<ZodObject<any, any, any, any, {}>>
llmChain: LLMChain<string, LLMType>
tools: StructuredTool<ZodObject<any, any, any, any, {}>>[]

Accessors

  • get allowedTools(): undefined | string[]
  • Returns undefined | string[]

  • get inputKeys(): string[]
  • Returns string[]

  • get returnValues(): string[]
  • Returns string[]

Methods

  • Constructs a scratch pad from a list of agent steps.

    Parameters

    • steps: AgentStep[]

      The steps to include in the scratch pad.

    Returns Promise<string | BaseMessage[]>

    A string or a list of BaseMessages representing the constructed scratch pad.

  • Name of tool to use to terminate the chain.

    Returns string

  • Prefix to append the LLM call with.

    Returns string

  • Prefix to append the observation with.

    Returns string

  • Plans the next action or finish state of the agent based on the provided steps, inputs, and optional callback manager.

    Parameters

    • steps: AgentStep[]

      The steps to consider in planning.

    • inputs: ChainValues

      The inputs to consider in planning.

    • Optional callbackManager: CallbackManager

      Optional CallbackManager to use in planning.

    Returns Promise<AgentAction | AgentFinish>

    A Promise that resolves to an AgentAction or AgentFinish object representing the planned action or finish state.

  • Prepare the agent for output, if needed

    Parameters

    • _returnValues: Record<string, any>
    • _steps: AgentStep[]

    Returns Promise<Record<string, any>>

  • Return response when agent has been stopped due to max iterations

    Parameters

    • earlyStoppingMethod: StoppingMethod
    • steps: AgentStep[]
    • inputs: ChainValues
    • Optional callbackManager: CallbackManager

    Returns Promise<AgentFinish>

  • Creates a prompt for the OpenAIAgent using the provided tools and fields.

    Parameters

    • _tools: StructuredTool<ZodObject<any, any, any, any, {}>>[]

      The tools to be used in the prompt.

    • Optional fields: OpenAIAgentCreatePromptArgs

      Optional fields for creating the prompt.

    Returns BasePromptTemplate<any, BasePromptValue, any>

    A BasePromptTemplate object representing the created prompt.

  • Load an agent from a json-like object describing it.

    Parameters

    • data: Object

    Returns Promise<Agent>

  • Creates an OpenAIAgent from a BaseLanguageModel and a list of tools.

    Parameters

    • llm: BaseLanguageModel<any, BaseLanguageModelCallOptions>

      The BaseLanguageModel to use.

    • tools: StructuredTool<ZodObject<any, any, any, any, {}>>[]

      The tools to be used by the agent.

    • Optional args: OpenAIAgentCreatePromptArgs & Pick<AgentArgs, "callbacks">

      Optional arguments for creating the agent.

    Returns OpenAIAgent

    An instance of OpenAIAgent.

  • Validate that appropriate tools are passed in

    Parameters

    • _tools: StructuredTool<ZodObject<any, any, any, any, {}>>[]

    Returns void

Generated using TypeDoc