Sub topic 10
Actions: calling backend capabilities
This chapter assumes you have read the earlier chapters on topics, variables, instructions and conditions. You should be comfortable with if/else logic and with the idea of calling a function with inputs and getting outputs back.
What an action is
An action is a backend capability the agent can call, such as looking up an order, creating a case or checking a balance. The model cannot read your database. It can only work with what an action returns.
An action has three parts:
- A name the script uses to refer to it.
- Inputs, the values the backend needs.
- Outputs, the values the backend returns.
The backend itself, for example a flow or an API, is outside the script. The script only declares how to reach it and what goes in and out.
Declaring an action
You declare actions inside a topic, so each topic has only the capabilities it needs. This sketch is illustrative. Check exact keys against the current Agent Script documentation.
# Illustrative sketch: an action declared inside a topic.
topic order_status:
description: "Answer questions about an existing order"
actions:
get_order_status:
description: "Look up the status of an order"
inputs:
order_id: string
outputs:
status: string
target: "flow://GetOrderStatus"The description matters. The model reads it when deciding whether the action fits the request.
Two ways to run an action
An action can run in two ways, and the difference decides who is in control.
| Approach | Who decides | Typical use |
|---|---|---|
| Script runs it | Fixed logic in the script | Steps that must happen, such as a lookup before answering |
| Model chooses it | The model, as a tool | Optional steps, such as offering a refund |
Running an action from the script
In a procedural instructions block, you can run an action directly, pass it variables and store the result. The model is not asked whether to call it.
# Illustrative sketch: the script runs the lookup, then shapes the prompt.
topic order_status:
reasoning:
instructions: ->
if @variables.order_id == "":
| Ask the customer for their order number.
else:
run @actions.get_order_status
with [email protected]_id
set @variables.status = @outputs.status
| The order status is {[email protected]}. Explain it to the customer.The lookup runs whenever an order number is present. It does not depend on the model remembering to call it. The result is saved in status, so later turns and later conditions can use it.
Letting the model choose an action
You can also list an action under reasoning: actions: so the model may call it as a tool.
# Illustrative sketch: the model may call this action when it judges it useful.
actions:
check_status: @actions.get_order_status
with [email protected]_idHere the model decides whether and when to call it. Use this for optional steps. Use script-run actions for required ones.
Common errors
- Passing an empty input. Running an action before its variable is filled makes the call fail or return nothing. Guard the call with a condition, as in the example above.
- Relying on the model for a required call. If the lookup must happen, run it from the script. A model-chosen action can be skipped.
- Vague descriptions. The model picks tools by description. Two actions with similar descriptions invite wrong choices.
- Forgetting to store outputs. An output that is not saved to a variable is gone after the turn. Save anything you need later.
Exercise
A refund action must only run after the order status lookup has returned "delivered". Which parts would you put in the script, and which would you leave to the model?
Show answer
Run the lookup from the script and store its output in a variable. Add a condition on that variable, such as status equal to "delivered". Offer the refund action only inside that branch. The model can still decide how to word the conversation and whether the customer actually wants the refund. The required order of steps and the eligibility check stay in the script.