from definable.agents import AgentTestCase, MockModel
from definable.tools import tool
@tool
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
class TestMathAgent(AgentTestCase):
def test_uses_add_tool(self):
agent = self.create_agent(
model=MockModel(
tool_calls=[{"name": "add", "arguments": {"a": 2, "b": 3}}],
responses=["2 + 3 = 5"],
),
tools=[add],
)
output = agent.run("What is 2 + 3?")
self.assert_no_errors(output)
self.assert_has_content(output)
self.assert_tool_called(output, "add")
self.assert_content_contains(output, "5")
def test_no_tools_needed(self):
agent = self.create_agent(
model=MockModel(responses=["Hello!"]),
)
output = agent.run("Say hello.")
self.assert_no_errors(output)
self.assert_tool_not_called(output, "add")