SkynetAgent / agents.py
cyberosa
trying new model and new search tool
ca302c3
raw
history blame
3.48 kB
from smolagents import (
LiteLLMModel,
OpenAIServerModel,
ToolCallingAgent,
CodeAgent,
VisitWebpageTool,
WikipediaSearchTool,
DuckDuckGoSearchTool,
SpeechToTextTool,
PythonInterpreterTool,
)
import os
import time
from typing import Optional
from tools import MySearchTool
gemini_api_key = os.environ.get("GEMINI_API_KEY", None)
open_router_api_key = os.environ.get("OPENROUTER_API_KEY", None)
gemini_model = LiteLLMModel(
model_id="gemini/gemini-2.0-flash",
api_key=gemini_api_key,
)
# alternative model
model = OpenAIServerModel(
# model_id='deepseek/deepseek-r1-0528-qwen3-8b:free',
# model_id="thudm/glm-4-32b:free" function calling
model_id="google/gemini-2.0-flash-exp:free", # function calling support
api_key=open_router_api_key,
)
search_tool = DuckDuckGoSearchTool()
speech_tool = SpeechToTextTool()
wiki_tool = WikipediaSearchTool()
python_tool = PythonInterpreterTool()
visit_webpage_tool = VisitWebpageTool()
my_search_tool = MySearchTool()
class SkynetMultiAgent:
def __init__(self):
web_agent = ToolCallingAgent(
tools=[search_tool, VisitWebpageTool(), WikipediaSearchTool()],
model=gemini_model,
max_steps=10,
name="web_search_agent",
add_base_tools=True,
description="Runs web searches and visit websites to get information.",
)
self.agent = CodeAgent(
tools=[],
model=gemini_model,
name="manager_agent",
description="Manages other agents and runs code.",
managed_agents=[web_agent],
additional_authorized_imports=["time", "numpy", "pandas"],
)
def __call__(self, question: str, file_path: Optional[str] = None) -> str:
print(f"Agent received question (first 50 chars): {question[:50]}...")
# Adding extra content if provided
if file_path and os.path.exists(file_path):
eval_question = f"{question}\n\nFile provided: {file_path}"
print(f"Processing question with file: {file_path}")
else:
eval_question = question
time.sleep(2) # 2-second delay
fixed_answer = self.agent.run(eval_question, max_steps=5)
print(f"Agent returning fixed answer: {fixed_answer}")
return fixed_answer
class SkynetSingleAgent:
def __init__(self):
self.agent = CodeAgent(
tools=[
speech_tool,
wiki_tool,
my_search_tool,
visit_webpage_tool,
python_tool,
],
model=gemini_model,
name="skynet_agent",
max_steps=5,
description="Agent to answer questions and run code",
additional_authorized_imports=["time", "numpy", "pandas"],
)
def __call__(self, question: str, file_path: Optional[str] = None) -> str:
print(f"Agent received question (first 50 chars): {question[:50]}...")
# Adding extra content if provided
if file_path and os.path.exists(file_path):
eval_question = f"{question}\n\nFile provided: {file_path}"
print(f"Processing question with file: {file_path}")
else:
eval_question = question
time.sleep(2) # 2-second delay
fixed_answer = self.agent.run(eval_question)
print(f"Agent returning fixed answer: {fixed_answer}")
return fixed_answer