File size: 1,187 Bytes
980a2ce f0f133a 6643df2 980a2ce | 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 | import os
from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool, WikipediaSearchTool
from tools import VisitWebpageTool, DownloadTaskAttachmentTool
class TheAgent:
"""Agent that processes questions using LLM and various tools."""
def __init__(self):
# Initialize the agent with model and tools
self.agent = CodeAgent(
model=LiteLLMModel(
model_id="openrouter/meta-llama/llama-4-maverick-17b-128e-instruct",
api_key=os.getenv("OPENROUTER_KEY")
),
tools=[
DuckDuckGoSearchTool(),
WikipediaSearchTool(),
VisitWebpageTool(),
DownloadTaskAttachmentTool()
],
add_base_tools=True,
additional_authorized_imports=['pandas', 'numpy', 'csv', 'subprocess', 'exec']
)
print("Agent initialized successfully.")
def __call__(self, question: str) -> str:
"""Process a question and return the answer."""
print(f"Processing question: {question[:50]}..." if len(question) > 50 else f"Processing question: {question}")
return self.agent.run(question)
|