diff --git a/tests/test_agents/__init__.py b/tests/test_agents/__init__.py index e69de29b..313c43ae 100644 --- a/tests/test_agents/__init__.py +++ b/tests/test_agents/__init__.py @@ -0,0 +1,21 @@ +from typing import Type +from langchain_core.tools import BaseTool +from langchain_core.pydantic_v1 import BaseModel, Field + + +class MockToolInput(BaseModel): + """Input for the MockTool tool.""" + + tool_input: str = Field(description="tool_input") + + +class MockTool(BaseTool): + """Mock tool for run agent tests""" + + name: str = "mock tool" + description: str = "Mock tool for tests" + + args_schema: Type[BaseModel] = MockToolInput + + def _run(self, tool_input: str, *args, **kwargs): + return tool_input diff --git a/tests/test_agents/test_langchain_output_handler.py b/tests/test_agents/test_langchain_output_handler.py index 89eddc9a..cfdfb884 100644 --- a/tests/test_agents/test_langchain_output_handler.py +++ b/tests/test_agents/test_langchain_output_handler.py @@ -1,11 +1,11 @@ import pytest -from langchain_community.tools import DuckDuckGoSearchRun from langchain_core.agents import AgentFinish, AgentAction from motleycrew.agents import MotleyOutputHandler from motleycrew.agents.langchain.tool_calling_react import ReActToolCallingAgent from motleycrew.agents.parent import DirectOutput from motleycrew.common.exceptions import InvalidOutput, OutputHandlerMaxIterationsExceeded +from tests.test_agents import MockTool invalid_output = "Add more information about AI applications in medicine." @@ -38,7 +38,7 @@ def fake_agent_take_next_step( @pytest.fixture def agent(): agent = ReActToolCallingAgent( - tools=[DuckDuckGoSearchRun()], + tools=[MockTool()], verbose=True, chat_history=True, output_handler=ReportOutputHandler(max_iterations=5), diff --git a/tests/test_agents/test_llama_index_output_handler.py b/tests/test_agents/test_llama_index_output_handler.py index 4bdd6baa..fd451617 100644 --- a/tests/test_agents/test_llama_index_output_handler.py +++ b/tests/test_agents/test_llama_index_output_handler.py @@ -2,7 +2,6 @@ from collections import deque import pytest -from langchain_community.tools import DuckDuckGoSearchRun from langchain_core.tools import StructuredTool try: @@ -20,9 +19,9 @@ from motleycrew.agents import MotleyOutputHandler from motleycrew.common.exceptions import ( InvalidOutput, - ModuleNotInstalled, OutputHandlerMaxIterationsExceeded, ) +from tests.test_agents import MockTool invalid_output = "Add more information about AI applications in medicine." @@ -49,20 +48,16 @@ def fake_run_step(*args, **kwargs): @pytest.fixture def agent(): - try: - search_tool = DuckDuckGoSearchRun() - agent = ReActLlamaIndexMotleyAgent( - description="Your goal is to uncover cutting-edge developments in AI and data science", - tools=[search_tool], - output_handler=ReportOutputHandler(max_iterations=5), - verbose=True, - ) - agent.materialize() - agent._agent._run_step = fake_run_step - agent._agent._run_step = agent.run_step_decorator()(agent._agent._run_step) - - except ModuleNotInstalled: - return + + agent = ReActLlamaIndexMotleyAgent( + description="Your goal is to uncover cutting-edge developments in AI and data science", + tools=[MockTool()], + output_handler=ReportOutputHandler(max_iterations=5), + verbose=True, + ) + agent.materialize() + agent._agent._run_step = fake_run_step + agent._agent._run_step = agent.run_step_decorator()(agent._agent._run_step) return agent