Sub topic 11
Transitions: moving between topics
This chapter assumes you have read the earlier chapters on topics, the starting topic, instructions and conditions. You should be comfortable reading an indentation-based script and know what a variable is.
What a transition is
A transition moves the conversation from one topic to another. The destination is always named in the script. The only open question is who decides to make the move. Agent Script gives you two ways to answer it, and the choice sets how deterministic the move is.
| Style | Who decides | Destination | Typical use |
|---|---|---|---|
| Model-chosen transition | The model, by picking a tool | Fixed by the script | Routing a free-form request |
| Script-driven transition | The script, inside a condition | Fixed by the script | Enforcing a required order |
The syntax below is an illustrative sketch. Check exact keys against the current Agent Script documentation.
Model-chosen transitions
A transition can be exposed to the model as a tool. The model reads the customer's message and decides whether to use it. It cannot pick a different destination, because the target is written into the script.
# Illustrative sketch: a transition the model may choose.
start_agent topic_selector:
description: "Route the customer to the right topic"
reasoning:
instructions: ->
| Decide whether the customer is asking about an order.
actions:
go_to_order_status: @utils.transition to @topic.order_statusHere go_to_order_status is the tool name the model sees. @utils.transition to @topic.order_status is the fixed part: whenever the tool is used, control passes to the order_status topic.
This style fits the starting topic well. Deciding what the customer wants is a judgement call, which models handle well. Where the conversation goes next is not left open.
Script-driven transitions
Sometimes the model should not have a say. If a customer must verify their identity before any refund, a prompt that asks the model to check first can still be skipped. Putting the move inside a condition removes that risk. The model never gets to choose, so the step runs the same way every time.
# Illustrative sketch: the script moves on when state says so.
topic identity_check:
description: "Verify the customer before continuing"
reasoning:
instructions: ->
if @variables.verified == True:
transition to @topic.refund
else:
| Ask the customer to confirm their email address.The condition reads a variable, and a variable is only changed by the script or by an action result. The prompt text is shown only while verified is false.
Choosing between the two
Use a model-chosen transition when the question is "what does the customer want?" Use a script-driven transition when the question is "has the required step happened?"
You can combine them. The starting topic offers model-chosen routes to order_status and refund. The refund topic then checks a variable and sends the customer back to identity_check if verified is false. Routing stays flexible, and the guardrail stays fixed.
Common errors
- Relying on the prompt for a must-happen step. "Always verify first" is a request, not a rule. Use a condition and a transition.
- Naming a topic that does not exist. The destination in
@topic.namemust match a declared topic exactly. - Looping with no exit. Two topics that each transition to the other on a condition that never changes will bounce forever. Make sure some action or variable change can make the condition resolve.
- Forgetting state. A script-driven transition is only as reliable as the variable it reads. If nothing ever sets
verified, the customer stays in the identity topic.
Exercise
A customer must accept the terms before an order can be cancelled. Should the move from the terms topic to the cancel_order topic be model-chosen or script-driven, and what would it depend on?
Show answer
Script-driven. The move should sit in a condition that reads a variable such as terms_accepted, and transition to cancel_order only when it is true. A model-chosen transition would let the model skip the required step.
Exercise
In the model-chosen example, what part of go_to_order_status: @utils.transition to @topic.order_status can the model influence?
Show answer
Only whether to use the tool. The destination, order_status, is fixed by the script.