|
|
from smolagents import ( |
|
|
CodeAgent, |
|
|
InferenceClientModel, |
|
|
PythonInterpreterTool, |
|
|
FinalAnswerTool, |
|
|
VisitWebpageTool, |
|
|
WikipediaSearchTool, |
|
|
WebSearchTool, |
|
|
PythonInterpreterTool, |
|
|
SpeechToTextTool, |
|
|
) |
|
|
import os |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyAgent: |
|
|
MODEL_REASONING = "deepseek-ai/DeepSeek-V3.1-Terminus" |
|
|
|
|
|
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): |
|
|
|
|
|
self.model = InferenceClientModel(model_id=self.MODEL_REASONING) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, |
|
|
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 |