Skip to content

Commit 096bbf3

Browse files
authored
Merge pull request #21 from DipayanDasgupta/feat/test-reasoning-base-class
test(reasoning): Add tests for Reasoning base class
2 parents ae0877e + d6b7cc3 commit 096bbf3

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

tests/test_reasoning/test_reasoning.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# tests/test_reasoning/test_reasoning.py
2-
31
from unittest.mock import Mock
42

53
from mesa_llm.reasoning.reasoning import (
64
Observation,
75
Plan,
6+
Reasoning,
87
)
98

109

@@ -39,3 +38,53 @@ def test_plan_creation(self):
3938
assert plan.step == 1
4039
assert plan.llm_plan == mock_llm_response
4140
assert plan.ttl == 3
41+
42+
43+
class TestReasoningBase:
44+
"""Tests for the abstract Reasoning base class."""
45+
46+
def test_execute_tool_call_generates_plan(self):
47+
"""Test that the base execute_tool_call method produces a Plan."""
48+
# 1. Setup a mock agent with all necessary components
49+
mock_agent = Mock()
50+
mock_agent.model.steps = 5
51+
52+
# Mock the LLM and its response
53+
mock_llm_response = Mock()
54+
mock_llm_response.choices = [Mock()]
55+
mock_llm_response.choices[0].message = "Final LLM message"
56+
mock_agent.llm.generate.return_value = mock_llm_response
57+
58+
# Mock the Tool Manager
59+
mock_agent.tool_manager.get_all_tools_schema.return_value = [
60+
{"schema": "example"}
61+
]
62+
63+
# 2. Instantiate a concrete implementation of Reasoning to test the base method
64+
class ConcreteReasoning(Reasoning):
65+
def plan(self, prompt, obs=None, ttl=1, selected_tools=None):
66+
pass # Not needed for this test
67+
68+
reasoning = ConcreteReasoning(agent=mock_agent)
69+
70+
# 3. Call the method we want to test
71+
chaining_message = "Execute the plan."
72+
result_plan = reasoning.execute_tool_call(
73+
chaining_message, selected_tools=["tool1"]
74+
)
75+
76+
# 4. Assert the results
77+
# Assert that the LLM was called with the correct parameters
78+
mock_agent.llm.generate.assert_called_once_with(
79+
prompt=chaining_message,
80+
tool_schema=[{"schema": "example"}],
81+
tool_choice="required",
82+
)
83+
# Assert that the tool manager was asked for the correct schema
84+
mock_agent.tool_manager.get_all_tools_schema.assert_called_once_with(
85+
selected_tools=["tool1"]
86+
)
87+
# Assert that the output is a correctly formed Plan object
88+
assert isinstance(result_plan, Plan)
89+
assert result_plan.step == 5
90+
assert result_plan.llm_plan == "Final LLM message"

0 commit comments

Comments
 (0)