File size: 1,416 Bytes
ef95f1f
 
 
 
 
e8f0fff
ef95f1f
0359413
 
86aee1a
 
 
 
 
618dd54
86aee1a
 
0359413
 
86aee1a
 
0359413
b8351ca
 
acc56d5
 
86aee1a
acc56d5
86aee1a
 
acc56d5
86aee1a
 
acc56d5
86aee1a
 
618dd54
 
 
86aee1a
 
fc71415
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from tools import (
    all_tools,
    analyze_youtube_video,
    extract_number_from_text,
    search_wikipedia,
    check_commutativity_table
)

class BasicAgent:
    def __init__(self):
        self.tool_registry = {
            "analyze_youtube_video": (analyze_youtube_video, "url"),
            "extract_number_from_text": (extract_number_from_text, "text"),
            "search_wikipedia": (search_wikipedia, "query"),
            "check_commutativity_table": (check_commutativity_table, "table_text"),
        }

    def __call__(self, question: str) -> str:
        try:
            tool, input_key = self.select_tool(question)
            return tool.invoke({input_key: question})
        except Exception as e:
            return f"Error: {e}"

    def select_tool(self, question: str):
        q = question.lower()

        if "youtube.com" in q or "youtu.be" in q or "in the video" in q:
            return self.tool_registry["analyze_youtube_video"]

        elif "how many" in q or "number of" in q:
            return self.tool_registry["extract_number_from_text"]

        elif "wikipedia" in q or "encyclopedia" in q or "who is" in q:
            return self.tool_registry["search_wikipedia"]

        elif "commutative" in q or "counter-examples" in q:
            return self.tool_registry["check_commutativity_table"]

        return self.tool_registry["extract_number_from_text"]  # fallback