|
|
|
@ -71,36 +71,34 @@ class ConversationalChatAgent(Agent):
|
|
|
|
|
output_parser: Optional[BaseOutputParser] = None,
|
|
|
|
|
) -> BasePromptTemplate:
|
|
|
|
|
tool_strings = "\n".join(
|
|
|
|
|
[f"> {tool.name}: {tool.description}" for tool in tools]
|
|
|
|
|
)
|
|
|
|
|
[f"> {tool.name}: {tool.description}" for tool in tools])
|
|
|
|
|
tool_names = ", ".join([tool.name for tool in tools])
|
|
|
|
|
_output_parser = output_parser or cls._get_default_output_parser()
|
|
|
|
|
format_instructions = human_message.format(
|
|
|
|
|
format_instructions=_output_parser.get_format_instructions()
|
|
|
|
|
)
|
|
|
|
|
final_prompt = format_instructions.format(
|
|
|
|
|
tool_names=tool_names, tools=tool_strings
|
|
|
|
|
)
|
|
|
|
|
format_instructions=_output_parser.get_format_instructions())
|
|
|
|
|
final_prompt = format_instructions.format(tool_names=tool_names,
|
|
|
|
|
tools=tool_strings)
|
|
|
|
|
if input_variables is None:
|
|
|
|
|
input_variables = ["input", "chat_history", "agent_scratchpad"]
|
|
|
|
|
messages = [
|
|
|
|
|
SystemMessagePromptTemplate.from_template(system_message),
|
|
|
|
|
MessagesPlaceholder(variable_name="chat_history"),
|
|
|
|
|
HumanMessagePromptTemplate.from_template(final_prompt),
|
|
|
|
|
HumanMessagePromptTemplate.from_template(final_prompt,
|
|
|
|
|
alias="instructions_tools"),
|
|
|
|
|
MessagesPlaceholder(variable_name="agent_scratchpad"),
|
|
|
|
|
]
|
|
|
|
|
return ChatPromptTemplate(input_variables=input_variables, messages=messages)
|
|
|
|
|
return ChatPromptTemplate(input_variables=input_variables,
|
|
|
|
|
messages=messages)
|
|
|
|
|
|
|
|
|
|
def _construct_scratchpad(
|
|
|
|
|
self, intermediate_steps: List[Tuple[AgentAction, str]]
|
|
|
|
|
) -> List[BaseMessage]:
|
|
|
|
|
self, intermediate_steps: List[Tuple[AgentAction,
|
|
|
|
|
str]]) -> List[BaseMessage]:
|
|
|
|
|
"""Construct the scratchpad that lets the agent continue its thought process."""
|
|
|
|
|
thoughts: List[BaseMessage] = []
|
|
|
|
|
for action, observation in intermediate_steps:
|
|
|
|
|
thoughts.append(AIMessage(content=action.log))
|
|
|
|
|
human_message = HumanMessage(
|
|
|
|
|
content=TEMPLATE_TOOL_RESPONSE.format(observation=observation)
|
|
|
|
|
)
|
|
|
|
|
human_message = HumanMessage(content=TEMPLATE_TOOL_RESPONSE.format(
|
|
|
|
|
observation=observation))
|
|
|
|
|
thoughts.append(human_message)
|
|
|
|
|
return thoughts
|
|
|
|
|
|
|
|
|
|