---
schema_version: "1"
id: aa1a70f436b120f3842629e84341bc2ffd71441c1da42a06ff9f193265524b7e
title: Call an Agent from a Flow or Apex Class
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ai/264-0-0/agent_custom_invocable_action_flow_apex.md
canonical_url: https://help.salesforce.com/s/articleView?id=ai.agent_custom_invocable_action_flow_apex.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 3ff4722152b3ceb4b0a385efa2e12cfaa8a9862944c51c2d66d92c726476ef9b
description: Give your users access to your agent’s subagents, actions, and reasoning capabilities to automate repetitive tasks and provide real-time assistance. Use invocable actions to call an Agentforce Service agent, Agentforce Employee agent, or Agentforce (Default) from a flow or Apex class. You can call an agent to complete background or event-driven tasks from anywhere that you can invoke a flow or Apex class.
products:
  - Agentforce
  - Cross Cloud
release: "264"
---
# Call an Agent from a Flow or Apex Class

Give your users access to your agent’s subagents, actions, and reasoning capabilities to automate repetitive tasks and provide real-time assistance. Use invocable actions to call an Agentforce Service agent, Agentforce Employee agent, or Agentforce (Default) from a flow or Apex class. You can call an agent to complete background or event-driven tasks from anywhere that you can invoke a flow or Apex class.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions. <a href="https://help.salesforce.com/s/articleView?id=ai.agent_setup_explore_types.htm&amp;release=264.0.0&amp;type=5" title="Learn about agent types and default templates for specific clouds and common use cases.">Required add-on licenses vary by agent type.</a></td></tr></tbody></table>

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ai-generative_ai-264-0-0-production-enus/f8ef6498-d7b2-44e3-9b34-ffd5a850aae9/images/icon_important.png)

Important Starting June 17, 2025, Agentforce (Default) will not include new features or improvements and isn’t available in new Salesforce environments. We recommend migrating to Agentforce Employee agent for continued enhancements and support. If you plan to transition to Agentforce Employee agent or make related license changes, complete the migration of your existing Agentforce (Default) agents in advance to avoid potential disruption in agent availability. If you can't complete the migration in advance, you can create new agents after the transition, which can involve some downtime. See [Migrate from Agentforce (Default) to Agentforce Employee Agent](https://help.salesforce.com/s/articleView?id=ai.migrate_agentforce_default_to_aea.htm&type=5&language=en_US).

Salesforce provides custom and standard invocable actions for calling an agent from a flow or Apex class.

Custom Agent Invocable Actions

Custom agent invocable actions handle more of the conversation automatically, and we recommend them for most use cases. Salesforce provides a custom agent invocable action for each Agentforce Service agent, Agentforce Employee agent, and Agentforce (Default) in your org.

Custom agent invocable actions make it easy to configure your agent’s behavior with clicks, not code. For example, when you add a custom agent invocable action to an Apex class or flow, you use a UI to specify the conditions that trigger the agent, the task to complete, and the data needed to complete the task. You define the task for the agent to complete by specifying a user message. The agent uses it to select subagents and actions, just like if a user had asked a question or made a request in a chat window. You can also define the fields that you want your agent to respond with, and then use those field values in your flow or Apex class.

Consider adding multiple custom agent invocable actions to a flow or Apex class depending on your use case. For example, you can call an agent to summarize a service case and then make a second call to use that summary to draft an email response. You can call the same agent multiple times from the same flow to handle separate but related tasks. Or you can call multiple agents from the same flow to handle more specialized tasks.

Standard Agent API Invocable Actions

Standard Agent API invocable actions give you direct access to [the Agent API](https://developer.salesforce.com/docs/ai/agentforce/guide/agent-api.html) from a flow or Apex class. They provide more granular control over the agent’s behavior during a session than custom agent invocable actions, but they require additional configuration. We recommend them for advanced use cases only.

For example, use the End Session action to make sure a session ends when certain conditions are met. Or use the Submit Feedback action to collect user feedback on the conversation and store it in Data Cloud.

Salesforce provides the following standard Agent API actions.

- End Session
- Send Message
- Start Session
- Submit Feedback

Learn more about Agent API actions in [Agent API Flow Core Actions](https://help.salesforce.com/s/articleView?id=platform.automate_flow_ref_elements_actions_agent_api.htm&language=en_US).

Custom agent invocable actions and standard agent API invocable actions aren't supported for Experience Cloud site users and [Platform Integration User](https://help.salesforce.com/s/articleView?id=xcloud.security_platform_integration_user.htm&language=en_US). The Platform Integration User is also referred to as the System User or system context.

Flows that call an Agentforce Service agent run in the context of [the agent user](https://help.salesforce.com/s/articleView?id=ai.agent_user.htm&release=264.0.0&type=5 "Learn how Agentforce Service agents control data access. Set up an agent user for your Agentforce Service agent and assign permissions, so your agent has everything it needs to do its job."). Flows that call an Agentforce Employee agent or Agentforce (Default) run in the context of the authenticated end user.

In flows, you can only call custom agent invocable actions and standard agent API invocable actions in asynchronous paths, not in a paths that run immediately.

## Prepare to Call an Agent from an Apex Class or Flow

[Create an Agentforce Service agent, Agentforce Employee agent, or Agentforce (Default).](https://help.salesforce.com/s/articleView?id=ai.agent_setup_create.htm&release=264.0.0&type=5 "Create intelligent, trusted, and customizable agents for your customers and employees.")

Prepare your agent’s subagents and actions. Because standard subagents and actions are designed for conversational use cases, they may not work as expected with agent invocable actions. Consider removing standard subagents and actions from your agent and creating custom actions for your use cases.

Custom agent invocable actions don't support custom variables or these standard context variables: $Context.EndUserId, $Context.RoutableId, $Context.EndUserLanguage, and $Context.EndUserContactId.

If you’re using an Agentforce Service agent, make sure that your agent has the necessary access to any records used by your agent actions. For example, if you want your agent to be able to summarize a case, create a permission set and modify the object settings to grant read access for the Case object. Then assign the permission set to [the agent user](https://help.salesforce.com/s/articleView?id=ai.agent_user.htm&release=264.0.0&type=5 "Learn how Agentforce Service agents control data access. Set up an agent user for your Agentforce Service agent and assign permissions, so your agent has everything it needs to do its job.").

- **[Set Up a Custom Agent Invocable Action in Flow Builder](https://help.salesforce.com/s/articleView?id=ai.agent_custom_invocable_action_flow_set_up.htm&release=264.0.0&type=5)**  
    Add a custom agent invocable action to a new or existing flow to complete a task automatically with your Agentforce Service agent or default Agentforce agent.
- **[Custom Agent Invocable Action: Example Apex Classes](https://help.salesforce.com/s/articleView?id=ai.agent_custom_invocable_action_apex_example.htm&release=264.0.0&type=5)**  
    Call a custom agent invocable action from an Apex class to complete a task automatically with your Agentforce Service agent or default Agentforce agent. The Apex class must return the agent’s response.

#### See Also

- [_Video_: Invoke Agents with Apex Invocable Actions](https://youtu.be/UcWM82ppxBQ)