|
|
State Transition Testing for Multi-Turn ADK Agents
Author: Venkata Sudhakar
State transition testing verifies that a multi-turn ADK agent moves through its conversation states correctly - accepting valid transitions and rejecting invalid ones. ShopMax India's order support agent has defined states (greeting, intent_identified, tool_called, response_given, session_closed) and must never skip a required state or re-enter a closed session, properties that are only caught by explicitly testing each transition path.
The test model is a state machine where each state has a set of valid next states. A StateTracker records the sequence of states visited during a conversation turn. Tests drive the agent through a valid path and assert the recorded sequence matches the expected state chain. Invalid transitions - like jumping from greeting directly to response_given - must raise a StateError or be blocked by the tracker.
The example below defines an OrderSupportStateMachine with five states, tests a valid end-to-end conversation path, and tests that an invalid transition from greeting to response_given is correctly rejected.
It gives the following output,
State path: ['greeting', 'intent_identified', 'tool_called', 'response_given', 'session_closed']
Invalid transition greeting->response_given correctly blocked
Closed session correctly blocked re-entry
3 passed in 0.05s
Draw the state machine diagram in the test file as a comment table so that new developers can visually verify test coverage against the spec. Test every valid path (not just the happy path) and every invalid transition from every state - this matrix approach ensures no edge in the state graph is untested. For agents with long conversation flows, use itertools.product to generate all transition combinations automatically rather than writing them by hand.
|
|