Testing Workflow Paths
Workflow path tests verify that the agent follows the correct sequence of steps for each type of input. They check the path taken, not just the final output.
8 min•By Priygop Team•Updated 2026
Path Tracing Test
Path Tracing Test
# Test that the agent follows the expected workflow path
class WorkflowPathTester:
"""Records the steps taken by an agent and compares to expected paths."""
def __init__(self, agent_fn):
self.agent_fn = agent_fn
def run_and_trace(self, goal: str, initial_state: dict) -> list:
"""Run the agent and collect the sequence of actions taken."""
path = []
state = initial_state.copy()
# Simulate agent loop (simplified)
for step in range(10):
decision = self.agent_fn(goal, state)
action = decision.get("action")
path.append(action)
if action in ("FINISH", "ESCALATE"):
break
# Update state based on action (simplified)
state.setdefault("history", []).append({"action": action})
return path
def assert_path_contains(self, path: list, required_actions: list) -> bool:
"""Check that all required actions appear in the path."""
missing = [a for a in required_actions if a not in path]
if missing:
print(f" ✗ Missing actions: {missing}")
return False
return True
def assert_action_order(self, path: list, before: str, after: str) -> bool:
"""Check that 'before' action always comes before 'after' action in path."""
if before not in path or after not in path:
return True # Cannot check if either is missing
idx_before = path.index(before)
idx_after = path.index(after)
if idx_before > idx_after:
print(f" ✗ Order violation: {after} came before {before}")
return False
return True
# Mock agent for path testing
step_counter = [0]
def scripted_agent(goal, state):
n = len(state.get("history", []))
steps = ["web_search", "extract_data", "summarise", "send_email", "FINISH"]
return {"action": steps[min(n, len(steps)-1)]}
tester = WorkflowPathTester(scripted_agent)
path = tester.run_and_trace("Research and send summary", {})
print("Path taken:", path)
# Assertions
ok1 = tester.assert_path_contains(path, ["web_search", "summarise", "FINISH"])
ok2 = tester.assert_action_order(path, "web_search", "summarise")
ok3 = tester.assert_action_order(path, "summarise", "send_email")
print(f" Path completeness: {'✓' if ok1 else '✗'}")
print(f" search before summarise: {'✓' if ok2 else '✗'}")
print(f" summarise before email: {'✓' if ok3 else '✗'}")