Walk a caller through steps they cannot skip
Expose only the next allowed AI agent tool at each step so callers cannot move backward or skip ahead.
The claim
A step is a prompt the model reads while that step is active, plus three fields around it. valid_steps lists where the model’s next_step tool can go. functions lists the tools that exist while the step is active. step_criteria is the sentence the runtime judges before it advances. The steps reference documents all three. Each step below names exactly one tool, and each step but the last names only the step after it, so the flow is a line.
Why it holds
Tool handlers accept the answers and write them to global_data. Your handler decides whether an answer counts before anything is written.
How it works
Each step is declared once and carries its own edges.
flow.add_step("location") \
.add_section("Current Task", "Ask where the vehicle is.") \
.set_step_criteria("save_location has accepted a location.") \
.set_functions(["save_location"]) \
.set_valid_steps(["vehicle"])The last step sets end instead of valid_steps. What the platform receives:
{"name": "location", "text": "...",
"step_criteria": "save_location has accepted a location.",
"functions": ["save_location"],
"valid_steps": ["vehicle"]}Call set_functions on every step. The SDK’s own note on set_functions says a step that does not declare functions inherits the previous step’s set. It calls that the most common bug in multi-step agents.
The handler judges the answer. A location under six characters returns INCOMPLETE and writes nothing; a vehicle needs at least two words. A usable answer emits set_global_data. The last handler records the problem and tells the model to say the request is recorded. This recipe dispatches nothing.
The SDK closes the flow at build time. A valid_steps entry naming a step that does not exist fails the context builder’s validate(). The SDK catches that error during render and logs it as ai_verb_config_error, so what you see is a schema error about a missing prompt. The line naming the step is in the log.
Limitations
A step is not a security boundary. step_criteria is a sentence the model judges, and valid_steps shapes the tool it is offered. What the verifier proves is the document: one tool per step, one edge per step. Anything that must not happen early belongs in a handler.
The verifier shows gather_info is absent from the SDK’s bundled schema, so a document using it cannot be validated offline. This recipe does not use it.
What to change first
Give vehicle a valid_steps of ["problem", "location"] and run the verifier. It fails on the backward edge: the document now offers the model a way back.
Where this sits
Seen in a build
One of 4 recipes composed by Absence reporting line: the caller gives details in any order and code decides when the form is complete.
Seen in a build
One of 6 recipes composed by After-hours AI answering service: code decides whether the AI is on the call at all.
Seen in a build
One of 6 recipes composed by AI appointment reminder caller: consent, do-not-call and calling hours enforced before the dial.
Seen in a build
One of 5 recipes composed by AI bank balance line: account tools that do not exist until a handler verifies the caller.
Seen in a build
One of 5 recipes composed by AI collections agent: a payment policy the model cannot reveal or bargain over.
Seen in a build
One of 3 recipes composed by AI front desk receptionist: departments as isolated personas that cannot use each other's tools.
Seen in a build
One of 5 recipes composed by AI hiring phone screen: a voice form the candidate cannot reorder or skip.
Seen in a build
One of 6 recipes composed by AI insurance claim intake: the adjuster is briefed and accepts before the bridge completes.
Seen in a build
One of 4 recipes composed by AI lead qualification line: a lead scored from typed handler data, not the transcript.
Seen in a build
One of 6 recipes composed by AI medical appointment line: recording that starts only in the handler that records consent.
Seen in a build
One of 5 recipes composed by AI order status line: the handler holds the full record and the model sees a curated slice.
Seen in a build
One of 5 recipes composed by Give Claude a phone number: an AI phone line whose tools are also an MCP server.
Seen in a build
One of 4 recipes composed by AI restaurant reservation line: a booking the model cannot confirm until code has made it.
Seen in a build
One of 6 recipes composed by AI SMS concierge: one agent definition answering texts and calls with the same rules.
Seen in a build
One of 6 recipes composed by AI support line with callback: the issue survives the queue and the return call without the model carrying it.
Seen in a build
One of 5 recipes composed by AI travel concierge: two agents handing a caller back and forth with context and no transcript.
Seen in a build
One of 4 recipes composed by AI trivia hotline: a game graded in code with an answer key the model never sees.
Seen in a build
One of 5 recipes composed by AI utility bill payment line: card digits that never reach the model, the recording or the logs.
Seen in a build
One of 4 recipes composed by AI website chat agent: the phone agent in a chat bubble, with the API token kept off the page.
Seen in a build
One of 8 recipes composed by Appointment confirmation by SMS: a text built by the handler and a reply that calls the customer back.
Seen in a build
One of 5 recipes composed by Bilingual AI support line: English and Spanish from one code path, switching mid-sentence.
Seen in a build
One of 4 recipes composed by Voice AI latency lab: the same agent under several models and voices, timed from the platform's own stamps.
Seen in a build
One of 3 recipes composed by Win/loss interview line: post-call extraction validated against a schema you own.