set up a conventional loop between assistant and tools
Browse files
app.py
CHANGED
|
@@ -65,7 +65,7 @@ class BasicAgent:
|
|
| 65 |
return final_answer, result["messages"]
|
| 66 |
|
| 67 |
def assistant(self, state: State):
|
| 68 |
-
|
| 69 |
textual_description_of_tool="""
|
| 70 |
search_tool(question: str, max_length: int = 1024) -> str:
|
| 71 |
Search info in the web.
|
|
@@ -86,11 +86,8 @@ class BasicAgent:
|
|
| 86 |
content=f"""You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 87 |
You can use provided tools:\n{textual_description_of_tool}"""
|
| 88 |
)
|
| 89 |
-
|
| 90 |
-
return
|
| 91 |
-
"messages": [self.model_with_tools.invoke([sys_msg] + state.get("messages", []))],
|
| 92 |
-
"question": state["question"]
|
| 93 |
-
}
|
| 94 |
|
| 95 |
def search_tool(self, question: str, max_length: int = 1024) -> str:
|
| 96 |
"""
|
|
|
|
| 65 |
return final_answer, result["messages"]
|
| 66 |
|
| 67 |
def assistant(self, state: State):
|
| 68 |
+
messages = state.get("messages", [])
|
| 69 |
textual_description_of_tool="""
|
| 70 |
search_tool(question: str, max_length: int = 1024) -> str:
|
| 71 |
Search info in the web.
|
|
|
|
| 86 |
content=f"""You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 87 |
You can use provided tools:\n{textual_description_of_tool}"""
|
| 88 |
)
|
| 89 |
+
new_message = self.model_with_tools.invoke([sys_msg] + messages)
|
| 90 |
+
return add_messages(state, [new_message])
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
def search_tool(self, question: str, max_length: int = 1024) -> str:
|
| 93 |
"""
|