# Create an Agent Platform resource for Sessions and Memory Bank An ADK agent running on Cloud Run, GKE, or another environment can use Agent Platform for managed Sessions and Memory Bank. Before configuring either service, create the backing Agent Engine resource. The API identifies this resource as a `reasoningEngine`. This post creates the resource through the REST API, waits for the asynchronous operation to finish, and prints the two service URIs needed by an ADK deployment. Note: The public [Memory Bank setup guide](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/agent-engine/memory-bank/set-up) shows the equivalent Vertex AI SDK flow and covers project setup, API enablement, and supported regions. ## Create the resource Before running the script, select your Google Cloud project with `gcloud config set project PROJECT_ID` and make sure `jq` is installed. Update `LOCATION` if you want to use a region other than `us-west1`. The companion repository contains this script: ```shell {linenos=table} # 1. Set your variables PROJECT_ID=$(gcloud config get-value project) LOCATION="us-west1" # Replace with your target region RESOURCE_DISPLAY_NAME="Agent Backend Resource" # 2. Build the request payload SETTINGS="{ \"displayName\": \"${RESOURCE_DISPLAY_NAME}\" }" # 3. Execute the REST API request, capturing the response body RESPONSE=$(curl -s -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/reasoningEngines" \ -d "${SETTINGS}") # 4. Check for errors in the response if [ -z "$RESPONSE" ]; then echo "Error: empty response from API" >&2 exit 1 fi if echo "$RESPONSE" | grep -q '"error"'; then echo "Error: API request failed" >&2 echo "$RESPONSE" >&2 exit 1 fi # 5. Parse the "name" field from the response NAME=$(echo "$RESPONSE" | jq -r '.name') if [ -z "$NAME" ] || [ "$NAME" = "null" ]; then echo "Error: could not parse 'name' from response" >&2 echo "$RESPONSE" >&2 exit 1 fi echo "Operation name: $NAME" # 6. Derive the engine resource name from the operation name ENGINE_NAME="${NAME%/operations/*}" # 6b. Wait for the create operation to complete (engine is provisioned async) echo "Waiting for engine to be created..." until [ "$(curl -s \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://${LOCATION}-aiplatform.googleapis.com/v1/${NAME}" | jq -r '.done')" = "true" ]; do sleep 5 done echo "Engine ready: $ENGINE_NAME" echo echo "Add these env variables to your deployment:" echo "SESSION_SERVICE_URI=agentengine://${ENGINE_NAME}" echo "MEMORY_SERVICE_URI=agentengine://${ENGINE_NAME}" echo # 7. Create a memory under the engine echo "Creating a test memory" MEMORY="{ \"fact\": \"My first memory.\", \"scope\": {\"placeholder\": \"true\"} }" curl -s -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://${LOCATION}-aiplatform.googleapis.com/v1/${ENGINE_NAME}/memories" \ -d "${MEMORY}" # 8. Create a session under the engine echo "Creating a test session" SESSION="{ \"userId\": \"example-user\" }" curl -s -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://${LOCATION}-aiplatform.googleapis.com/v1/${ENGINE_NAME}/sessions" \ -d "${SESSION}" ``` *[deploy_backend.sh](https://github.com/WilliamDenniss/agent-examples/blob/master/04_AgentPlatformBackend/deploy_backend.sh)* The create request returns a long-running operation. The script derives the resource name from that operation, waits until provisioning completes, and prints values in this format: ```shell SESSION_SERVICE_URI=agentengine://projects/PROJECT/locations/REGION/reasoningEngines/ENGINE_ID MEMORY_SERVICE_URI=agentengine://projects/PROJECT/locations/REGION/reasoningEngines/ENGINE_ID ``` The final two requests create a test memory and session. Their responses should identify resources under the new `reasoningEngine`. The example scope and user ID are placeholders rather than a recommended production data model. With the resource available, [configure an agent on Cloud Run or GKE to use Sessions and Memory Bank](/agents/use-sessions-memory-from-cloud-run-gke/).