Sub topic 3
Anatomy of an Agent Script file
This chapter assumes you know what an LLM-based agent is, and that you are comfortable with prompts, actions, and conversation turns. You should also be able to read indentation-based syntax such as YAML or Python. The examples are illustrative sketches. Check exact keys against the current Agent Script documentation.
The big picture
An Agent Script file describes one agent. It is a set of named blocks. Each block has one job, and together they split the work between fixed logic and model judgement.
| Block | Purpose |
|---|---|
| `system` | Agent-wide settings, such as the base instructions |
| `variables` | State the agent keeps across turns |
| `start_agent` | The starting topic, which routes the first request |
| `topic` | One block per area of work, such as order questions |
Later chapters cover each block in detail. Here the aim is to recognise the shape of a file and know where each kind of decision belongs.
A minimal file
# Illustrative sketch of the overall shape of an Agent Script file.
# Check exact keys against the current Agent Script documentation.
system:
instructions: "You are a support agent for order questions."
variables:
order_id: mutable string = ""
start_agent topic_selector:
description: "Route the customer to the right topic"
topic order_status:
description: "Answer questions about an existing order"Read it from the top.
systemholds settings that apply to the whole agent. Here that is one sentence describing the agent's role.variablesdeclaresorder_idas a mutable string with an empty default. Mutable means the script can change it during the conversation.start_agent topic_selectoris the entry point. Every conversation begins here.topic order_statusis a scoped area of behaviour with its own description.
Notice the indentation. Nesting shows which settings belong to which block, as in YAML.
How a request flows through the blocks
The starting topic receives the first message and decides where it goes. The chosen topic then runs its own instructions, reading and updating variables as it works. The system settings apply throughout.
Where decisions belong
The reason for this structure is to separate two kinds of decisions.
- Fixed logic is the same every time. Examples are checking whether
order_idis empty, or sending the conversation to a particular topic. The script writes these as ordinary conditions and transitions. - Model judgement is flexible. Examples are interpreting what the customer means, or wording a friendly reply. The script leaves these to the model through natural-language text.
Each topic can contain both. A topic's description tells the model what the topic is for. Its instructions then mix prompt text with procedural logic. You will see this in the instructions chapter.
# Illustrative sketch: fixed logic decides which prompt text the model sees.
topic order_status:
description: "Answer questions about an existing order"
reasoning:
instructions: ->
if @variables.order_id == "":
| Ask the customer for their order number before doing anything else.
else:
| Help the customer with order {[email protected]_id}.The if runs in the script, not in the model. The model never has to remember to ask for the order number. It only sees the line that matches the current state.
Common errors
- Putting everything in
system. A long prompt there brings back the unpredictability you are trying to remove. Keep it to agent-wide guidance. - Forgetting to declare a variable. A topic that reads
@variables.order_idneeds that variable declared in thevariablesblock first. - Overlapping topic descriptions. The model uses descriptions to choose between topics. Vague or similar descriptions make routing unreliable.
- Broken indentation. A line indented at the wrong level belongs to a different block, or to none.
Exercise
A script checks whether order_id is empty before the model replies. Which part of the file holds the stored value, and which part holds the check?
Show answer
The variables block declares and stores order_id. The check is an if condition inside the topic's instructions, so it runs in the script and does not depend on the model.
Exercise
Name the block that every conversation enters first, and say what it does.
Show answer
The start_agent block (here topic_selector). It receives the first request and routes it to the appropriate topic.