Agentforce product images

The Agentforce Guide to Context Engineering

Learn how Agentforce uses hybrid reasoning, subagents, actions, and more for reliable, enterprise-grade agents.

A circular diagram shows the agent lifecycle within Agentforce Studio. A user writes the Agent Script in the Agentforce Builder. After testing in Testing Centre, users monitor agent performance in Agentforce Observability, and return to Agentforce Builder to optimise their Agent Script as needed.

Agentforce Studio is your one-stop-shop to continuously improve your agents. With this suite of tools, you can build, test, deploy, monitor, and optimise your agents in a unified way.

Data 360 Components for Extensibility and Control

Component When to Use Skills Required
Agent Invocable Actions To invoke an agent from Flow or Apex Low-code
Agent API To invoke an agent from outside Salesforce Pro-code
Agent Variables To add additional controls to how your agent reasons through subagent and action selection Low-code
Agentforce SDK To build an agent from scratch using Python code via a programmatic interface to Salesforce’s Agentforce infrastructure Pro-code
Model Builder Customise a generative AI model or create a predictive model Low-code
Screenshots of Agent Script as seen in the Canvas view and the code-first Script view.

Agentforce Script saves your agent details in a flat, readable text file for easier review and governance.

Agent Metadata Hierarchy Diagram

Agentforce Custom Action Selection

Component When to Use Skills Required Additional Licence Required?
Prompt Template To invoke an LLM to generate a response. Prompt template actions are one way an agent uses RAG. Low-code Yes
Flow To run low-code rules-based automation and record retrieval Low-code No
Apex code To run pro-code rules-based automation and record retrieval Pro-code No
MuleSoft API To retrieve data from legacy systems and other external applications in a complex enterprise environment Pro-code Yes
External Service To retrieve data from REST APIs that support OpenAPI specs Low-code Yes
Predictive Model To use predictive AI with your agent Low-code Yes
Flow chart graphic showing a high-level decision tree of the Agentforce Reasoning Engine.

Note: This Reasoning Engine Flow diagram uses the term “topics” for what we now call subagents. We’ll update the diagram soon.

Activity Steps Description
Agent Invocation 1 Agent is invoked.
Classify Subagent 2-3 The engine analyses the customer’s message and matches it to the most appropriate subagent based on the subagent name and description.


Agentforce Script transforms the Agent Router into a fully configurable element, eliminating the “black box” of probabilistic LLM routing. By treating navigation as a programmable subagent, you gain absolute transparency and control, allowing you to align the agent’s decision-making logic precisely with your specific business requirements and architectural standards.
Execute Subagent’s
Agentforce Script and Build Instructions / Resolve Instructions & Available Actions
4-5 Execute scripted actions as dictated by instructions. These are actions that should be executed once a subagent is chosen, before the system proceeds to evaluate the non-deterministic instructions or the rest of the conversational context.

Prompt and Conversation History Sent to LLM
6 Once all scripted actions are executed, a prompt with the subagent scope, instructions, and available actions along with the conversation history are sent to LLM.
Note: Instructions are covered in level 2, Agentic Control.
LLM Decides to Respond or Run an Action 7 Using all this information, the engine determines whether to:
• Run an action to retrieve or update information
• Ask the customer for more details
• Respond directly with an answer
If the LLM decides to respond, step 12 is executed.
Action Execution 8-9 If an action is needed, the engine runs it and collects the results.
Run After-Action Logic 10 Only applicable with Agentforce Script: With Agentforce Script, actions can have deterministic transitions to other actions or subagent. Those will always be executed after the action is executed.
Action Output Returned + Action Loop 11 The engine evaluates the new information and decides again what to do next — whether to run another action, ask for more information, or respond.
Grounding Check - LLM Responds to Client 12 Before sending a final response, the engine checks that the response:
• Is based on accurate information from actions or instructions
• Follows the guidelines provided in the subagent’s instructions
• Stays within the boundaries set by the subagent’s scope
Note: It’s possible with Agentforce Script to add a step to format the final answer.
The grounded response is sent to the customer.

Best Practices for Subagents

Agentforce Script transforms subagents from a black box of probabilistic routing into a fully configurable element.

  • Give each subagent a clear name. Use a name that reflects the specific domain of the subagent.
  • Provide a descriptive purpose. Use the description field to explain the intent of the subagent for orchestration purposes.
  • Use explicit transitions. Use script commands to move the user from one subagent to another with absolute certainty.
Bad Example Good Example Why It's Better
Handle order questions and issues. Your job is to answer questions related to order status or repair policies. This description helps the Reasoning Engine identify the correct expert for classification.
Help with login problems. Your job is to help customers who cannot log in by resetting passwords or looking up usernames. This explicitly defines the activities for the classification engine.

Example Use Case: Password Reset

This configuration shows how to blend natural language instructions with deterministic script logic.

