Agentforce Example: Customer Support Agent

This example builds a customer support agent that verifies a customer’s identity and helps them get information about their orders. You can build the same agent in three different ways (Headless, Script, or Canvas). Choose the path that fits how you work.

The agent contains three subagents:

  • The agent_router subagent, which provides general instructions to the LLM and exposes two tools that the LLM can select to call. The two tools are utilities that transition to the required subagents, based on user input.
  • The Identity subagent, which verifies the user’s identity. This subagent allows the LLM to request the user’s email (if it doesn’t exist), then sends a verification code to the provided email. Then, the LLM can validate the verification code that the customer provides. This subagent contains deterministic tools and actions, while allowing the LLM freedom to use natural language to interact with the user.
  • The Order_Management subagent, which allows the user to look up order details.

Before you build the agent on any path, make sure that your org is ready:

  • Einstein and Agentforce are enabled. See Set Up Einstein and Agentforce.
  • You have an active user for the agent. Every agent runs as a specific user. These examples use agentforce@salesforce.com as a placeholder for the default_agent_user — replace it with an active Einstein Agent User in your own org. To find one, in Setup go to Users, or query SELECT Username FROM User WHERE UserType = 'EinsteinAgent' AND IsActive = true.
  • The flows the agent calls exist in your org. See Flows This Agent Calls. If they don’t exist yet, stub them so you can preview the agent end-to-end.
  • For the Headless and Script paths, the Salesforce CLI must be installed and authorized to your org. See Set Up Your DX Environment.

No matter which path you select, this agent calls four flows to do its work. The agent expects them to exist in your org. These names are the example’s defaults. If you point an action at a different flow, keep its input and output variable names the same so the action’s contract still matches.

FlowCalled to…InputsOutputs
Get_Verification_CodeSend a verification code by emailemail, member_numberverification_code, member_name
validate_Verification_CodeConfirm the code that the customer enteredverification_codeverification (boolean)
Get_Current_OrderLook up the customer’s current ordermember_emailorder_summary, order_id
Get_Past_OrderLook up a past order by IDqueryorder_summary, order_id

All four flows are specific to this example. (In a real Service Cloud org, the order lookups are often handled by standard SvcCopilotTmpl__ flows instead. That namespace is reserved for a managed package, so this example uses its own plainly named flows that any org can create.)

If a flow doesn’t exist in your org, the agent won’t publish — a flow action can’t point at a flow:// target that isn’t there. To try the agent end-to-end without wiring up real backends, replace each flow with a stub: an autolaunched flow that ignores its inputs and returns canned values.

A stub flow needs only three things:

  1. Input variables that match the action’s inputs (marked Available for input), so the agent can pass values in.
  2. Output variables that match the action’s outputs (marked Available for output), so the agent can read results back.
  3. An Assignment element that sets each output variable to a fixed value.

For example, a validate_Verification_Code stub takes a verification_code input, ignores it, and assigns true to a verification output — so any code the customer enters passes. A Get_Verification_Code stub returns a fixed verification_code (such as 123456) and a member_name. Give each stub the exact flow name and variable names from the table above, deploy it (sf project deploy start), then build the agent.

You can build this agent three ways. Select a tab to follow that path from start to finish.

If you’re a…You’ll build with…Open the tab…
Vibe coder (instruct an AI agent)Natural-language prompts to an AI coding agent, no platform UI requiredHeadless
Developer (code)Agent Script in Script view, Agentforce DX, or the CLIScript
Admin (clicks, not code)Agentforce Builder Canvas viewCanvas

Build the agent by describing what you want in natural language and letting an AI coding agent generate the metadata for you — no platform UI required. To get reliable results, use a coding agent that has Salesforce development context loaded, so it follows platform best practices and produces valid Agent Script.

With this context in place, paste the prompt from each step below into your coding agent. The more specific your prompt — naming the agent’s behavior, the rules it must follow, and any flows or actions it needs to call — the closer the result matches.

This prompt sets up the agent’s foundation — its name, instructions, welcome message, running user, and locale.

When you build headlessly, you don’t hand-write variable declarations or specify Agent Script types — but do name the variables explicitly, so they match the references in the prompts for later steps.

This prompt creates the router subagent — the agent’s entry point that welcomes the customer and routes them to the right subagent based on whether they’re verified.

This prompt creates the Identity subagent, which verifies the customer by email before any order data is exposed, calling flows to send and validate a verification code.

This prompt creates the Order Management subagent, which automatically looks up the customer’s current order on entry and can also retrieve a past order by ID.

