diff --git a/langchain/agents/mrkl/base.py b/langchain/agents/mrkl/base.py index f28a01ab01..e1d55eb12f 100644 --- a/langchain/agents/mrkl/base.py +++ b/langchain/agents/mrkl/base.py @@ -124,6 +124,10 @@ class ZeroShotAgent(Agent): @classmethod def _validate_tools(cls, tools: Sequence[BaseTool]) -> None: validate_tools_single_input(cls.__name__, tools) + if len(tools) == 0: + raise ValueError( + f"Got no tools for {cls.__name__}. At least one tool must be provided." + ) for tool in tools: if tool.description is None: raise ValueError( diff --git a/tests/unit_tests/agents/test_serialization.py b/tests/unit_tests/agents/test_serialization.py index db68fd2b28..64e5e4d8d5 100644 --- a/tests/unit_tests/agents/test_serialization.py +++ b/tests/unit_tests/agents/test_serialization.py @@ -3,12 +3,19 @@ from tempfile import TemporaryDirectory from langchain.agents.agent_types import AgentType from langchain.agents.initialize import initialize_agent, load_agent +from langchain.agents.tools import Tool from langchain.llms.fake import FakeListLLM def test_mrkl_serialization() -> None: agent = initialize_agent( - [], + [ + Tool( + name="Test tool", + func=lambda x: x, + description="Test description", + ) + ], FakeListLLM(responses=[]), agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True,