Sborole commited on
Commit
d5e4541
·
verified ·
1 Parent(s): 5a08257

Update tools/FinalAnswerTool.py

Browse files
Files changed (1) hide show
  1. tools/FinalAnswerTool.py +56 -17
tools/FinalAnswerTool.py CHANGED
@@ -11,24 +11,63 @@ print(settings.llm_model_id)
11
  class FinalAnswerTool(Tool):
12
  name = "final_answer"
13
  description = """
14
- Takes the agent's computed result and formats the final answer.
15
-
16
- If the question asks for time rounded to the nearest *thousand hours*,
17
- you MUST:
18
-
19
- 1. First compute total time in hours.
20
- 2. THEN divide by FINAL ANSWER BY 1000 to convert to 'thousands of hours'.
21
- 3. Round that result to the nearest integer.
22
- 4. Output ONLY that integer (e.g., 17),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- Always output a clean string with ONLY the final answer.
25
- STRICT RULES:
26
- - Do NOT use Markdown formatting.
27
- - Do NOT use bold formatting.
28
- - Do NOT surround the answer with **asterisks**.
29
- - Do NOT add explanations, units, or extra words.
30
- - If the answer is a number, output ONLY the number (e.g., 17000).
31
- - Output must be plain ASCII text, no special symbols.
32
  """
33
  inputs = {
34
  "answer": {"type": "string", "description": "The final, correctly formatted answer string."}
 
11
  class FinalAnswerTool(Tool):
12
  name = "final_answer"
13
  description = """
14
+ This tool receives the agents computed result and MUST always be called
15
+ to produce the final answer output — even if the agent is at max steps or
16
+ the plan is incomplete.
17
+
18
+ The Final Answer Tool is the ONLY place where the final answer may be
19
+ emitted. The agent must not output answers directly.
20
+
21
+ GENERAL RULES
22
+ -------------
23
+ - ALWAYS call this tool before finishing.
24
+ - Output ONLY the final answer.
25
+ - NO explanations.
26
+ - NO reasoning.
27
+ - NO markdown.
28
+ - NO bold.
29
+ - NO asterisks (** **).
30
+ - NO labels (“Answer:”, “Final answer:”).
31
+ - NO surrounding text.
32
+ - Output must be plain ASCII text with no special symbols.
33
+
34
+ ROUNDING RULES
35
+ --------------
36
+ If the question requests:
37
+ - A simple numeric answer → output that number (e.g., `3`)
38
+ - Rounding → apply the rounding, then output ONLY the rounded value
39
+ - “Thousands of hours” → follow this exact sequence:
40
+
41
+ 1. Compute total time in hours.
42
+ 2. Divide by 1000 to convert to “thousands of hours”.
43
+ 3. Round to the nearest integer.
44
+ 4. Output ONLY that integer (example: `17`).
45
+
46
+ FORMAT CLEANING
47
+ ---------------
48
+ Before returning the answer:
49
+ - Remove all markdown (e.g., ** **)
50
+ - Remove LaTeX symbols ($, \, { })
51
+ - If `boxed{...}` appears → extract the content inside
52
+ - Keep only digits, letters, decimal points, hyphens, slashes,
53
+ commas, and spaces
54
+ - Collapse multiple spaces into a single space
55
+
56
+ MANDATORY INVOCATION
57
+ --------------------
58
+ The agent MUST call this tool to produce the final answer output,
59
+ regardless of:
60
+ - how many steps are taken,
61
+ - whether max_steps is reached,
62
+ - whether computation is partial or complete.
63
+
64
+ FAILSAFE
65
+ --------
66
+ If the provided answer is empty, malformed, or cannot be cleaned,
67
+ output exactly:
68
+ "I am unable to answer"
69
+ and nothing else.
70
 
 
 
 
 
 
 
 
 
71
  """
72
  inputs = {
73
  "answer": {"type": "string", "description": "The final, correctly formatted answer string."}