Component Contents
Subagent Name Password Reset
Description This explicitly defines the activities for the classification engine.
Agentforce Script (Control) Require identity verification before any reset action runs. Check if the user has a valid session. Use script logic to provide a fallback to security questions if primary verification methods are unavailable.
Instructions (Behaviour) Ask which verification method the customer prefers. Use a professional tone. Explain that a secure reset link will arrive via email after verification succeeds

Best Practices for Instructions

Instructions guide the agent on how to handle conversations within a subagent. They help the agent make decisions about action selection and response patterns. Because instructions are non-deterministic, they do not replace the need for coded business rules within Agentforce Script or an action.

Bad Example Good Example Why It's Better
Get the customer's order details. If a customer enquires about their order status, offer all lookup options including email address or order ID. Provides specific guidance and uses language similar to the action name.
Help with device issues Before using the Knowledge action, clarify the device type (iOS or Android). Gives clear instruction on what information to gather first.
Use knowledge for product questions. Identify the specific product first. Then use the Knowledge action with the exact product name. Provides a clear sequence of steps for the action.
Check if customers need help. After providing the shipping status, always ask if the customer needs anything else related to their order. Specific about when and how to follow up.

Table: Agentforce Features Powered by Data 360

Agentforce Feature Powered by Data 360 Description Provisioning
Data Library Automation Automates creation of search indices and retrievers to support agent actions like Answer Questions with Knowledge Provisioned by Default
Agent Analytics Streams usage data to Data 360 for Reports and Dashboards Provisioned by Default
Retrieval Augmented Generation (RAG) Enables users to augment their prompts with data from Salesforce and Data 360, retrieved at inference time Provisioned by Default
Audit Trail & Feedback Logging Generative AI audit data Optional
Bring Your Own Large Language Model (BYO-LLM) Allows users to use their own LLM Optional
External Data Sources (non-CRM) Enables users to ground AI-generated responses with external sources Optional
Unstructured Data Enables users to ground AI-generated responses in unstructured data Optional
Real Time Data Graphs Enables near real-time grounding of AI-generated responses using normalised data from multiple Data 360 sources
Optional

Agentforce Guide FAQs

Agentforce is Salesforce’s platform for building agents that go beyond simple chat interactions. Unlike standard generative AI tools, these agents can autonomously plan, reason, and take action to achieve specific goals, with or without a human in the loop.

Agentforce has evolved from basic AI interactions into a comprehensive development lifecycle within Agentforce Studio, introducing the Agentforce Builder and Agent Script for enhanced deterministic control. This shift includes rebranding "Topics" as "Subagents." Ultimately, the platform has transitioned from a prompt-centric approach to a hybrid-reasoning model, prioritising reliable logic over probabilistic natural language prompts.

Yes! See https://www.salesforce.com/agentforce/legacy-guide/
While these guides provide technical detail about how Agentforce works, they’re not official implementation guides with click paths and troubleshooting tips. Find official Agentforce Implementation Guides on Salesforce Help.

Find official Agentforce Implementation Guides on Salesforce Help.
While this guide provides technical detail about how Agentforce works, but it’s not an official implementation guide with click paths and troubleshooting tips.

Hybrid reasoning is Agentforce’s approach to agent orchestration that combines deterministic, rule-based logic with LLM-driven intelligence — letting builders dial up or dial down AI autonomy depending on how much reliability vs. flexibility a given task requires.

The guide covers Agentforce Fundamentals, the difference between Prompts and Agents, How Agentforce Reasons, Best Practices for various components, and whether Agentforce needs Data 360.

Agentforce Script provides full deterministic control by replacing long, convoluted system prompts with structured logic. It allows practitioners to define specific code-like steps and "if-then" sequences that must occur before or after LLM reasoning, guaranteeing predictable outcomes.

  • Subagents (formerly called ‘topics’) are like specialised departments with specific expertise and defined boundaries for what an agent can handle.
  • Actions are the specific mechanisms — such as Apex code, Flows, or APIs — that a subagent uses to perform a task or retrieve data.

Use Agentforce Script for ‘control,’ such as enforcing mandatory sequences, complex calculations, or sensitive business rules. Use instructions for ‘behaviour,’ which includes guiding the agent’s tone, persona, and general conversation patterns.

Context engineering is the successor to prompt engineering. It involves designing a system of subagents, instructions, rules, and actions to provide an agent with the exact information and boundaries it needs to be successful, rather than trying to craft the perfect words in an attempt to coax an LLM to give you exactly the right responses.

Filters act as system-level gatekeepers. They can completely hide or include specific subagents or actions based on real-time data, such as whether a customer has been authenticated or if a specific variable (like an order number) has been collected.

Data 360 is integral building effective enterprise agents, powering the indexing and ‘chunking’ of data for Retrieval Augmented Generation (RAG). It also provisions essential features like Agent Analytics and the Digital Wallet used to track agent performance and usage.