Spaces:
Sleeping
Sleeping
Update tools/FinalAnswerTool.py
Browse files- tools/FinalAnswerTool.py +60 -57
tools/FinalAnswerTool.py
CHANGED
|
@@ -11,64 +11,67 @@ print(settings.llm_model_id)
|
|
| 11 |
class FinalAnswerTool(Tool):
|
| 12 |
name = "final_answer"
|
| 13 |
description = """
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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."}
|
| 74 |
}
|
|
|
|
| 11 |
class FinalAnswerTool(Tool):
|
| 12 |
name = "final_answer"
|
| 13 |
description = """
|
| 14 |
+
SYSTEM INSTRUCTIONS FOR THE AGENT
|
| 15 |
+
=================================
|
| 16 |
+
You are a reasoning agent that must solve each question using tools.
|
| 17 |
+
You MUST follow this order of preference for information gathering:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
1. ALWAYS use SerpApiSearchTool first for factual data.
|
| 20 |
+
2. If more detail is needed, THEN use Wikipedia tools (wiki_titles → wiki_page).
|
| 21 |
+
3. Use Python tools or math tools for calculations.
|
| 22 |
+
4. You MUST ALWAYS call final_answer AS THE LAST TOOL CALL.
|
| 23 |
+
|
| 24 |
+
You may NOT return a final answer directly in text. The final answer
|
| 25 |
+
MUST come through the final_answer tool.
|
| 26 |
+
|
| 27 |
+
------------------------------------------------------
|
| 28 |
+
RULES FOR FINAL ANSWERS
|
| 29 |
+
------------------------------------------------------
|
| 30 |
+
The final answer MUST be produced ONLY by calling final_answer.
|
| 31 |
+
The agent MUST NOT output explanations after final_answer.
|
| 32 |
+
|
| 33 |
+
For numerical questions:
|
| 34 |
+
- If the question requires a single numeric answer → compute it and
|
| 35 |
+
pass the numeric string to final_answer.
|
| 36 |
+
- If rounding is required → apply the rounding before sending to
|
| 37 |
+
final_answer.
|
| 38 |
+
- If the question asks for "thousands of hours":
|
| 39 |
+
STEP 1: Compute total time in hours.
|
| 40 |
+
STEP 2: Divide by 1000 to convert to "thousands of hours".
|
| 41 |
+
STEP 3: Round to the nearest integer.
|
| 42 |
+
STEP 4: Send ONLY that integer to final_answer.
|
| 43 |
+
|
| 44 |
+
------------------------------------------------------
|
| 45 |
+
WHEN MAX STEPS ARE REACHED
|
| 46 |
+
------------------------------------------------------
|
| 47 |
+
Even if reasoning is incomplete, the LAST step MUST ALWAYS be a
|
| 48 |
+
final_answer tool call using the best available computed value.
|
| 49 |
+
Never end the run without calling final_answer.
|
| 50 |
+
|
| 51 |
+
FAILSAFE
|
| 52 |
+
--------
|
| 53 |
+
If input is empty or unusable → output:
|
| 54 |
+
I am unable to answer
|
| 55 |
+
|
| 56 |
+
------------------------------------------------------
|
| 57 |
+
PROHIBITIONS
|
| 58 |
+
------------------------------------------------------
|
| 59 |
+
- No markdown.
|
| 60 |
+
- No bold text.
|
| 61 |
+
- No asterisks.
|
| 62 |
+
- No units unless required.
|
| 63 |
+
- No surrounding text.
|
| 64 |
+
- No explanations after final_answer.
|
| 65 |
+
- No answering directly without using final_answer.
|
| 66 |
+
|
| 67 |
+
FORMAT CLEANING
|
| 68 |
+
---------------
|
| 69 |
+
- Remove markdown symbols.
|
| 70 |
+
- Remove LaTeX ($, \, { }).
|
| 71 |
+
- If boxed{...} appears, extract content inside.
|
| 72 |
+
- Keep digits, letters, decimal points, hyphens, slashes, commas, spaces.
|
| 73 |
+
- Collapse extra whitespace.
|
| 74 |
+
"""
|
| 75 |
inputs = {
|
| 76 |
"answer": {"type": "string", "description": "The final, correctly formatted answer string."}
|
| 77 |
}
|