mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
8dbbcf0b6c
**Description:** This template creates an agent that transforms a single LLM into a cognitive synergist by engaging in multi-turn self-collaboration with multiple personas. **Tag maintainer:** @hwchase17 --------- Co-authored-by: Sayandip Sarkar <sayandip.sarkar@skypointcloud.com> Co-authored-by: Erick Friis <erick@langchain.dev>
19 lines
813 B
Python
19 lines
813 B
Python
from langchain.schema import AgentAction, AgentFinish
|
|
|
|
|
|
def parse_output(message: str):
|
|
FINAL_ANSWER_ACTION = "<final_answer>"
|
|
includes_answer = FINAL_ANSWER_ACTION in message
|
|
if includes_answer:
|
|
answer = message.split(FINAL_ANSWER_ACTION)[1].strip()
|
|
if "</final_answer>" in answer:
|
|
answer = answer.split("</final_answer>")[0].strip()
|
|
return AgentFinish(return_values={"output": answer}, log=message)
|
|
elif "</tool>" in message:
|
|
tool, tool_input = message.split("</tool>")
|
|
_tool = tool.split("<tool>")[1]
|
|
_tool_input = tool_input.split("<tool_input>")[1]
|
|
if "</tool_input>" in _tool_input:
|
|
_tool_input = _tool_input.split("</tool_input>")[0]
|
|
return AgentAction(tool=_tool, tool_input=_tool_input, log=message)
|