Skip to Content
DocumentationAssertionsAgent Assertions

Agent Assertions

Validate tool/function calling behavior.

tool_called

expect.tool_called("web_search") # called at least once expect.tool_called("web_search", times=1) # called exactly once expect.tool_called("web_search", min_times=2) # at least 2 times

no_loop_detected

Detects infinite loops in tool call traces (same tool called 3+ times consecutively).

expect.no_loop_detected()

Loop detection looks for the same tool called 3+ times in a row. This catches runaway agents before they burn through your budget.

tool_call_order

Checks tools were called in order.

expect.tool_call_order(["search", "parse", "summarize"])

Full Example

test_agent.py
from assertllm import expect, llm_test @llm_test( expect.tool_called("search", min_times=1), expect.tool_call_order(["search", "summarize"]), expect.no_loop_detected(), expect.latency_under(5000), model="claude-sonnet-4-6", ) def test_research_agent(llm): tools = [ { "type": "function", "function": { "name": "search", "description": "Search the web", "parameters": { "type": "object", "properties": {"query": {"type": "string"}}, }, }, }, { "type": "function", "function": { "name": "summarize", "description": "Summarize text", "parameters": { "type": "object", "properties": {"text": {"type": "string"}}, }, }, }, ] llm("Find and summarize recent AI news", tools=tools)
Output
test_agent.py::test_research_agent Tool calls: search → summarize ✓ tool_called("search", min_times=1) — called 1 time ✓ tool_call_order(["search", "summarize"]) ✓ no_loop_detected() ✓ latency_under(5000) — 2341ms PASSED [2.3s]
Last updated on