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
| Name | Type |
|---|---|
input | AgentInput |
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
| Name | Type |
|---|---|
steps | AgentStep[] |
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
| Name | Type |
|---|---|
_input | string |
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
| Name | Type | Description |
|---|---|---|
steps | AgentStep[] | Steps the LLM has taken so far, along with observations from each. |
inputs | ChainValues | User inputs. |
Returns
Promise<AgentAction | AgentFinish>
Action specifying what tool to use.
Overrides
Defined in
langchain/src/agents/agent.ts:297
prepareForOutput
▸ prepareForOutput(_returnValues, _steps): Promise<Record<string, any>>
Prepare the agent for output, if needed
Parameters
| Name | Type |
|---|---|
_returnValues | Record<string, any> |
_steps | AgentStep[] |
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
| Name | Type |
|---|---|
earlyStoppingMethod | StoppingMethod |
steps | AgentStep[] |
inputs | ChainValues |
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
| Name | Type | Description |
|---|---|---|
_tools | Tool[] | 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
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
| Name | Type |
|---|---|
data | Object |
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
| Name | Type |
|---|---|
_llm | BaseLanguageModel |
_tools | Tool[] |
_args? | Record<string, any> |
Returns
Defined in
langchain/src/agents/agent.ts:217
validateTools
▸ Static validateTools(_tools): void
Validate that appropriate tools are passed in
Parameters
| Name | Type |
|---|---|
_tools | Tool[] |
Returns
void
Defined in
langchain/src/agents/agent.ts:229