Skip to main content
SFDC Developers
Agentforce & AI

Building Agent-Ready Salesforce Flows for Agentforce

Vinay Vernekar · · 4 min read

Architecting Flows for Agentforce Integration

The paradigm shift in Salesforce automation is moving toward agentic workflows. While traditional Flows relied heavily on Record-Triggered or Screen Flows to manage human interaction or data changes, Agentforce requires Flows that can be invoked directly by AI agents without a user interface.

This necessitates a fundamental design change: treating the Flow as a direct service endpoint, analogous to a microservice callable via an API or Apex subflow, rather than a UI interaction layer.

The Shift: From Screens to Service Endpoints

Previous Flow development focused on collecting user input via screens (Screen Flows) or reacting to database events (Record-Triggered Flows). Agent execution models, however, bypass the need for a visual interface. Agents require direct access to the Flow's capability, relying solely on defined input and output variables for context and result delivery. This aligns the Agent-callable Flow paradigm with Autolaunched Flows invoked through Apex or as subflows.

Importance of Context via Descriptions

For an AI agent to utilize a utility Flow effectively, rich, machine-readable context is paramount. Unlike human users who can infer intent from a screen's layout, agents rely entirely on metadata and documentation embedded within the Flow definition. Treat Flow description fields as critical documentation for the agent environment.

Actionable practice: Ensure every component, especially the main Flow and all input/output variables, has comprehensive descriptions detailing:

  • The Flow's overall objective.
  • The specific purpose of each input variable (data type, expected context, constraints).
  • The structure and meaning of the output variables.

This documentation is the 'instruction manual' the agent uses to formulate its invocation parameters.

Building an Agent-Ready Autolaunched Flow

Consider a common requirement: retrieving related records based on a primary record ID. The Flow must be an Autolaunched Flow defined strictly by input and output variables.

For this example, we aim to find all Case records linked to the same Account as a specified primary Case, excluding the primary Case itself.

1. Define Input/Output Variables

Variables must be explicitly marked as available for input or output. Note the use of Record type variables for complex outputs, especially collections.

API Name Description Data Type Collection Available For
inputAccountId The Id of the Account associated with the primary Case. Text False Input
inputCaseId The Id of the primary Case record to exclude from results. Text False Input
outputCases The collection of related Case records returned to the Agent. Record (Case) True Output

2. Implement Logic Using Get Records

To optimize performance and adhere to the 'service endpoint' concept, we aim to perform the entire logic within a single query element if possible, directly mapping results to the output variable.

  1. Add a Get Records element to the canvas.
  2. Object: Case
  3. Criteria:
    • AccountId Equals {!inputAccountId}
    • Id Does Not Equal {!inputCaseId}
  4. How many records to store: Select All records.
  5. How to store record data: Select Choose fields and assign variables (advanced).
    • Map only the required fields (e.g., CaseNumber, Subject, Description) directly to fields within the outputCases Record Collection Variable.

This configuration minimizes intermediate assignment steps and loads the query results directly into the required output structure, respecting data retrieval governor limits.

Testing Governor Limit Consumption

Testing Agent-callable Flows requires simulating the agent's request payload. Use the Debug feature in Flow Builder:

  1. Set the values for all input variables (inputAccountId, inputCaseId).
  2. Enable Show Governor Limit Consumption in the Setup panel.

Reviewing the Debug details for the Get Records element will confirm:

  • The number of SOQL queries executed (should be one).
  • The number of query rows captured (which corresponds to the count of records assigned to {!outputCases}).

This validates that the Flow executes efficiently and populates the agent's expected output structure.

Key Takeaways

  • Autolaunched Flows are the standard mechanism for Agentforce interaction, bypassing the need for human UI elements.
  • Input and Output variables are the sole interface between the AI agent and the Flow logic.
  • Comprehensive Description Fields across the entire Flow definition are non-negotiable documentation for agent consumption and intent resolution.
  • Aim for efficient, single-element logic (like direct mapping in Get Records) to keep the execution footprint minimal and predictable for the agent.

Share this article

Vinay Vernekar

Vinay Vernekar

Salesforce Developer & Founder

Vinay is a seasoned Salesforce developer with over a decade of experience building enterprise solutions on the Salesforce platform. He founded SFDCDevelopers.com to share practical tutorials, best practices, and career guidance with the global Salesforce community.

Get weekly Salesforce dev tutorials in your inbox

Comments

Loading comments...

Leave a Comment

Trending Now