cjb97 commited on
Commit
ea40075
·
1 Parent(s): 35c3a86

Fix prompts.yaml and add FinalAnswerTool implementation for smolagents 1.9.2

Browse files
Files changed (3) hide show
  1. prompts.yaml +11 -3
  2. tools/__init__.py +5 -0
  3. tools/final_answer.py +10 -13
prompts.yaml CHANGED
@@ -6,16 +6,24 @@ system: |
6
  When you want to use a tool, output a code block with the tool name and arguments.
7
  For example:
8
  ```python
9
- get_current_time_in_timezone(timezone="America/New_York")
 
 
 
 
10
  ```
11
 
12
  After using a tool, you'll receive the result. Analyze the result and decide if you need to use more tools or if you can provide a final answer.
13
- When you have a final answer, use the final_answer tool.
 
 
 
14
 
15
  Remember to:
16
  1. Think step by step
17
  2. Use tools when appropriate
18
  3. Provide helpful, accurate, and concise responses
 
19
 
20
  user: |
21
  {{query}}
@@ -24,4 +32,4 @@ tool_response: |
24
  The result of your tool call was:
25
  {{observation}}
26
 
27
- What would you like to do next?
 
6
  When you want to use a tool, output a code block with the tool name and arguments.
7
  For example:
8
  ```python
9
+ get_weather(location="New York")
10
+ ```
11
+ or
12
+ ```python
13
+ duck_duck_go_search(query="latest news about artificial intelligence")
14
  ```
15
 
16
  After using a tool, you'll receive the result. Analyze the result and decide if you need to use more tools or if you can provide a final answer.
17
+ When you have a final answer, use the final_answer tool like this:
18
+ ```python
19
+ final_answer("Your detailed response here")
20
+ ```
21
 
22
  Remember to:
23
  1. Think step by step
24
  2. Use tools when appropriate
25
  3. Provide helpful, accurate, and concise responses
26
+ 4. Always use the final_answer tool when you're ready to give your final response
27
 
28
  user: |
29
  {{query}}
 
32
  The result of your tool call was:
33
  {{observation}}
34
 
35
+ What would you like to do next? You can use another tool or provide a final answer.
tools/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ """Tools for the agent."""
2
+
3
+ from .final_answer import FinalAnswerTool
4
+
5
+ __all__ = ["FinalAnswerTool"]
tools/final_answer.py CHANGED
@@ -1,10 +1,15 @@
1
- from typing import Optional
 
2
 
3
- class FinalAnswerTool:
4
- """A tool that allows the agent to provide a final answer to the user's query."""
 
 
 
5
 
6
  def __call__(self, answer: str) -> str:
7
- """Provide a final answer to the user's query.
 
8
 
9
  Args:
10
  answer: The final answer to provide to the user.
@@ -12,19 +17,11 @@ class FinalAnswerTool:
12
  Returns:
13
  A confirmation message.
14
  """
15
- return f"FINAL ANSWER: {answer}"
16
 
17
  def __str__(self) -> str:
18
  return "final_answer"
19
 
20
- @property
21
- def name(self) -> str:
22
- return "final_answer"
23
-
24
- @property
25
- def description(self) -> str:
26
- return "Use this tool to provide a final answer to the user's query."
27
-
28
  @property
29
  def signature(self) -> str:
30
  return "final_answer(answer: str) -> str"
 
1
+ from smolagents.tools import Tool
2
+ from typing import Any, Optional
3
 
4
+ class FinalAnswerTool(Tool):
5
+ """Tool for providing a final answer to the user's query."""
6
+
7
+ name = "final_answer"
8
+ description = "Use this tool to provide your final answer to the user's question."
9
 
10
  def __call__(self, answer: str) -> str:
11
+ """
12
+ Provide a final answer to the user's query.
13
 
14
  Args:
15
  answer: The final answer to provide to the user.
 
17
  Returns:
18
  A confirmation message.
19
  """
20
+ return answer
21
 
22
  def __str__(self) -> str:
23
  return "final_answer"
24
 
 
 
 
 
 
 
 
 
25
  @property
26
  def signature(self) -> str:
27
  return "final_answer(answer: str) -> str"