Several factors can affect the reliability of agent answers, including the quality of input for each action and their execution conditions. Variables are a new structured memory type in Agentforce that can be exchanged between actions and leveraged as conditions to trigger agent actions and impose determinism, thereby enhancing control over these elements.
If you’re starting an Agentforce implementation and looking to enhance the reliability of agent answers, or add deterministic behavior to Agentforce processes, then this post is for you. We’ll discuss how to use variables and explore their potential impact on agent implementation and new use cases.
Core agentic capabilities
There are some essential capabilities that agents need to be able to complete the tasks required of them, including:
- Reasoning: Agents must be able to autonomously build a plan of action to solve a problem.
- Doing: Agents must be able to execute actions that can deeply impact existing environments.
- Knowing: Agents must possess the knowledge to discern which data is applicable to specific tasks. This process mirrors a long-term memory capability, analogous to accessing a vast library of information. Agents usually utilize retrieval augmented generation (RAG) techniques to extract pertinent data points for each task.
- Remembering: Agents need the ability to recall past interactions and data. Currently, they have limited memory and can forget important context and history.
To address the limitations on remembering, we’re introducing structured short-term memory variables. These variables provide persistent storage for critical information and enable deterministic action invocation by controlling execution conditions.
Variables roles and types
Variables are a type of structured memory whose value can be used as an input or output for actions. The state of a variable can determine whether a topic or action is triggered.
Variables are essential to two main capabilities of Agentforce:
- Persistent dynamic grounding: Variables allow agents to continuously update their understanding of the world while persisting important information. This persistence remains unaffected by any subsequent interactions. This method ensures that critical information, which can be unstructured data retrieved via RAG or structured data like user profile information, is maintained throughout the conversation.
- Determinism: Variables can be used as both input and output for actions. They can also be used to determine the conditions for actions or topics to be executed, based on the state of the variables. This allows a specific flow of information between actions as well as determinism in action execution. This is particularly crucial for security rules, where actions cannot be initiated if specific input variables, such as email, are not verified.
There are two types of variables in Agentforce:
- Context variable: These are system generated variables holding information about the user and the conversation sessions
- Custom variables: These can be instantiated by the user
The following table shows the differences between different types of variables. For more details about variables, please refer to this blog post.
Example use case
Let’s dig into variables further with an example use case: a customer-facing troubleshooting agent.
Customer requirements
The customer requires an agent to guide them through troubleshooting an issue, offering a human-like experience. This means that the agent shouldn’t provide all the troubleshooting steps in one go, but instead offer step-by-step instructions and the ability to navigate between steps (including going back to previously covered steps) based on the customer’s responses.
Challenge
The agent’s capacity for retaining troubleshooting steps across multiple interactions on the same issue is crucial for maintaining consistency. Given the agent’s limited memory and restricted number of interactions it can store, these steps could be lost if they were not preserved within agent variables.
Solution
Ground the planner service/conversation dynamically with these troubleshooting steps via agent variables.
Use variables to ensure a data flow
Creating a topic with two actions is necessary to maintain a consistent data flow. The first action is used to populate the variable, and the second action utilizes the variable during troubleshooting.
- Issue Resolution Steps action: This is the initial action, triggered by the agent’s first introduction to the issue. It employs Retrieval Augmented Generation to extract all necessary resolution steps. The resulting output is then allocated to the Steps to Follow variable.
- Use in the Middle of Solving an Issue action: This is an action based on a prompt that outputs the most likely next troubleshooting step to be used during the troubleshooting process. The agent is instructed to use this action while in the middle of solving an issue.
The action’s input includes the customer’s question and the troubleshooting steps that are then mapped to the Steps to Follow variable. It is important to note that this action won’t retrieve the troubleshooting steps, but will instead get them as input from the first action, the Issue Resolution Steps action.
An example prompt for this action is shown in the screenshot below.
The following diagram depicts the data flow between those two actions.
As the Use in the Middle of Solving an Issue action will always refer to the original troubleshooting steps retrieved by the Issue Resolution Steps action, then this data flow ensures that troubleshooting steps are maintained as coherent and available for the agent no matter the length of the conversation.
How to add variables as input and output to actions
Once a topic is created and its actions are assigned, all you have to do is open an action detail screen, where you can create or map the inputs or outputs of actions to variables.
Once a variable is created, you can see it in the left sidebar area under the X icon, as shown in the screenshot below.
Use filters to ensure the order of execution of actions
The current execution order of actions is determined by instructions. However, the non-deterministic nature of LLMs used by agents can lead to a different order. To ensure a deterministic order of execution, we can implement filters on variables.
- Issue Resolution Steps action can only be executed if the Resolution Step variable is empty
- Use in the Middle of Solving an Issue Action can only be executed if the Resolution Step variable is filled
In this case, we also need to add an Empty the Resolution Variable action that would empty the variable once the issue is completely solved
So, in this scenario, the Use in the Middle of Solving an Issue action has to wait for the Issue Resolution Steps action to fill in the variable before being executed, and in that way, we can enforce an order of execution.
How to add variables as filters to actions and topics
First, create the filter condition in the filter tab under the variable section, as shown in the screenshot below.
Then, assign the filters to an action or topic under the funnel icon on the action detail page, as shown in the screenshot below.
Use case summary
In summary, variables are crucial to enabling our example troubleshooting agent to solve customer problems by allowing for the following:
- Persistent dynamic grounding: Variables store troubleshooting steps, ensuring that they are available throughout the conversation, regardless of length or number of interactions. This prevents the agent from forgetting context.
- Data flow: Variables facilitate data flow between actions. For example, the Steps to Follow variable stores the retrieved troubleshooting steps from the Issue Resolution Steps action and provides them as input to the Use in the Middle of Solving an Issue action.
- Determinism: Variables can be used as filters to enforce a specific order of action execution. For example, the Use in the Middle of Solving an Issue action only executes if the Resolution Step variable is filled, ensuring the Issue Resolution Steps action runs first.
Agents are not chatbots: Don’t make every instruction deterministic
Ensure that you only enforce determinism in use cases where it is absolutely necessary, as the agent requires flexibility to effectively respond to customer requests. Here are some examples where determinism makes sense:
- Access control (Authorization): For example, ensure a user’s email validity before disclosing sensitive data
- Hard business rules: For example, only launch a campaign if its ROI is higher than a certain fixed value
Importance of variables for multi-agent orchestration
Multi-agent orchestration relies on the capability of having a shared memory that can be asynchronously updated by different agents. Thus, it is important to structure the agent’s memory in variables that can be passed between different agents.
Conclusion
Agentforce variables are instrumental in enhancing agent accuracy, reliability, and functionality. They provide persistent dynamic grounding, ensuring that agents retain crucial information across interactions. Variables also enable data flow between actions and enforce determinism, leading to more structured and predictable agent behavior. Ultimately, variables transform agents from simple responders to intelligent, context-aware problem solvers.
Resources
- Documentation: Agent Variables
- Documentation: Filters for topics and actions
- Blog post: Control Agent Access and Decision-Making with Variables and Filters
About the author
Olfa Kharrat is an AI & Agentforce Product Director at Salesforce. She brings over 11 years of experience in AI, including seven years focused on Salesforce solutions in roles such as AI architect and predictive analytics presales. Her work spans diverse projects — from propensity to buy and stock optimization to biological applications — always with a focus on embedding AI into business workflows.