Sitemap

Member-only story

Agent Script in Depth — Part 3: Variables and Gates

12 min readOct 30, 2026

--

Series: Agent Script in Depth — writing Agentforce agents as code

Press enter or click to view image in full size

Part 2 ended on an uncomfortable truth. Case Desk could add comments to cases, and its instructions said to show the user the exact text and wait for confirmation first. But an instruction is a suggestion. Nothing in the agent actually stopped the model from calling add_comment the moment the user mentioned a comment. Most of the time it would behave. Some of the time it wouldn't, and "some of the time" is not a property you want on a write.

This part turns that suggestion into a guarantee. The tool is available when, a guard that decides, on every pass through the reasoning loop, whether a tool exists at all from the model's point of view. Combined with a few well-chosen variables and one new block, after_reasoning, it lets Case Desk enforce a rule that instructions alone never could: a comment can only be written in a later turn than the one in which its draft was shown, and only with the exact text the user saw.

Along the way, we’ll look more closely at the two other ideas that make gates work: how the model fills variables from conversation, and how conditional instructions keep what the model is told consistent with what it’s allowed to do.

Who sets a variable?

--

--

Director of Salesforce Practice | Salesforce Certified AI, System & Application Architect | Claude Certified Architect | 40x Certified | All Star Ranger |

See more from me