Sub topic 11
Transitions: moving between topics
This chapter covers how an Agent Script agent moves from one topic to another. It assumes you have read the chapters on topics, the starting topic, instructions, and conditions. You should be comfortable reading indentation-based configuration and simple if/else logic. The code samples are illustrative sketches. Check exact keys and syntax against the current Agent Script documentation before you use them.
What a transition is
A transition moves the conversation from the current topic to another topic. Each topic has its own description, instructions and actions. A transition changes which of those the model works with on the next step.
Moving between topics is a routing decision, and routing is where agents often go wrong. A purely prompt-driven agent might stay in the wrong topic, jump early, or skip a step you wanted. Agent Script lets you decide how much of that choice the model keeps. The destination of a transition is always written in the script. The model never invents a topic name. What varies is who decides when the transition happens.
There are two styles:
- Model-chosen transitions. The script exposes a transition as a tool. The model decides whether to use it, based on the conversation. The script fixes only where it leads.
- Script-driven transitions. Fixed logic, such as an if/else on a variable, performs the transition. The model is not asked.
Model-chosen transitions
The starting topic is the usual place to see this style. It listens to the first request and picks a destination.
# 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_statusRead the action line in three parts:
go_to_order_statusis the name the model sees for this tool.@utils.transitionis a built-in utility that performs a topic change.@topic.order_statusis the fixed destination.
The model may call go_to_order_status, or it may not. If the customer's message does not match, the model can ask a clarifying question instead. The script guarantees one thing: if the model routes, it routes to order_status.
Write the tool name and the instruction text so that the model can tell when to use the tool. A name like go_to_order_status carries meaning. A name like route1 does not.
Script-driven transitions
Sometimes you do not want the model to choose. For example, a customer must be verified before any account topic runs. Put the check in the script and make the move yourself.
# Illustrative sketch: the script moves the conversation, not the model.
topic account_help:
description: "Help with account questions"
reasoning:
instructions: ->
if @variables.is_verified == False:
transition to @topic.verify_identity
| Help the customer with their account question.The if runs every time this topic is entered, before any prompt text reaches the model. If is_verified is false, the conversation moves to verify_identity and the model never sees the account instructions. This is the deterministic form of routing.
The exact way to write a script-driven transition may differ from this sketch. Check how the current documentation spells it.
Choosing between the two styles
Use this table as a starting point.
| Question | Model-chosen | Script-driven |
|---|---|---|
| Who decides when to move? | The model, from the conversation | The script, from variables or earlier results |
| Best for | Interpreting free-form intent | Enforcing prerequisites and required order |
| Failure mode | The model does not call the transition when it should | The condition is wrong or the variable is stale |
| Testing | Needs many varied phrasings | Needs a few state combinations |
A good rule: if the decision depends on what the customer meant, let the model choose. If it depends on facts the script already holds, such as a verified flag, use fixed logic.
Transitions and variables
Transitions work best together with variables. Moving to a new topic does not erase what the agent knows. Variables live for the whole conversation, so a value set in one topic can be read in the next.
A common pattern has three steps:
- A topic collects a value and stores it in a variable.
- The script checks the variable.
- The script transitions to the topic that needs the value.
# Illustrative sketch: state set in one topic drives a transition from another.
variables:
order_id: mutable string = ""
is_verified: mutable boolean = False
topic verify_identity:
description: "Confirm who the customer is"
reasoning:
instructions: ->
if @variables.is_verified == True:
transition to @topic.order_status
| Ask the customer for their email address and confirm it.Here the check on is_verified sends a verified customer onward without asking again. An unverified customer gets the prompt text. Because the check sits in the script, it does not depend on the model remembering the earlier result.
What the model sees after a transition
A transition changes the active topic. The model then works from the new topic's description, instructions and available actions. It does not continue using the old topic's instructions.
This has practical consequences:
- Put needed context in variables. Do not rely on the model recalling something from a previous topic's instructions. If the destination topic needs the order number, read it from a variable.
- Write each topic so it stands alone. Assume the model arrives with the conversation history but not with the previous topic's rules.
- Check what the old topic left unfinished. If a topic was halfway through a task, the new topic must either finish it or deliberately drop it.
Order matters inside instructions
In a procedural instructions block, lines run top to bottom. A script-driven transition placed before the prompt text stops that text from being used. A transition placed after it may still let the model see the earlier lines first, depending on how the platform handles the step. Put prerequisite checks at the top of the block so the behavior is predictable, and confirm in testing which lines the model actually receives.
Design guidance
Keep transitions simple to reason about.
- One reason per transition. A transition with a single clear trigger is easy to test. If you need several triggers, give each its own named transition.
- Name destinations by purpose.
go_to_refund_reviewtells the model and the next reader what will happen. - Avoid loops without exit conditions. If topic A sends to B when a value is empty and B sends back to A when it is still empty, the conversation can bounce. Make sure each topic either fills the value or ends the exchange.
- Provide a way back. If a customer changes their mind mid-flow, they need a route to the starting topic or a general help topic.
- Do not duplicate routing everywhere. Keep general routing in the starting topic. Add transitions elsewhere only when the flow needs them.
Common errors
- Assuming the model will always route. A model-chosen transition is optional. If a step must happen, use a script-driven transition.
- Misspelled or missing destinations. The destination must match a topic that exists in the script. A typo means the transition cannot work.
- Unset variables. A condition that reads a variable nothing ever sets will always take the same branch. Declare a default and make sure some step updates it.
- Overlapping descriptions. If two topics have similar descriptions, the model may pick the wrong transition. Make each description say what is in scope and what is not.
- Hidden dependence on conversation memory. A destination topic that works only if the model remembers an earlier answer is fragile. Store that answer in a variable.
A flow in outline
The diagram shows a typical flow. The starting topic routes by model choice. The account topic checks verification with fixed logic.
Testing transitions
Test each transition in the way it can fail.
- Model-chosen transitions. Write several phrasings of the same request, including vague and misspelled ones. Check that the right transition is used and that unrelated requests do not trigger it.
- Script-driven transitions. Test each state: variable unset, variable false, variable true. Check that the conversation lands in the expected topic each time.
- Round trips. Follow a path that leaves a topic and returns. Confirm that variables kept their values and that the agent does not repeat questions.
- Dead ends. Try to reach a topic with no exit. Fix any you find.
If behavior is wrong, first decide which style the transition uses. A wrong model-chosen transition usually calls for better descriptions or tool names. A wrong script-driven transition usually calls for a fix to the condition or to the variable it reads.
Exercise
A support agent must confirm the customer's identity before any refund topic runs. A teammate proposes adding a model-chosen transition to verify_identity at the top of the refund topic, with the instruction "Verify the customer first." Explain why this may fail, and describe a better design.
Show answer
A model-chosen transition is optional. The model may skip it, call it late, or decide the customer is already verified, so the refund topic can run without verification. A better design keeps a boolean variable such as is_verified, default False. At the top of the refund topic's instructions, add an if check that performs a script-driven transition to verify_identity when the variable is false. The verify topic sets the variable on success and moves back to the refund topic. The check runs every time, so the order does not depend on the model.
Exercise
Topic A moves to topic B when order_id is empty. Topic B asks for the order number but moves back to A whenever the customer's reply is unclear, without setting order_id. What problem can this cause, and how would you fix it?
Show answer
The conversation can bounce between A and B forever, because the condition that triggers the move never changes. Fix it by making B either set order_id when the reply is valid or stay in B and ask again, and by adding an exit, such as a limit on attempts tracked in a variable, that sends the customer to a help topic or ends the exchange.