A session represents a conversation between a Dialogflow CX agent and an end-user.
You create a session at the beginning of a conversation
and use it for each turn of the conversation.
Once the conversation has ended,
you discontinue using the session.

You should not use the same session for concurrent conversations
with different end-users.
A session remains active and its data is stored for 30 minutes
after the last request is sent for the session.

Each session is determined unique by a session ID generated by your system.
You create a new session by providing a new session ID
in a detect intent request and other session methods.
A session ID is a string of at most 36 bytes in size.
Your system is responsible for generating unique session IDs.
They can be random numbers, hashed end-user identifiers,
or any other values that are convenient for you to generate.

Check the [Regionalization](https://docs.cloud.google.com/dialogflow/cx/docs/how/region)
documentation for information about the Location ID value in the session name.

## Long-lasting sessions

By default, Dialogflow CX maintains the session data for 30 minutes. There are two ways to extend the lifetime of the sessions:

- **(Preferred)** Set session TTL using `QueryParameters.session_ttl`. The maximum allowed value is 24 hours.
- You can revive the previous session state by setting
  `QueryParameters.current_page` and `QueryParameters.parameters` in `DetectIntentRequest`.

  An example workflow looks like:
  1. End-user talks with the agent under session A.
  2. Your code records the state associated with session A returned in the API response, namely `QueryResult.current_page` and `QueryResult.parameters`.
  3. End-user stops interacting with the agent after 50 minutes.
  4. End-user talks with the agent again.
  5. Your code sends the end-user input, together with the previously recorded `QueryParameters.current_page` and `QueryParameters.parameters` in the request, to detect intent with the previous session state. You do not need to use the same session ID as used by session A.

  > [!NOTE]
  > **Note:** [Handler call stack](https://docs.cloud.google.com/dialogflow/cx/docs/concept/handler#call-stack) will **not** be revived with this approach.

## References

For information on session pricing, see the
[pricing page](https://cloud.google.com/products/conversational-agents/pricing).

For more information on sessions:


<button class="devsite-dialog-button cloud-button cloud-button--primary" style="display: block; padding: 10px; margin-top: 10px; margin-bottom: 10px;" data-modal-dialog-id="cx-agent-reference-dialog-Session">Go to the Session API reference</button>
**Select a protocol and version for the Session reference:**

| Protocol | V3 | V3beta1 |
|---|---|---|
| REST | [Session resource](https://docs.cloud.google.com/dialogflow/cx/docs/reference/rest/v3/projects.locations.agents.sessions) | [Session resource](https://docs.cloud.google.com/dialogflow/cx/docs/reference/rest/v3beta1/projects.locations.agents.sessions) |
| RPC | [Session interface](https://docs.cloud.google.com/dialogflow/cx/docs/reference/rpc/google.cloud.dialogflow.cx.v3#google.cloud.dialogflow.cx.v3.Sessions) | [Session interface](https://docs.cloud.google.com/dialogflow/cx/docs/reference/rpc/google.cloud.dialogflow.cx.v3beta1#google.cloud.dialogflow.cx.v3beta1.Sessions) |
| C++ | [SessionsClient](https://googleapis.dev/cpp/google-cloud-dialogflow_cx/latest/classgoogle_1_1cloud_1_1dialogflow__cx_1_1SessionsClient.html) | Not available |
| C# | [SessionsClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Dialogflow.Cx.V3/latest/Google.Cloud.Dialogflow.Cx.V3.SessionsClient) | Not available |
| Go | [SessionsClient](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/dialogflow/latest/cx/apiv3#cloud_google_com_go_dialogflow_cx_apiv3_SessionsClient) | Not available |
| Java | [SessionsClient](https://docs.cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.SessionsClient) | [SessionsClient](https://docs.cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3beta1.SessionsClient) |
| Node.js | [SessionsClient](https://googleapis.dev/nodejs/dialogflow-cx/latest/v3.SessionsClient.html) | [SessionsClient](https://googleapis.dev/nodejs/dialogflow-cx/latest/v3beta1.SessionsClient.html) |
| PHP | Not available | Not available |
| Python | [SessionsClient](https://docs.cloud.google.com/python/docs/reference/dialogflow-cx/latest/google.cloud.dialogflowcx_v3.services.sessions.SessionsClient) | [SessionsClient](https://docs.cloud.google.com/python/docs/reference/dialogflow-cx/latest/google.cloud.dialogflowcx_v3beta1.services.sessions.SessionsClient) |
| Ruby | Not available | Not available |

<button class="devsite-dialog-close">Close</button>

<br />