File size: 841 Bytes
491eb11
 
 
 
 
 
 
 
 
 
 
9019097
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491eb11
9019097
 
 
491eb11
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
import os
from smolagents import (
    CodeAgent,
    LiteLLMModel,
    PythonInterpreterTool,
    DuckDuckGoSearchTool,
    VisitWebpageTool,
)
from rate_limiter import RateLimiter


class BasicAgent:
    def __init__(self):
        model = LiteLLMModel(
            model_id=os.getenv("MODEL_ID"),
            api_key=os.getenv("MODEL_API_KEY"),
        )
        self.agent = CodeAgent(
            tools=[
                PythonInterpreterTool(),
                DuckDuckGoSearchTool(),
                VisitWebpageTool(),
            ],
            model=model,
            step_callbacks=[RateLimiter().increment_and_sleep_if_needed],
        )

    def __call__(self, question: str) -> str:
        final_answer = self.agent.run(task=question)
        print(f"Agent returning final answer: {final_answer}")
        return final_answer