Sub topic 7
The starting topic: routing the first request
This chapter assumes you have read the earlier chapters on the structure of an Agent Script file, variables, and topics. You should know that a script is made of named blocks, that a topic scopes one area of the agent's work, and that variables hold state between turns. The code in this chapter is an illustrative sketch of the shape of the language. Check exact keys and spellings against the current Agent Script documentation before you use them.
What the starting topic is for
Every conversation has to begin somewhere. When a customer sends the first message, the agent has not yet chosen which topic should handle it. The starting topic makes that choice.
In Agent Script the starting topic is declared with start_agent instead of topic. It is the entry point of the script. Its job is routing: read the request, decide which topic fits, and hand the conversation over.
Keep two ideas separate:
- Which topic to pick is a judgement. Customers phrase things in many ways, so the model decides.
- Where each route leads is a rule. The script fixes the destination, and the model cannot invent one.
This is the same split between model judgement and fixed rules that runs through the whole tutorial. The starting topic puts the judgement in one narrow place and keeps everything around it fixed.
Anatomy of a starting topic
Here is a minimal starting topic, built from the examples in the plan.
# Illustrative sketch: a starting topic that can route to one topic.
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_status
topic order_status:
description: "Answer questions about an existing order"It has four parts.
- The header.
start_agent topic_selector:names the block. A script has one starting topic, because a conversation has one entry point. The name is yours to choose, andtopic_selectoris a common convention. - The description. This is a short statement of the block's purpose. For ordinary topics, descriptions help the model decide when a topic applies. Write them with that reader in mind.
- The instructions. Under
reasoning, theinstructionsblock holds the text the model sees. The->marks a procedural block, and each line starting with|is natural-language prompt text. - The actions.
go_to_order_status: @utils.transition to @topic.order_statusdefines a tool the model may call. The name on the left is what the model sees. The right side says what the tool does: move to theorder_statustopic.
How the first request flows
The diagram shows what happens to one message. The model chooses among the transitions it has been given. The script decides what each transition does.
Each arrow out of the model's choice corresponds to one transition action in the script. If you do not define a transition to a topic, the model cannot reach it from here.
Routing to several topics
Real agents have more than one destination. You add one transition per topic.
# Illustrative sketch: three destinations and an explicit fallback instruction.
start_agent topic_selector:
description: "Route the customer to the right topic"
reasoning:
instructions: ->
| Work out what the customer needs.
| Use go_to_order_status for questions about an existing order.
| Use go_to_returns for return or refund requests.
| If the request fits neither, ask one short question to clarify.
actions:
go_to_order_status: @utils.transition to @topic.order_status
go_to_returns: @utils.transition to @topic.returns
topic order_status:
description: "Answer questions about an existing order"
topic returns:
description: "Start or check a return or refund"The instructions here name the actions explicitly and say what to do when nothing fits. The fallback line matters. Without it, the model may pick a poor match, or answer the question itself without any topic-level rules.
Where the model's judgement ends
A transition exposed as a tool is a choice for the model. The script limits that choice in three ways:
- Destinations are fixed.
@topic.order_statusis written into the script. The model cannot send the conversation to a topic you did not list. - The menu is fixed. The model picks only from the actions defined in the block.
- The text is under your control. What the model reads about each route comes from your descriptions and instructions.
What remains probabilistic is the match between the customer's wording and the route. That is why the quality of your descriptions and instructions matters more here than almost anywhere else.
Making routing less dependent on the model
Sometimes you already know where the conversation should go, and asking the model adds risk for no benefit. The procedural form of instructions lets you use script state. For example, you might store a verified customer flag in a variable and change what the starting topic tells the model.
# Illustrative sketch: state changes what the starting topic offers the model.
variables:
is_verified: mutable boolean = False
start_agent topic_selector:
description: "Route the customer to the right topic"
reasoning:
instructions: ->
if @variables.is_verified == False:
| Tell the customer they must verify their identity first.
| Use go_to_verification.
else:
| Work out what the customer needs and pick a matching transition.
actions:
go_to_verification: @utils.transition to @topic.verification
go_to_order_status: @utils.transition to @topic.order_statusThe if runs in the script, not in the model. The model sees only the lines from the branch that applies. A later chapter covers conditions in detail, and the chapter on action availability shows how to hide go_to_order_status entirely until the customer is verified. Hiding an action is stronger than asking the model not to use it.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The model picks the wrong topic for borderline requests | Two topic descriptions overlap | Rewrite descriptions so each names what it handles and what it does not |
| The agent answers directly without routing | Instructions do not tell the model to use the transitions | Name each transition in the instructions and say when to use it |
| The agent loops on unclear requests | No fallback instruction | Add a line that asks one clarifying question |
| A topic is never reached | No transition to it exists in the starting topic, or its description is vague | Add the transition and sharpen the description |
| Routing differs between runs for the same message | The choice is left entirely to the model | Add a condition on a variable, or remove actions that should not be offered yet |
| Every request routes to the first listed topic | Instructions list the topics in a way that implies a default | Remove ordering cues and describe each route by its purpose |
Design guidance
- Keep the starting topic thin. It should route and nothing else. Put business rules in the destination topics, where they are easier to test.
- Write one-purpose descriptions. A description such as "Answer questions about an existing order" is clear. "Handle customer things" gives the model nothing to compare.
- Name transitions after destinations.
go_to_order_statustells both the model and the next reader what the action does. - Handle the unclear case on purpose. Decide whether the agent should ask a question, offer a menu of options, or hand off to a person.
- Prefer a rule when you have one. If a variable or earlier step determines the route, use a condition. Use the model only for the part that really depends on language.
Summary
The starting topic is the single entry point of a script. It contains instructions and transition actions, and the model uses them to choose among a fixed set of destinations. The model's choice is a judgement about wording, and the destinations and the menu are rules in the script. Clear descriptions, a stated fallback, and conditions on state keep that judgement narrow and predictable.
Exercise
A script has a startagent block with transitions to orderstatus and returns. Testing shows that "I want my money back for order 1182" sometimes goes to order_status. Name two changes you could make in the script to improve routing, and say which part of the behaviour each change affects.
Show answer
First, rewrite the topic descriptions so they do not overlap, for example making returns say it handles refunds and money-back requests and orderstatus say it handles tracking and details of an existing order. This improves the model's judgement about which route fits. Second, add a line to the starting topic's instructions that says to use goto_returns for return or refund requests, naming the transition explicitly. This tells the model which menu item matches which wording. Both changes affect the probabilistic part, the match between wording and route. The destinations stay fixed by the script either way.
Exercise
You want customers who have not verified their identity to reach only a verification topic from the starting topic. Which two techniques from this chapter and the next chapters apply, and why is one stronger?
Show answer
One technique is an if/else in the procedural instructions that tells the model to use only gotoverification while isverified is False. The other is making the gotoorderstatus action unavailable until is_verified is True. The second is stronger because the model cannot call an action it is not offered, whereas an instruction can be ignored or misread.