Spaces:
Running
Running
Update agent.py
Browse files
agent.py
CHANGED
@@ -646,14 +646,13 @@ def task_classifier(question: str) -> str:
|
|
646 |
|
647 |
return "default"
|
648 |
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
# Step 1: Use task_classifier to identify the intent of the question
|
654 |
intent = task_classifier(question)
|
655 |
|
656 |
-
#
|
657 |
intent_tool_map = {
|
658 |
"math": "calculator",
|
659 |
"wiki_search": "wiki_tool",
|
@@ -661,35 +660,31 @@ def select_tool_and_run(question: str, tools: list) -> any:
|
|
661 |
"arxiv": "arxiv_tool",
|
662 |
"get_youtube_transcript": "youtube_tool",
|
663 |
"video_analysis": "video_tool",
|
664 |
-
"
|
665 |
"wikidata_query": "wikidata_query",
|
666 |
"default": "default_tool"
|
667 |
}
|
668 |
|
|
|
669 |
tool_name = intent_tool_map.get(intent, "default_tool")
|
670 |
|
671 |
-
#
|
672 |
-
tool_func = tools
|
673 |
|
674 |
if not tool_func:
|
675 |
-
print(f"No matching tool found for {intent}")
|
676 |
return None
|
677 |
|
678 |
-
#
|
679 |
try:
|
680 |
parsed_input = json.loads(question)
|
681 |
except json.JSONDecodeError:
|
682 |
-
parsed_input = question #
|
683 |
|
|
|
684 |
return tool_func.run(parsed_input)
|
685 |
|
686 |
|
687 |
-
# Run the function to select and execute the tool
|
688 |
-
result = select_tool_and_run(question, tools)
|
689 |
-
|
690 |
-
# Output the result
|
691 |
-
print(result)
|
692 |
-
|
693 |
|
694 |
# Function to extract math operation from the question
|
695 |
|
|
|
646 |
|
647 |
return "default"
|
648 |
|
649 |
+
|
650 |
+
|
651 |
+
def select_tool_and_run(question: str, tools: list):
|
652 |
+
# Classify intent
|
|
|
653 |
intent = task_classifier(question)
|
654 |
|
655 |
+
# Map intent to expected tool names
|
656 |
intent_tool_map = {
|
657 |
"math": "calculator",
|
658 |
"wiki_search": "wiki_tool",
|
|
|
660 |
"arxiv": "arxiv_tool",
|
661 |
"get_youtube_transcript": "youtube_tool",
|
662 |
"video_analysis": "video_tool",
|
663 |
+
"data_analysis": "analyze_tool", # FIXED key from 'analyze_tool'
|
664 |
"wikidata_query": "wikidata_query",
|
665 |
"default": "default_tool"
|
666 |
}
|
667 |
|
668 |
+
# Resolve the tool name for the detected intent
|
669 |
tool_name = intent_tool_map.get(intent, "default_tool")
|
670 |
|
671 |
+
# Try to find the matching tool object from the list
|
672 |
+
tool_func = next((tool for tool in tools if getattr(tool, "name", "") == tool_name), None)
|
673 |
|
674 |
if not tool_func:
|
675 |
+
print(f"No matching tool found for intent: {intent} (tool_name: {tool_name})")
|
676 |
return None
|
677 |
|
678 |
+
# Try to parse question into JSON for tools expecting structured input
|
679 |
try:
|
680 |
parsed_input = json.loads(question)
|
681 |
except json.JSONDecodeError:
|
682 |
+
parsed_input = question # Fallback to raw string if not JSON
|
683 |
|
684 |
+
# Run the tool and return result
|
685 |
return tool_func.run(parsed_input)
|
686 |
|
687 |
|
|
|
|
|
|
|
|
|
|
|
|
|
688 |
|
689 |
# Function to extract math operation from the question
|
690 |
|