Agent Script Pattern: Action Chaining and Sequencing
Run multiple actions in a guaranteed sequence.
Action chaining can be implemented in multiple ways depending on when and how you need actions to execute. You can run actions sequentially in instructions, chain reasoning actions, or combine actions with transitions and conditionals.
Action sequencing ensures that one action can trigger another, creating reliable multi-step workflows without relying on the LLM to remember multiple steps.
Pattern Example: Get the user's order with one action, then immediately check return eligibility for that order in another action.
Call actions one after another in reasoning instructions. Both run deterministically before the prompt is sent to the LLM.
When you run an action in instructions, you must manually set variables for the inputs and outputs because the action is run before any reasoning takes place. See Actions Reference.
You can also store the output of one action in a variable, then use it as the input to another action, or as part of a subsequent prompt.
Define a follow-up action that automatically runs when the LLM calls an action.
Whenever the LLM calls my_action, the agent automatically runs other_action afterwards.
Run an action and then automatically transition to another topic.
Chain actions conditionally based on the results of previous actions.
- Use sequential instructions for deterministic flows: When you always want actions to run in a specific order.
- Use variables for action outputs: If your second action needs an output from the first action, store the first action's outputs in a variable and assign it as an input to the second action.
- Reference: Actions
- Reference: Reasoning Instructions
- Reference: Tools (Reasoning Actions)