RCaz commited on
Commit
cbbbfb4
·
verified ·
1 Parent(s): 546a399

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +40 -40
agent.py CHANGED
@@ -49,43 +49,43 @@ def real_number_calculator(
49
 
50
 
51
 
52
- class TestAgent:
53
- def __init__(self):
54
-
55
- # import code agent and basic tool from smolagent
56
- from smolagents import CodeAgent, OpenAIServerModel, DuckDuckGoSearchTool, FinalAnswerTool, VisitWebpageTool, MCPServerTool
57
-
58
- # import additional tool from langchain @ https://docs.langchain.com/oss/python/integrations/tools
59
- from langchain.agents import load_tools
60
- from smolagents import Tool
61
- wikipedia_tool = Tool.from_langchain(load_tools(["wikipedia"])[0])
62
- wikipedia_tool.top_k_results=3
63
-
64
- # import tools from MCP servers @ https://github.com/mcp
65
- from mcp import StdioServerParameters
66
- server_parameters = StdioServerParameters(command="uvx",
67
- args=["--quiet", "youtubeqa@0.2.1"],
68
- env={"UV_PYTHON": "3.12", **os.environ},
69
- )
70
- youtube_tools = MCPServerTool(server_params=server_parameters)
71
-
72
- model = OpenAIServerModel(model_id="gpt-4o")
73
- #model = InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct")
74
- # Instantiate the agent
75
- self.agent = CodeAgent(
76
- tools=[real_number_calculator(), # homemade tool
77
- DuckDuckGoSearchTool(), # basic tools from smolagent
78
- VisitWebpageTool(),
79
- wikipedia_tool, # tool from langchain with extra parmaeters
80
- youtube_tools, # tool from MCP server
81
- FinalAnswerTool()],
82
- model=model,
83
- max_steps=3,
84
- verbosity_level=2
85
- )
86
-
87
- def __call__(self, question: str) -> str:
88
- print(f"Agent received question (first 50 chars): {question[:50]}...")
89
- answer = self.agent.invoke(question)
90
- print(f"Agent returning his answer: {answer}")
91
- return answer
 
49
 
50
 
51
 
52
+ class TestAgent:
53
+ def __init__(self):
54
+
55
+ # import code agent and basic tool from smolagent
56
+ from smolagents import CodeAgent, OpenAIServerModel, DuckDuckGoSearchTool, FinalAnswerTool, VisitWebpageTool, MCPServerTool
57
+
58
+ # import additional tool from langchain @ https://docs.langchain.com/oss/python/integrations/tools
59
+ from langchain.agents import load_tools
60
+ from smolagents import Tool
61
+ wikipedia_tool = Tool.from_langchain(load_tools(["wikipedia"])[0])
62
+ wikipedia_tool.top_k_results=3
63
+
64
+ # import tools from MCP servers @ https://github.com/mcp
65
+ from mcp import StdioServerParameters
66
+ server_parameters = StdioServerParameters(command="uvx",
67
+ args=["--quiet", "youtubeqa@0.2.1"],
68
+ env={"UV_PYTHON": "3.12", **os.environ},
69
+ )
70
+ youtube_tools = MCPServerTool(server_params=server_parameters)
71
+
72
+ model = OpenAIServerModel(model_id="gpt-4o")
73
+ #model = InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct")
74
+ # Instantiate the agent
75
+ self.agent = CodeAgent(
76
+ tools=[real_number_calculator(), # homemade tool
77
+ DuckDuckGoSearchTool(), # basic tools from smolagent
78
+ VisitWebpageTool(),
79
+ wikipedia_tool, # tool from langchain with extra parmaeters
80
+ youtube_tools, # tool from MCP server
81
+ FinalAnswerTool()],
82
+ model=model,
83
+ max_steps=3,
84
+ verbosity_level=2
85
+ )
86
+
87
+ def __call__(self, question: str) -> str:
88
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
89
+ answer = self.agent.invoke(question)
90
+ print(f"Agent returning his answer: {answer}")
91
+ return answer