Deploy the agent to your org with the Salesforce CLI or your coding agent’s MCP connection, then open it in Agentforce Builder and select Preview. Start a conversation, such as I need help with my order, and confirm the agent asks you to verify your identity first.

Build the agent by writing Agent Script directly in Script view, in Agentforce DX, or with the CLI. The snippets below assemble into the complete script in The Complete Script at the end of this tab.

Set up the agent’s foundation. This Agent Script snippet defines the system block (the agent’s instructions and welcome and error messages), the config block (developer name and description), the access block (the default agent user), and the language block (locale settings).

Replace agentforce@salesforce.com with an active Einstein Agent User in your org. The agent won’t publish with a default_agent_user that doesn’t exist. See Prerequisites.

Declare the variables that the agent uses to remember information across the conversation. This Agent Script snippet declares them in a variables block, grouped into identity variables (such as member_email and the verified boolean) and order variables (such as order_summary). Each variable is mutable, so the agent can update it during the conversation, and some have default values.

Add the agent_router subagent as the agent’s entry point. This Agent Script snippet defines the start_agent subagent with a reasoning block. The reasoning instructions tell the LLM how to greet and route the customer, and the actions section exposes two @utils.transition tools, each gated by an available when condition on the verified variable, so customers must verify before they can look up orders.

Add the Identity subagent, which verifies the customer before any order data is exposed. This Agent Script snippet defines the subagent: the reasoning block runs send_verification_code deterministically when an email exists, then guides the LLM to validate the code, while the reasoning.actions section exposes the two verification actions and a transition tool. The subagent’s own actions section defines send_verification_code and validate_verification_code, each targeting a flow.

Add the Order_Management subagent, which looks up order details. This Agent Script snippet defines the subagent: the reasoning block runs lookup_current_order when order_summary is empty and stores the result in variables, and the reasoning.actions section exposes both lookup actions. The subagent’s actions section defines lookup_order and lookup_current_order, each targeting a flow.

In Script view, select Preview and start a conversation, such as I need help with my order. Confirm that the agent asks you to verify your identity first, and that order details return correctly after verification.

  • Each agent needs a unique developer_name. If you make multiple agents from one example script, change the developer name each time.
  • If you encounter an unexpected error in Agentforce Builder with the last line of your script, add a blank line or a comment to the end.

The snippets from Steps 1–5 combine into this complete script. Copy and paste it to create the agent in one shot.

Build the agent with clicks in Agentforce Builder’s Canvas view, which summarizes Agent Script into easily understandable blocks. For full details on the features used here, see Building Agents in Canvas View.

Create an agent in Agentforce Builder. In the setup flow, set the agent’s name, running user, description, and tone — the foundation that the agent’s instructions and welcome message build on. When you finish, Agentforce Builder opens your new agent in Canvas view.

Open the Variables panel and create the variables that the agent uses to remember information across the conversation. For each one, set a name, a data type, and an optional default value:

  • Identity: member_name, member_email, member_number, verification_code, user_verification_code, and a verified boolean (default False).
  • Orders: order_id and an order_summary string (default empty).

The verified boolean and order_summary string are the variables that later gate which subagents and actions the agent can use. See Manage Variables.

The router is your start subagent — the agent’s entry point on every customer message. In actions available for reasoning, add two transition utilities: one to the Identity subagent, one to Order Management. Use a filter (Make this action available when:) so the transition to Identity is available only when verified equals False, and the transition to Order Management only when verified equals True. This ensures customers verify their identity before they can look up orders.

A transition utility in a subagent's actions available for reasoning in Canvas view

Add a subagent named Identity to verify the customer before any order data is exposed. Add the send_verification_code and validate_verification_code actions (both backed by flows) to actions available for reasoning. In the reasoning instructions, use the inline action shortcuts (/) to run the send action and store its outputs in variables, and reference the actions as resources (@) so the agent validates the code the customer enters. Add a transition to Order Management, available only when verified equals True.

The inline actions shortcut menu, opened with the slash key in Canvas view reasoning instructions

Add a subagent named Order Management to look up order details. Add the lookup_current_order and lookup_order actions. In the reasoning instructions, use a conditional (/) so that when order_summary is empty, the agent runs lookup_current_order and stores the result in the order_summary variable. Reference member_name and order_summary as resources (@) to personalize the response. Customers can also look up a past order by providing an Order ID.

Running the lookup_current_order action inside a conditional instruction in Canvas view

In Canvas view, select Preview and start a conversation, such as I need help with my order. Confirm that the agent asks you to verify your identity first, and that order details return correctly after verification.