| """ |
| GAIA Level-1 agent powered by smolagents. |
| |
| * Planner/esecutore: CodeAgent (smolagents) |
| * LLM backend : GPT-4.1 via OpenAI |
| * Tools : DuckDuckGo (builtin), WikipediaTool, ArxivTool |
| * Output : UNA sola riga (exact-match) |
| """ |
| from __future__ import annotations |
| import os, textwrap |
| from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIModel |
| from tools import WikipediaTool, ArxivTool |
| import openai |
|
|
| |
| openai.api_key = os.getenv("OPENAI_API_KEY") or "" |
| if not openai.api_key: |
| raise EnvironmentError( |
| "OPENAI_API_KEY non impostata: aggiungila nei Secrets dello Space " |
| "o in un file .env locale." |
| ) |
|
|
| |
| SYSTEM_PROMPT = textwrap.dedent(""" |
| You are a helpful assistant tasked with answering questions using a set of tools. |
| Your final answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. |
| If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. |
| If you are asked for a string, don't use articles, neither abbreviations, and write digits in plain text unless specified otherwise. |
| Return ONLY the final answer line. |
| """).strip() |
|
|
| |
| model = OpenAIModel( |
| model_id="gpt-4.1", |
| temperature=0, |
| system_prompt=SYSTEM_PROMPT |
| ) |
|
|
| tools = [ |
| DuckDuckGoSearchTool(), |
| WikipediaTool(), |
| ArxivTool(), |
| ] |
|
|
| core_agent = CodeAgent( |
| model=model, |
| tools=tools, |
| max_steps=6, |
| scratchpad="minimal" |
| |
| ) |
|
|
| |
| class BasicAgent: |
| def __init__(self): |
| print("β
smolagents BasicAgent inizializzato") |
|
|
| def __call__(self, question: str) -> str: |
| """ |
| Esegue CodeAgent e restituisce SOLO la prima riga, |
| così il grader riceve una stringa exact-match. |
| """ |
| raw_answer: str = core_agent.run(question) |
| answer = raw_answer.strip().split("\n", 1)[0] |
| print(f"[ANSWER] {answer}") |
| return answer |
|
|