Frazer2810's picture
Update agent.py
395ccfe verified
raw
history blame
1.97 kB
"""
GAIA Level-1 agent powered by smolagents β‰₯ 0.6
"""
from __future__ import annotations
import os, textwrap
from smolagents import CodeAgent, DuckDuckGoSearchTool
from tools import WikipediaTool, ArxivTool
import openai
# ─── API key ───────────────────────────────────────
openai.api_key = os.getenv("OPENAI_API_KEY") or ""
if not openai.api_key:
raise EnvironmentError("OPENAI_API_KEY non trovata – aggiungila nei Secrets dello Space.")
# ─── System prompt (exact-match) ───────────────────
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()
# ─── Build CodeAgent ───────────────────────────────
MODEL_ID = os.getenv("GAIA_MODEL_ID", "gpt-4o") # override se hai β€œgpt-4.1”
core_agent = CodeAgent(
model=MODEL_ID,
tools=[
DuckDuckGoSearchTool(),
WikipediaTool(),
ArxivTool(),
],
max_steps=6,
temperature=0,
system_prompt=SYSTEM_PROMPT,
stream_outputs=False,
)
# ─── Thin wrapper per app.py ───────────────────────
class BasicAgent:
def __init__(self):
print("βœ… smolagents BasicAgent avviato")
def __call__(self, question: str) -> str:
raw = core_agent.run(question)
return raw.strip().split("\n", 1)[0]