---
schema_version: "1"
id: d984f5825b8b5cbe6534c140a03984b7f363e9cf00a0470972fc1e23aba2252a
title: End Session Action
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/automate_flow_ref_elements_agent_api_end_session.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.automate_flow_ref_elements_agent_api_end_session.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: e38602fd8aa0137a502375cb868c0cfef778920bca12d7633dc1d34ce6db966f
description: This action ends a specified session for an agent.
products:
  - Flow Builder
  - Salesforce Platform
release: "264"
---
# End Session Action

This action ends a specified session for an agent.

### 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. Required add-on licenses vary by agent type.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=platform.flow_ref_supported_editions.htm&amp;release=264.0.0&amp;type=5" title="Learn about the editions and user interfaces that support Flow Builder. Some Flow Builder features integrate with other Salesforce products that require additional licenses.">View licenses for integrated features.</a></td></tr></tbody></table>

In Flow Builder, add an Action element to your flow. Select the **AI Agent API** category. Then, select the **End Session** action.

## Set Input Values

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:17.825311942959%">
          <col style="width:82.174688057041%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d118907e98">Field</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d118907e101">Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d118907e98 ">Session End Message</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d118907e101 ">
              <p>Required. An Apex
                AgentInvAction__AIAgentAPIV1_SessionEndedMessage record that
                contains a message with the reason why the session
                ended.</p>
              <p>Valid values for the <code>reason</code> property are:</p>
              <ul>
                <li><code>UserRequest</code></li>

                <li><code>Transfer</code>
                </li>

                <li><code>Expiration</code>
                </li>

                <li><code>Error</code>
                </li>

                <li><code>Other</code></li>

              </ul>
            </td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d118907e98 ">Session ID</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d118907e101 ">Required. The ID of the current agent session.</td>

          </tr>
          <tr class="">
            <td data-label="Field" class="slds-cell-wrap" style="vertical-align:top;" headers="d118907e98 ">Tenant Key ID</td>

            <td data-label="Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d118907e101 ">Reserved for internal use only.</td>

          </tr>
        </tbody>
      </table>

## Set Output Values

 
| Set Field | Description |
| --- | --- |
| 200 | Batched response (headless) |
| 400 Exception | Bad request |
| 401 Exception | Access bearer token is missing or invalid |
| 403 Exception | User is forbidden from accessing the resource |
| 404 Exception | Resource not found |
| 422 Exception | Any exception that occurred during the request execution |
| 423 Exception | Server is busy and cannot process the request at this time |
| 429 Exception | Too many requests for the server to handle |
| 503 Exception | Service is unavailable possibly because Apex or flow calls timed out |
| Default Exception | Server is busy and cannot process the request at this time |
| responseCode | The response code associated with the exception message. |

## Usage

This action is available only if the following are true. Otherwise, the action fails.

- Agentforce is enabled.
- The user who runs the flow has the Manage AI Agents permission.
- The specified agent has an active version.

To set the Session End Message input:

- Create an Apex-defined variable and select the **AgentInvAction\_\_AIAgentAPIV1\_SessionEndedMessage** Apex class.
- Use Assignment elements to set the `reason` property.
- Use the AgentInvAction\_\_AIAgentAPIV1\_SessionEndedMessage variable as the Session End Message input.