|
|
@ -76,6 +76,7 @@ class StructuredChatAgent(Agent):
|
|
|
|
human_message_template: str = HUMAN_MESSAGE_TEMPLATE,
|
|
|
|
human_message_template: str = HUMAN_MESSAGE_TEMPLATE,
|
|
|
|
format_instructions: str = FORMAT_INSTRUCTIONS,
|
|
|
|
format_instructions: str = FORMAT_INSTRUCTIONS,
|
|
|
|
input_variables: Optional[List[str]] = None,
|
|
|
|
input_variables: Optional[List[str]] = None,
|
|
|
|
|
|
|
|
memory_prompts: Optional[List[BasePromptTemplate]] = None,
|
|
|
|
) -> BasePromptTemplate:
|
|
|
|
) -> BasePromptTemplate:
|
|
|
|
tool_strings = []
|
|
|
|
tool_strings = []
|
|
|
|
for tool in tools:
|
|
|
|
for tool in tools:
|
|
|
@ -85,12 +86,14 @@ class StructuredChatAgent(Agent):
|
|
|
|
tool_names = ", ".join([tool.name for tool in tools])
|
|
|
|
tool_names = ", ".join([tool.name for tool in tools])
|
|
|
|
format_instructions = format_instructions.format(tool_names=tool_names)
|
|
|
|
format_instructions = format_instructions.format(tool_names=tool_names)
|
|
|
|
template = "\n\n".join([prefix, formatted_tools, format_instructions, suffix])
|
|
|
|
template = "\n\n".join([prefix, formatted_tools, format_instructions, suffix])
|
|
|
|
|
|
|
|
if input_variables is None:
|
|
|
|
|
|
|
|
input_variables = ["input", "agent_scratchpad"]
|
|
|
|
|
|
|
|
_memory_prompts = memory_prompts or []
|
|
|
|
messages = [
|
|
|
|
messages = [
|
|
|
|
SystemMessagePromptTemplate.from_template(template),
|
|
|
|
SystemMessagePromptTemplate.from_template(template),
|
|
|
|
|
|
|
|
*_memory_prompts,
|
|
|
|
HumanMessagePromptTemplate.from_template(human_message_template),
|
|
|
|
HumanMessagePromptTemplate.from_template(human_message_template),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
if input_variables is None:
|
|
|
|
|
|
|
|
input_variables = ["input", "agent_scratchpad"]
|
|
|
|
|
|
|
|
return ChatPromptTemplate(input_variables=input_variables, messages=messages)
|
|
|
|
return ChatPromptTemplate(input_variables=input_variables, messages=messages)
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
@ -105,6 +108,7 @@ class StructuredChatAgent(Agent):
|
|
|
|
human_message_template: str = HUMAN_MESSAGE_TEMPLATE,
|
|
|
|
human_message_template: str = HUMAN_MESSAGE_TEMPLATE,
|
|
|
|
format_instructions: str = FORMAT_INSTRUCTIONS,
|
|
|
|
format_instructions: str = FORMAT_INSTRUCTIONS,
|
|
|
|
input_variables: Optional[List[str]] = None,
|
|
|
|
input_variables: Optional[List[str]] = None,
|
|
|
|
|
|
|
|
memory_prompts: Optional[List[BasePromptTemplate]] = None,
|
|
|
|
**kwargs: Any,
|
|
|
|
**kwargs: Any,
|
|
|
|
) -> Agent:
|
|
|
|
) -> Agent:
|
|
|
|
"""Construct an agent from an LLM and tools."""
|
|
|
|
"""Construct an agent from an LLM and tools."""
|
|
|
@ -116,6 +120,7 @@ class StructuredChatAgent(Agent):
|
|
|
|
human_message_template=human_message_template,
|
|
|
|
human_message_template=human_message_template,
|
|
|
|
format_instructions=format_instructions,
|
|
|
|
format_instructions=format_instructions,
|
|
|
|
input_variables=input_variables,
|
|
|
|
input_variables=input_variables,
|
|
|
|
|
|
|
|
memory_prompts=memory_prompts,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
llm_chain = LLMChain(
|
|
|
|
llm_chain = LLMChain(
|
|
|
|
llm=llm,
|
|
|
|
llm=llm,
|
|
|
|