Testing the Agent
Testing a production agent requires four phases: unit testing of individual components, integration testing of the full workflow, evaluation testing of output quality, and regression testing after changes.
8 min•By Priygop Team•Updated 2026
Four-Phase Testing Strategy
Four-Phase Testing Strategy
# Complete testing strategy for a production agent
# Phase 1: Unit tests — individual components in isolation
def test_check_eligibility_unit():
"""Test eligibility logic without calling the LLM or external APIs."""
from datetime import date, timedelta
def check_eligibility(order: dict) -> str:
order_date = date.fromisoformat(order["date"])
days_since = (date.today() - order_date).days
if days_since > 30:
return "ineligible"
if order["total"] >= 100:
return "eligible_manual"
return "eligible_auto"
# Test all branches
recent_small = {"date": str(date.today() - timedelta(5)), "total": 49.99}
recent_large = {"date": str(date.today() - timedelta(5)), "total": 199.99}
old_order = {"date": str(date.today() - timedelta(45)), "total": 49.99}
assert check_eligibility(recent_small) == "eligible_auto"
assert check_eligibility(recent_large) == "eligible_manual"
assert check_eligibility(old_order) == "ineligible"
print("✓ Phase 1: Unit tests passed")
# Phase 2: Integration test — full workflow with mock tools
def test_full_workflow_integration():
"""Run the complete workflow with mocked external calls."""
mock_tools = {
"get_order": lambda order_id: {"status":"success","order":{"total":49.99,"date":"2024-01-10"}},
"issue_refund": lambda order_id, amount: {"status":"success","refund_id":"REF-001"},
"send_email": lambda to, subject, body: {"status":"success"}
}
# Simulate a successful run through the full workflow
order = mock_tools["get_order"]("ORD-123")["order"]
refund = mock_tools["issue_refund"]("ORD-123", order["total"])
email = mock_tools["send_email"]("user@ex.com", "Refund confirmed", "...")
assert refund["status"] == "success"
assert email["status"] == "success"
print("✓ Phase 2: Integration test passed")
# Phase 3: Evaluation — score output quality
def test_output_quality():
"""Score agent output against expected criteria."""
agent_output = {
"outcome": "success", "refund_id": "REF-001",
"message": "Your refund of $49.99 for order ORD-123 has been processed."
}
score = 0
if agent_output.get("outcome") == "success": score += 1
if agent_output.get("refund_id"): score += 1
if agent_output.get("message") and len(agent_output["message"]) > 20: score += 1
if "49.99" in agent_output.get("message", ""): score += 1
assert score == 4, f"Quality score {score}/4"
print("✓ Phase 3: Output quality test passed (4/4)")
test_check_eligibility_unit()
test_full_workflow_integration()
test_output_quality()
print("\nAll phases passed!")