File size: 5,025 Bytes
8b3139e
 
 
 
 
 
 
 
 
 
 
86cbfce
 
 
 
 
 
 
 
834b7c1
 
a573bfb
264afdc
 
 
8b3139e
 
86cbfce
 
 
 
 
 
8b3139e
 
86cbfce
 
 
 
 
 
 
 
 
 
 
 
 
264afdc
 
 
 
 
 
 
86cbfce
 
 
 
 
 
 
 
 
834b7c1
 
a573bfb
264afdc
 
 
 
 
8b3139e
 
 
 
 
 
 
a516261
86cbfce
 
 
 
 
 
 
8b3139e
 
86cbfce
 
 
 
 
 
 
834b7c1
 
 
 
86cbfce
 
 
 
 
834b7c1
a573bfb
264afdc
 
8b3139e
 
 
 
 
 
 
 
86cbfce
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from smolagents import (
    CodeAgent,
    InferenceClientModel,
    PythonInterpreterTool,  # python_interpreter
    FinalAnswerTool,        # final_answer
    VisitWebpageTool,       # visit_webpage
    WikipediaSearchTool,    # wikipedia_search
    WebSearchTool,          # web_search
    PythonInterpreterTool,  # python_interpreter
    SpeechToTextTool,
)
import os
# --------- my tools
from my_tool_reverse_string import ReverseStringTool
from my_tool_image_load import ImageLoadTool
from my_tool_chess_board import ChessBoard
from my_tool_fen import FENTool
from my_tool_chess_analysis import ChessAnalysisTool
from my_prompt_config import MyPromptConfig
from my_tool_wiki_page_section import MyWikiPageSectionTool
from my_tool_wiki_filter_tables import MyWikiTableFilterTool
from my_tool_wiki_featured_articles import MyWikiFeaturedArticles
from my_tools_libretexts import MyLibreTextsBookshelvesTool, MyLibreTextsBooksTool
from my_tools_libretexts import MyLibreTextsBookSectionsTool, MyLibreTextsBookSectionParagraphsTool
from my_tools_libretexts import MyLibreTextsParagraphContentsTool
from my_tool_excel_load import ExcelLoadTool
from my_tool_python_load import PythonLoadTool
from dotenv import load_dotenv


# --- Basic Agent Definition ---
# ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
class MyAgent:
    MODEL_REASONING = "deepseek-ai/DeepSeek-V3.1-Terminus"  # much worse

    chess_board_model_name = "my_chess_pieces_recognition.pth"
    chess_board_model_dir = "/mnt/c/Users/krzsa/IdeaProjects/Agents-Course-Assignment/saved_models"

    def __init__(self):
        print("Agent initialized.")
        load_dotenv()
        self.__create_agents__()

    def __create_agents__(self):
        # --- HF Inference ------------------------------------------------------------------------------
        self.model = InferenceClientModel(model_id=self.MODEL_REASONING)
        # --- HF Inference ------------------------------------------------------------------------------

        # Instruction how to specify tools
        #   1. Implement a tool (one or more tools per file)
        #   2. Add imports for used tools in the header for this file
        #   3. Add file(s) with tools to the 'additional_authorized_imports' below
        #   4. Add tool(s) to 'tools' below
        #   5. Add tool(s) name(s) to prompt configuration in my_prompt_config.py

        self.reasoning_agent = CodeAgent(
            name="CourseAssistant",
            description="General AI Assistant",
            tools=[
                ImageLoadTool(),
                ReverseStringTool(),
                ChessBoard(self.chess_board_model_name, self.chess_board_model_dir),
                FENTool(),
                ChessAnalysisTool(),
                MyWikiPageSectionTool(),
                MyWikiTableFilterTool(),
                MyWikiFeaturedArticles(),
                MyLibreTextsBookshelvesTool(),
                MyLibreTextsBooksTool(),
                MyLibreTextsBookSectionsTool(),
                MyLibreTextsBookSectionParagraphsTool(),
                MyLibreTextsParagraphContentsTool(),
                PythonInterpreterTool(),
                VisitWebpageTool(),
                WikipediaSearchTool(),
                WebSearchTool(),
                SpeechToTextTool(),
                ExcelLoadTool(),
                PythonLoadTool(),
                # ---------
                FinalAnswerTool(),
            ],
            model=self.model,
            planning_interval=3, # This is where you activate planning!,
            prompt_templates=MyPromptConfig.PROMPT_TEMPLATES,
            managed_agents=[],
            additional_authorized_imports=[
                "os",
                "io"
                "PIL",
                "chess",
                "matplotlib",
                "matplotlib.pyplot",
                "stockfish",
                "requests",
                "bs4",
                "json",
                "lxml",
                "wikitextparser",
                "mwparserfromhell"
                "my_tool_chess_analysis",
                "my_tool_chess_board",
                "my_tool_fen",
                "my_tool_image_load",
                "my_tool_reverse_string",
                "my_tool_wiki_page_section",
                "my_tool_wiki_table_filter",
                "my_tool_wiki_featured_articles",
                "my_tools_libretexts",
                "my_base_libretexts_api",
                "my_tool_excel_load",
                "my_tool_python_load",
                "smolagents",
                "transformers",
                "pandas",
                "openpyxl",
                "markdownify"
            ],
        )
        print(f"Main agent initialized: {self.reasoning_agent}")

    def __call__(self, question: str) -> str:
        print(f"Agent received question (first 50 chars): {question[:50]}...")

        answer = self.reasoning_agent.run(question)

        print(f"Agent returning answer: {answer}")
        return answer