from smolagents import ( CodeAgent, DuckDuckGoSearchTool, VisitWebpageTool, InferenceClientModel, ) class BasicAgent: def __init__(self): token = os.getenv("HF_TOKEN") if not token: raise ValueError("Add HF_TOKEN in your Space's Settings → Secrets.") model = InferenceClientModel(token=token) self.agent = CodeAgent( tools=[ DuckDuckGoSearchTool(), VisitWebpageTool(), ], model=model, max_steps=12, ) def __call__(self, question: str) -> str: prompt = ( "Answer the following question accurately. " "Use web search and visit source pages when needed. " "Follow the requested answer format exactly. " "Return only the answer, without explanations, citations, " "or a 'FINAL ANSWER' prefix.\n\n" + question ) return str(self.agent.run(prompt, reset=True)).strip()