from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel from tools.wiki_tool import WikiTool from tools.excel_analysis_tool import ExcelAnalysisTool import os def create_agent(): """ Creates and configures the CodeAgent with the necessary model and tools. Returns: CodeAgent: The configured agent instance. """ # Load API key from environment variable (more secure) api_key = os.getenv("HF_API_KEY") if not api_key: raise RuntimeError("Missing Hugging Face API key. Set HF_API_KEY environment variable.") # Initialize the LLM model model = HfApiModel(api_key=api_key, model_id="deepseek-ai/deepseek-coder-6.7b-instruct") # Initialize tools wiki_tool = WikiTool() # Custom Wikipedia wrapper web_search_tool = DuckDuckGoSearchTool() # Built-in smolagents web search tool excel_analysis_tool = ExcelAnalysisTool() # Custom Excel processing tool # Create and return the agent agent = CodeAgent( model=model, tools=[wiki_tool, web_search_tool, excel_analysis_tool], max_steps=8, verbosity_level=2 ) return agent # Example usage if __name__ == "__main__": agent = create_agent() print("Agent created with tools:", [tool.name for tool in agent.tools])