Recipes← all recipesView on GitHub

Walk a caller through steps they cannot skip

AI Agentsguided AI conversation flow

Expose only the next allowed AI agent tool at each step so callers cannot move backward or skip ahead.

contexts

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.