Sub topic 7
The starting topic: routing the first request
This chapter assumes you have read the earlier chapters on script structure, variables and topics. You should know that a topic is a scoped block with a description and its own instructions. You should also be comfortable reading indentation-based syntax.
What the starting topic does
Every conversation has to begin somewhere. In Agent Script, the start_agent block is that place. It is a special topic that receives the customer's first request and decides which regular topic should handle it.
The starting topic usually does not answer questions itself. Its job is routing. Keeping that job separate means each regular topic can stay focused on one kind of request.
The examples in this chapter are illustrative sketches. Check exact keys against the current Agent Script documentation.
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_statusReading the example
The block has three parts.
- The header and description.
start_agent topic_selectornames the block. Thedescriptiontells the model what this block is for. - The instructions. The line starting with
|is prompt text. It is natural language that goes to the model. Here it asks the model to judge what the customer wants. - The actions.
go_to_order_statusis a transition exposed as a tool.@utils.transition to @topic.order_statusmeans the model may call it, and if it does, the conversation moves to theorder_statustopic.
Who decides what
The model and the script each make one decision here.
| Decision | Made by | Why |
|---|---|---|
| Whether the request is about an order | The model | Understanding free-form language is what the model is good at |
| Which topic the transition leads to | The script | The destination is written in the script and cannot change |
| Which transitions are on offer | The script | Only transitions you declare can be chosen |
The model cannot invent a destination. It can only pick from the transitions you expose. This keeps routing flexible where the customer's wording varies and fixed where the structure matters.
Adding more destinations
To route to more topics, add one transition per destination. Give each a clear name, since the model reads the names and descriptions when it chooses.
start_agent topic_selector:
description: "Route the customer to the right topic"
reasoning:
instructions: ->
| Decide whether the customer is asking about an order or about a return.
actions:
go_to_order_status: @utils.transition to @topic.order_status
go_to_returns: @utils.transition to @topic.returnsEach destination topic must exist in the script. A transition that points to a topic you never defined is an error.
Common errors
- Answering in the starting topic. If the starting topic holds detailed instructions for a task, routing and task logic get mixed. Move that logic into a regular topic.
- Vague routing instructions. If the prompt does not say what distinguishes one topic from another, the model may pick the wrong one. Name the differences.
- Overlapping topic descriptions. Two topics whose descriptions cover the same requests make the choice ambiguous.
- Putting required checks in routing. Routing is a model decision. Checks that must always happen, such as confirming an order number, belong in the destination topic's conditional logic, where they do not depend on the model.
Exercise
A script has a startagent block with one transition, gotoorderstatus. A customer asks about returning an item. Which part of the system decides where the conversation goes, and what is a sensible fix?
Show answer
The model chooses among the transitions the script exposes, and only gotoorderstatus exists, so the model cannot send the customer to a returns topic. The fix is to define a returns topic and add a second transition, such as goto_returns: @utils.transition to @topic.returns, and to update the routing instructions so they say when each applies.
Exercise
Why should an order-number check live in the order_status topic instead of the starting topic's prompt text?
Show answer
Routing relies on the model's judgement, so an instruction in the starting topic may be skipped or misapplied. An if/else in the destination topic's instructions runs every time and does not depend on the model remembering to ask.