File size: 1,318 Bytes
6073dc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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])