|
If you (like me) were wondering how these works, the LLM is given a prompt like: Answer the following questions as best you can. You have access to the following tools:
Search: Use this to search the internet.
Calculator: Use this to do math.
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Question: What is the age of the president of Egypt squared?
Thought:
To which the LLM will generate a completion like: Thought: I need to find the age of the president of Egypt.
Action: Search
Action Input: Age of president of Egypt
Observation:
At which point, the code (langchain, haystack, etc) will parse out the requested tool (Search) and input (Age of president of Egypt), and then call the right tool or API, then append the output of that action into the prompt.This all happens in a loop, at each step, the LLM is given the entire past prompt history, and given the opportunity to do a completion to choose the next tool and input to the next tool, after which the code parses those out, executes the tool, and repeats until the LLM decides it has the final answer and returns. |
https://github.com/cantino/browser-friend