Class LLMSingleActionAgent

Class representing a single action agent using a LLMChain in LangChain. Extends the BaseSingleActionAgent class and provides methods for planning agent actions based on LLMChain outputs.

Example

const customPromptTemplate = new CustomPromptTemplate({
tools: [new Calculator()],
inputVariables: ["input", "agent_scratchpad"],
});
const customOutputParser = new CustomOutputParser();
const agent = new LLMSingleActionAgent({
llmChain: new LLMChain({
prompt: customPromptTemplate,
llm: new ChatOpenAI({ temperature: 0 }),
}),
outputParser: customOutputParser,
stop: ["\nObservation"],
});
const executor = new AgentExecutor({
agent,
tools: [new Calculator()],
});
const result = await executor.invoke({
input:
"Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?",
});

Hierarchy

Constructors

Properties

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

Accessors

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

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

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

Methods

  • Decide what to do given some input.

    Parameters

    • steps: AgentStep[]

      Steps the LLM has taken so far, along with observations from each.

    • inputs: ChainValues

      User inputs.

    • Optional callbackManager: CallbackManager

      Callback manager.

    Returns Promise<AgentAction | AgentFinish>

    Action specifying what tool to use.

  • 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>

Generated using TypeDoc