File size: 772 Bytes
ab8fe52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os

import yaml
from smolagents import OpenAIServerModel, CodeAgent, DuckDuckGoSearchTool, VisitWebpageTool


model = OpenAIServerModel(
    model_id="claude-3-5-haiku-20241022",
    api_base="https://api.anthropic.com/v1/",
    api_key=os.environ["ANTROPHIC_API_KEY"],
)

agent = CodeAgent(
    model=model,
    tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
    max_steps=10,
    additional_authorized_imports=["time", "numpy", "pandas"]
)

class BasicAgent:
    def __init__(self):
        print("BasicAgent initialized.")
    def __call__(self, question: str) -> str:
        print(f"Agent received question (first 50 chars): {question[:50]}...")
        answer = agent.run(question)
        print(f"Agent returning answer: {answer}")
        return answer