from smolagents import HfApiModel, CodeAgent, DuckDuckGoSearchTool, VisitWebpageTool, InferenceClientModel, LiteLLMModel, GoogleSearchTool, WebSearchTool # from huggingface_hub import InferenceClient import os class Agent: def __init__(self): self.model_id = "openai/gpt-4.1-mini" # self.model = HfApiModel( # model_id=self.model_id, # token=os.getenv("HF_TOKEN"), # ) # self.model = InferenceClientModel( # model=self.model_id, # token=os.getenv("HF_TOKEN"), # provider="hf-inference", # ) self.model = LiteLLMModel( model_id=self.model_id, api_key=os.getenv("OpenAI") ) self.agent = CodeAgent( model=self.model, tools=[WebSearchTool(engine="bing"), VisitWebpageTool()], max_steps=15, ) print("Agent initialized.") def __call__(self, question: str) -> str: print(f"Agent received question (first 50 chars): {question[:50]}...") prompt = f""" You are an expert on the GAIA dataset. Given a question from the GAIA dataset, you will answer it using the tools available to you. The question itself might be cryptic. When you're done, only output the final answer, without any additional text or explanation. question: {question} """ answer = self.agent.run(question) print(f"Agent returning answer: {answer}") return answer