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