mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 14:18:52 +00:00
parent
03c7140228
commit
0568998166
@ -87,6 +87,9 @@ class Agent(Chain, BaseModel, ABC):
|
|||||||
"""Create a prompt for this class."""
|
"""Create a prompt for this class."""
|
||||||
return cls.prompt
|
return cls.prompt
|
||||||
|
|
||||||
|
def _prepare_for_new_call(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_llm_and_tools(cls, llm: LLM, tools: List[Tool], **kwargs: Any) -> "Agent":
|
def from_llm_and_tools(cls, llm: LLM, tools: List[Tool], **kwargs: Any) -> "Agent":
|
||||||
"""Construct an agent from an LLM and tools."""
|
"""Construct an agent from an LLM and tools."""
|
||||||
@ -119,6 +122,8 @@ class Agent(Chain, BaseModel, ABC):
|
|||||||
def _call(self, inputs: Dict[str, str]) -> Dict[str, str]:
|
def _call(self, inputs: Dict[str, str]) -> Dict[str, str]:
|
||||||
"""Run text through and get agent response."""
|
"""Run text through and get agent response."""
|
||||||
text = inputs[self.input_key]
|
text = inputs[self.input_key]
|
||||||
|
# Do any preparation necessary when receiving a new input.
|
||||||
|
self._prepare_for_new_call()
|
||||||
# Construct a mapping of tool name to tool for easy lookup
|
# Construct a mapping of tool name to tool for easy lookup
|
||||||
name_to_tool_map = {tool.name: tool.func for tool in self.tools}
|
name_to_tool_map = {tool.name: tool.func for tool in self.tools}
|
||||||
# Construct the initial string to pass into the LLM. This is made up
|
# Construct the initial string to pass into the LLM. This is made up
|
||||||
|
@ -31,6 +31,9 @@ class ReActDocstoreAgent(Agent, BaseModel):
|
|||||||
f"Tool names should be Lookup and Search, got {tool_names}"
|
f"Tool names should be Lookup and Search, got {tool_names}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _prepare_for_new_call(self) -> None:
|
||||||
|
self.i = 1
|
||||||
|
|
||||||
def _fix_text(self, text: str) -> str:
|
def _fix_text(self, text: str) -> str:
|
||||||
return text + f"\nAction {self.i}:"
|
return text + f"\nAction {self.i}:"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user