Agent Script Common Patterns
This section provides common patterns for building agents with Agent Script. Each pattern focuses on a specific technique you can use to make your agents more reliable and effective.
These patterns are written in Agent Script as it appears in Script view, so you can easily reuse them in your own agent by copying and pasting. However, the patterns apply in Canvas view, as well.

| Pattern | Description |
|---|---|
| Action Chaining & Sequencing | Run multiple actions in a guaranteed sequence |
| Conditionals | Use if/else logic to control instructions, actions, and transitions |
| Context Engineering | Apply context engineering strategies with your Agentforce agents |
| Fetch Data | Run actions to retrieve data before the LLM begins reasoning |
| Filtering with Available When | Control when topics and actions are visible to the reasoning engine |
| Required Topic Workflow | Guarantee users pass through required steps before proceeding |
| Resource References | Reference variables and actions directly in reasoning instructions |
| System Overrides | Override global system instructions to change behavior per topic |
| Topic Selector | Set up effective topic routing in the start_agent block |
| Transitions | Move execution between topics with @utils.transition to |
| Variables | Store and use state effectively across topics |
When building agents with Agent Script, keep these principles in mind:
- Start with simple reasoning instructions. Start with the fewest instructions necessary for an agent to perform as expected. Add instructions as needed as you preview user conversations for different use cases, and then test for regressions between each change.
- Use good names and descriptions. Clear names for topics, actions, and variables help your agent make better decisions.
- Good names and descriptions are specific, distinct, and clearly related to the agent's task.
- Review names and descriptions for other topics, actions, and variables in your agent to ensure that the names and descriptions are distinct and don't overlap.
- Use plain language that end users are likely to use and understand, not technical terms. This makes it easier for the agent to match a user's question or request to a relevant topic, action, or variable.
- Use language consistently throughout. When language is ambiguous, an agent can apply instructions inconsistently or incorrectly. For example, instead of naming an action “Get Client Info” and naming another action "Verify Customer," use the term “customer” in both.
- Add determinism strategically. Balance natural language instruction with deterministic logic expressions to get the most out of your agent's capabilities. Add logic for business workflows to increase predictable behavior.
- Reference resources directly in reasoning instructions. "@ mention" references to topics, actions, and variables to give the LLM explicit guidance. References to resources increase the likelihood that your agent will use the resource as intended.