Package com.hw.langchain.agents.agent
Class Agent
java.lang.Object
com.hw.langchain.agents.agent.BaseSingleActionAgent
com.hw.langchain.agents.agent.Agent
- Direct Known Subclasses:
ChatAgent
,ZeroShotAgent
Class responsible for calling the language model and deciding the action.
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.
- Author:
- HamaWhite
-
Constructor Summary
ConstructorDescriptionAgent
(LLMChain llmChain, List<String> allowedTools, AgentOutputParser outputParser) -
Method Summary
Modifier and TypeMethodDescriptionconstructScratchpad
(List<org.apache.commons.lang3.tuple.Pair<AgentAction, String>> intermediateSteps) Construct the scratchpad that lets the agent continue its thought process.static BaseSingleActionAgent
fromLLMAndTools
(BaseLanguageModel llm, List<BaseTool> tools, Map<String, Object> kwargs) getFullInputs
(List<org.apache.commons.lang3.tuple.Pair<AgentAction, String>> intermediateSteps, Map<String, Object> kwargs) Create the full inputs for the LLMChain from intermediate steps.Return the input keys.abstract String
Prefix to append the LLM call with.abstract String
Prefix to append the observation with.plan
(List<org.apache.commons.lang3.tuple.Pair<AgentAction, String>> intermediateSteps, Map<String, Object> kwargs) Given input, decided what to do.returnStoppedResponse
(String earlyStoppingMethod, List<org.apache.commons.lang3.tuple.Pair<AgentAction, String>> intermediateSteps, Map<String, ?> kwargs) Return response when agent has been stopped due to max iterations.stop()
static void
validateTools
(List<BaseTool> tools) Validate that appropriate tools are passed in.Methods inherited from class com.hw.langchain.agents.agent.BaseSingleActionAgent
returnValues
-
Constructor Details
-
Agent
-
-
Method Details
-
stop
-
constructScratchpad
public Object constructScratchpad(List<org.apache.commons.lang3.tuple.Pair<AgentAction, String>> intermediateSteps) Construct the scratchpad that lets the agent continue its thought process.- Parameters:
intermediateSteps
- Steps the LLM has taken to date, along with observations- Returns:
- String or List[BaseMessage]
-
validateTools
Validate that appropriate tools are passed in. -
inputKeys
Description copied from class:BaseSingleActionAgent
Return the input keys.- Specified by:
inputKeys
in classBaseSingleActionAgent
-
observationPrefix
Prefix to append the observation with. -
llmPrefix
Prefix to append the LLM call with. -
plan
public AgentResult plan(List<org.apache.commons.lang3.tuple.Pair<AgentAction, String>> intermediateSteps, Map<String, Object> kwargs) Description copied from class:BaseSingleActionAgent
Given input, decided what to do.- Specified by:
plan
in classBaseSingleActionAgent
- Parameters:
intermediateSteps
- Steps the LLM has taken to date, along with observationskwargs
- User inputs.- Returns:
- Action specifying what tool to use.
-
getFullInputs
public Map<String,Object> getFullInputs(List<org.apache.commons.lang3.tuple.Pair<AgentAction, String>> intermediateSteps, Map<String, Object> kwargs) Create the full inputs for the LLMChain from intermediate steps. -
fromLLMAndTools
public static BaseSingleActionAgent fromLLMAndTools(BaseLanguageModel llm, List<BaseTool> tools, Map<String, Object> kwargs) -
returnStoppedResponse
public AgentFinish returnStoppedResponse(String earlyStoppingMethod, List<org.apache.commons.lang3.tuple.Pair<AgentAction, String>> intermediateSteps, Map<String, ?> kwargs) Description copied from class:BaseSingleActionAgent
Return response when agent has been stopped due to max iterations.- Overrides:
returnStoppedResponse
in classBaseSingleActionAgent
-
toolRunLoggingKwargs
- Overrides:
toolRunLoggingKwargs
in classBaseSingleActionAgent
-