Skip to main content

Class: Agent

agents.Agent

Class responsible for calling a language model and deciding an action.

Remarks

This is driven by an LLMChain. The prompt in the LLMChain must include a variable called "agent_scratchpad" where the agent can put its intermediary work.

Hierarchy

Constructors

constructor

new Agent(input)

Parameters

NameType
inputAgentInput

Overrides

BaseSingleActionAgent.constructor

Defined in

langchain/src/agents/agent.ts:170

Properties

llmChain

llmChain: LLMChain

Defined in

langchain/src/agents/agent.ts:158

Accessors

allowedTools

get allowedTools(): undefined | string[]

Returns

undefined | string[]

Overrides

BaseSingleActionAgent.allowedTools

Defined in

langchain/src/agents/agent.ts:162


inputKeys

get inputKeys(): string[]

Returns

string[]

Overrides

BaseSingleActionAgent.inputKeys

Defined in

langchain/src/agents/agent.ts:166


returnValues

get returnValues(): string[]

Returns

string[]

Inherited from

BaseSingleActionAgent.returnValues

Defined in

langchain/src/agents/agent.ts:31

Methods

_agentType

Abstract _agentType(): string

Return the string type key uniquely identifying this class of agent.

Returns

string

Overrides

BaseSingleActionAgent._agentType

Defined in

langchain/src/agents/agent.ts:198


_stop

_stop(): string[]

Returns

string[]

Defined in

langchain/src/agents/agent.ts:231


constructScratchPad

constructScratchPad(steps): string | BaseChatMessage[]

Construct a scratchpad to let the agent continue its thought process

Parameters

NameType
stepsAgentStep[]

Returns

string | BaseChatMessage[]

Defined in

langchain/src/agents/agent.ts:245


extractToolAndInput

extractToolAndInput(_input): Promise<null | { input: string ; tool: string }>

Extract tool and tool input from LLM output.

Parameters

NameType
_inputstring

Returns

Promise<null | { input: string ; tool: string }>

Defined in

langchain/src/agents/agent.ts:179


finishToolName

finishToolName(): string

Name of tool to use to terminate the chain.

Returns

string

Defined in

langchain/src/agents/agent.ts:238


llmPrefix

Abstract llmPrefix(): string

Prefix to append the LLM call with.

Returns

string

Defined in

langchain/src/agents/agent.ts:193


observationPrefix

Abstract observationPrefix(): string

Prefix to append the observation with.

Returns

string

Defined in

langchain/src/agents/agent.ts:188


plan

plan(steps, inputs): Promise<AgentAction | AgentFinish>

Decide what to do given some input.

Parameters

NameTypeDescription
stepsAgentStep[]Steps the LLM has taken so far, along with observations from each.
inputsChainValuesUser inputs.

Returns

Promise<AgentAction | AgentFinish>

Action specifying what tool to use.

Overrides

BaseSingleActionAgent.plan

Defined in

langchain/src/agents/agent.ts:297


prepareForOutput

prepareForOutput(_returnValues, _steps): Promise<Record<string, any>>

Prepare the agent for output, if needed

Parameters

NameType
_returnValuesRecord<string, any>
_stepsAgentStep[]

Returns

Promise<Record<string, any>>

Inherited from

BaseSingleActionAgent.prepareForOutput

Defined in

langchain/src/agents/agent.ts:67


returnStoppedResponse

returnStoppedResponse(earlyStoppingMethod, steps, inputs): Promise<AgentFinish>

Return response when agent has been stopped due to max iterations

Parameters

NameType
earlyStoppingMethodStoppingMethod
stepsAgentStep[]
inputsChainValues

Returns

Promise<AgentFinish>

Overrides

BaseSingleActionAgent.returnStoppedResponse

Defined in

langchain/src/agents/agent.ts:307


createPrompt

Static createPrompt(_tools, _fields?): BasePromptTemplate

Create a prompt for this class

Parameters

NameTypeDescription
_toolsTool[]List of tools the agent will have access to, used to format the prompt.
_fields?Record<string, any>Additional fields used to format the prompt.

Returns

BasePromptTemplate

A PromptTemplate assembled from the given tools and fields.

Defined in

langchain/src/agents/agent.ts:208


deserialize

Static deserialize(data): Promise<Agent>

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

Parameters

NameType
dataObject

Returns

Promise<Agent>

Defined in

langchain/src/agents/agent.ts:347


fromLLMAndTools

Static fromLLMAndTools(_llm, _tools, _args?): Agent

Construct an agent from an LLM and a list of tools

Parameters

NameType
_llmBaseLanguageModel
_toolsTool[]
_args?Record<string, any>

Returns

Agent

Defined in

langchain/src/agents/agent.ts:217


validateTools

Static validateTools(_tools): void

Validate that appropriate tools are passed in

Parameters

NameType
_toolsTool[]

Returns

void

Defined in

langchain/src/agents/agent.ts:229