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:153
Properties
llmChain
• llmChain: LLMChain
Defined in
langchain/src/agents/agent.ts:141
Accessors
allowedTools
• get
allowedTools(): undefined
| string
[]
Returns
undefined
| string
[]
Overrides
BaseSingleActionAgent.allowedTools
Defined in
langchain/src/agents/agent.ts:145
inputKeys
• get
inputKeys(): string
[]
Returns
string
[]
Overrides
BaseSingleActionAgent.inputKeys
Defined in
langchain/src/agents/agent.ts:149
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:181
_stop
▸ _stop(): string
[]
Returns
string
[]
Defined in
langchain/src/agents/agent.ts:214
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:228
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:162
finishToolName
▸ finishToolName(): string
Name of tool to use to terminate the chain.
Returns
string
Defined in
langchain/src/agents/agent.ts:221
llmPrefix
▸ Abstract
llmPrefix(): string
Prefix to append the LLM call with.
Returns
string
Defined in
langchain/src/agents/agent.ts:176
observationPrefix
▸ Abstract
observationPrefix(): string
Prefix to append the observation with.
Returns
string
Defined in
langchain/src/agents/agent.ts:171
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:280
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:80
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:290
createPrompt
▸ Static
createPrompt(_tools
, _fields?
): BasePromptTemplate
Create a prompt for this class
Parameters
Name | Type |
---|---|
_tools | Tool [] |
_fields? | Record <string , any > |
Returns
A PromptTemplate assembled from the given tools and fields.
Defined in
langchain/src/agents/agent.ts:191
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:328
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:200
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:212