When building instructions for an AI Agent in Salesforce, you are actually writing two completely different types of code in the same list. Logic lines act like traditional code (fetching data, evaluating true/false). Prompt lines act like natural human English that the LLM will read. You use conditions to decide which prompt lines actually get sent to the model.
Imagine an agent checking a system outage. You use three logic lines to fetch and store the outage status. Then, you write two conditional prompt lines. One says, "Give the confirmed estimate," and the other says, "Say no estimate is available." Based on the logic lines, only one of those prompt lines will ever reach the model to guide its response.
Core Concepts of Agent Instructions
- Logic Instructions: These are deterministic or conditional expressions that execute actions (like calling an Apex method) and set variables. The LLM does not "read" these.
- Prompt Instructions: This is the actual text that becomes part of the prompt sent to the LLM (like Claude).
- Syntax Markers: The pipe character
|marks text as a prompt. The arrow->introduces a condition. - Execution Order: Instructions resolve strictly top to bottom. A decision made early cannot be undone by a line further down.
- Procedural Blocks: You can open specific blocks for logic that must run and resolve before the AI begins its reasoning phase.
- Subagent Overrides: If a specific subagent needs a different persona (e.g., a "Sales Agent" vs a "Support Agent"), you can use per-subagent system instruction overrides without breaking the global rules.
Code Example: Logic vs. Prompt
reasoning:
instructions:
- run @actions.get_outage_status ... ← LOGIC (Executes action)
- set @variables.is_confirmed = ... ← LOGIC (Stores result)
- @variables.is_confirmed == True -> ← CONDITION (If true...)
| Give the confirmed estimate. ← PROMPT (Sent to LLM)
- @variables.is_confirmed == False -> ← CONDITION (If false...)
| Say no estimate is available yet. ← PROMPT (Sent to LLM)
In the execution above, only ONE of those prompt branches will ever be sent to the model.
| means prompt. Anything after a pipe is English for the model to read. Everything else is logic that runs first.
Do not describe the entire instruction list as "the prompt." Half of that list (the logic) never reaches the AI model. If you say, "these lines resolve into a prompt," you will sound like a seasoned AI architect.
๐งญ 360 Card: Instructions Architecture
- The Rule: Put certainty (data fetching/decisions) in logic lines and tone/guidance in prompt lines. Never mix the two responsibilities.
- The Gain: The same instruction list dynamically carries both the hard system decision and the soft wording for the AI, keeping everything in a readable order.
- The Price: It looks like standard prose but behaves like strict code. Developers new to Agentforce misread this constantly.
- The Limits: Whitespace is structural (like Python or YAML). Indentation errors are real compile errors.
- The Mirror: Alternatively, you could write a single, massive prose paragraph. It is readable, but it forces the LLM to make the hard logic decisions, which leads to hallucinations.
Core Q&A
They sit in the exact same list but perform entirely different jobs:
- Logic instructions are deterministic or conditional expressions. They run Apex actions and set system variables.
- Prompt instructions are the text that actually becomes part of the final prompt. They are always marked with a pipe
|. - Conditions are introduced with an arrow
->. They act as gates to determine whether the prompt text beneath them is included in the final payload. - Everything resolves strictly from top to bottom.
You use the per-subagent system instructions override. This allows one specific specialist (e.g., an Escalation Agent) to depart from the global instructions without you having to write messy, qualifying logic in the main instruction list.
No. Salesforce official guidance stresses that shorter instructions produce more accurate results. When you give an LLM too many rules in a single prompt, it suffers from "attention decay" and will likely ignore some of your instructions. Keep your prompt lines concise and rely on logic lines to handle complex routing.