| # functions/agent.py | |
| """Agent definition for GAIA question answering system.""" | |
| import logging | |
| from smolagents import CodeAgent, VisitWebpageTool | |
| from functions.tools import ( | |
| google_search, | |
| wikipedia_search, | |
| get_wikipedia_page, | |
| libretext_book_search, | |
| get_libretext_book, | |
| ) | |
| from functions.agent_helper_functions import step_memory_cap, step_wait | |
| from configuration import MODEL | |
| logger = logging.getLogger(__name__) | |
| def create_agent() -> CodeAgent: | |
| """Creates the GAIA agent using GPT‑4.1 or Mistral‑7B fallback.""" | |
| agent = CodeAgent( | |
| model=MODEL, | |
| tools=[ | |
| google_search, | |
| VisitWebpageTool(), | |
| wikipedia_search, | |
| get_wikipedia_page, | |
| libretext_book_search, | |
| get_libretext_book, | |
| ], | |
| add_base_tools=False, | |
| additional_authorized_imports=['bs4.*', 'json'], | |
| step_callbacks=[step_memory_cap, step_wait], | |
| name="GAIA_agent", | |
| verbosity_level=5, | |
| max_steps=20, | |
| planning_interval=5 | |
| ) | |
| logger.info("GAIA_agent created with dynamic LLM (OpenAI or HF fallback).") | |
| return agent | |