Sub topic 12
Limiting which actions the model can choose
This chapter assumes you have read the earlier chapters on topics, variables, conditions, and actions. You should know that a topic lists actions the model may call, and that variables hold state between turns.
Why restrict actions
Listing an action in a topic makes it a tool the model can call whenever it judges that useful. That is fine for harmless lookups. It is a problem for actions with side effects, such as issuing a refund or cancelling an order. If the prompt says "only refund verified customers" and the action is still available, the model can still call it. Prompt wording is a request, not a guarantee.
The fix is to control the tool list itself. If the action is not offered to the model on a given turn, the model cannot call it, however the customer phrases the request.
Availability conditions
You attach a condition to an action so it is offered only when the condition is true. The condition reads script variables, which the model cannot overwrite by saying something persuasive. Only the script, or an action's declared outputs, sets them.
# Illustrative sketch. Check exact keys against the current Agent Script documentation.
variables:
order_verified: mutable boolean = False
topic order_status:
description: "Answer questions about an existing order"
reasoning:
instructions: ->
if @variables.order_verified == False:
| Verify the customer's order number first.
else:
| The order is verified. Help with refunds if asked.
actions:
lookup_order: @actions.lookup_order
set @variables.order_verified = @outputs.found
issue_refund: @actions.issue_refund
available when @variables.order_verified == TrueTwo things happen here. lookup_order is always offered, and its output sets order_verified. issue_refund appears in the model's tool list only once that variable is true.
Keep the prompt and the tool list in agreement
The conditional in the instructions and the availability condition use the same variable. This is deliberate. When the order is unverified, the model is told to verify it and also has no refund tool. When it is verified, the prompt and the tool list change together. If the two disagree, the model may be told to do something it has no tool for, and it may improvise or give a wrong answer.
Common errors
- Relying on prompt text alone. "Never refund without verification" in the instructions does not remove the tool. Use an availability condition for anything with side effects.
- Conditions on model-controlled values. If the condition reads a variable the model fills in freely, the model can satisfy it without real verification. Base conditions on variables set by action outputs or script logic.
- Forgetting to update the variable. If nothing ever sets
order_verifiedto true, the action stays hidden and the agent seems unable to help. Check that a path to true exists. - Hiding too much. Each hidden action reduces what the agent can do. Restrict only actions where order or permission matters, and leave low-risk actions open.
Choosing between mechanisms
| Need | Mechanism |
|---|---|
| Guide wording or tone | Prompt text |
| Force a fixed next step | A direct action call or transition in the script |
| Allow a step only after a precondition | Availability condition |
| Let the model decide freely among safe options | Plain action listing |
Availability conditions sit in the middle. They do not force a step. They only make a step possible, and the model still chooses whether to use it.
Exercise
A topic lists a cancel_order action. The instructions say "Only cancel orders that have not shipped," but a customer with a shipped order still got a cancellation. What change makes this reliably impossible, and why does the prompt line fail?
Show answer
Store the shipping status in a variable, set from the lookup action's output, and add an availability condition such as "available when @variables.ordershipped == False" to cancelorder. The prompt line fails because it only asks the model to behave. The action stays in the tool list, so the model can call it anyway. With the condition, the tool is absent whenever the order has shipped.