from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
template = """You are a helpful assistant. Help the user answer any questions.
You have access to the following tools:
{tools}
In order to use a tool, you can use  and  tags. You will then get back a response in the form 
For example, if you have a tool called 'search' that could run a google search, in order to search for the weather in SF you would respond:
searchweather in SF
64 degrees
When you are done, you can respond as normal to the user.
Example 1:
Human: Hi!
Assistant: Hi! How are you?
Human: What is the weather in SF?
Assistant: searchweather in SF
64 degrees
It is 64 degress in SF
Begin!"""  # noqa: E501
conversational_prompt = ChatPromptTemplate.from_messages(
    [
        ("system", template),
        MessagesPlaceholder(variable_name="chat_history"),
        ("user", "{question}"),
        ("ai", "{agent_scratchpad}"),
    ]
)
def parse_output(message):
    text = message.content
    if "" in text:
        tool, tool_input = text.split("")
        _tool = tool.split("")[1]
        _tool_input = tool_input.split("")[1]
        if "" in _tool_input:
            _tool_input = _tool_input.split("")[0]
        return AgentAction(tool=_tool, tool_input=_tool_input, log=text)
    else:
        return AgentFinish(return_values={"output": text}, log=text)