This document describes how to create a data agent in Cloud SQL for MySQL Studio using an agent context file. A data agent is associated with a single agent context file.
To learn about data agents, see Data agents overview.Before you begin
Complete the following prerequisites before creating an agent.
Enable required services
Enable the following services for your project:Prepare a Cloud SQL instance
- Make sure that you have access to an existing Cloud SQL instance or create a new one. For more information, see Create instances for Cloud SQL.
- Ensure that you create a database in your instance where you will create the tables. For more information, see Create a database on the Cloud SQL instance
Required roles and permissions
- Add an IAM user or service account at the instance level. For more information, see Add an IAM policy binding to a user, service account, or group.
- Grant the
cloudsql.studioUserandcloudsql.instanceUserroles to the IAM user at the project level. For more information, see Add IAM policy binding for a project. - You must also grant database privileges to
an IAM user or service account by logging in as the password-based user of the
database.
GRANT ALL PRIVILEGES ON * TO "IAM_USERNAME";.
For more information, see Grant database privileges to an individual IAM user or service account.
Grant executesql permission to Cloud SQL instance
To grant the executesql permission to Cloud SQL instance and enable the Cloud SQL
Data API, run the following command:
gcloud components update gcloud beta sql instances patch INSTANCE_ID --data-api-access=ALLOW_DATA_API
INSTANCE_ID with your Cloud SQL instance ID.
To perform steps in this tutorial, sign in to Cloud de Confiance by S3NS, and then authenticate to the database using IAM authentication.
Create a data agent
To create a data agent, perform the following steps:
In the Cloud de Confiance by S3NS console, go to the Cloud SQL page.
Select an instance from the list.
In the navigation menu, click Cloud SQL Studio.
Sign in to Studio using Identity and Access Management (IAM) authentication.
In the Explorer pane, next to Data Agents, click View actions.
Click Create agent.
In Agent name, provide a unique agent name. The agent name is case-sensitive and can contain letters, numbers, hyphens, and underscores.
Optional. In Agent description, add a description for your agent.
Optional. Click Show Advanced Options and in Select a location, select a region for storing agent context. You can select from the following list of supported regions:
us-central1us-east1europe-west4asia-southeast1
Click Create.
Build agent context
After creating an agent, follow the steps in Build contexts using Gemini CLI to create an agent context file. You can then edit your agent to upload the context file.
Edit an agent
To edit a data agent, perform the following steps:
In the Cloud de Confiance console, go to the Cloud SQL page.
Select an instance from the list.
In the navigation menu, click Cloud SQL Studio.
Sign in to Studio using Identity and Access Management (IAM) authentication.
In the Explorer pane, next to Data Agents, click View actions.
Click Edit agent.
Optional: Edit Agent description.
Click Browse in the Upload agent context file section, and select the agent context file.
Click Save.
Delete a data agent
To delete a data agent, perform the following steps:
In the Cloud de Confiance console, go to the Cloud SQL page.
Select an instance from the list.
In the navigation menu, click Cloud SQL Studio.
Sign in to Studio using Identity and Access Management (IAM) authentication.
In the Explorer pane, next to Data Agents, click View actions.
Click Delete agent.
In the Delete agent confirmation dialog, enter the name of the agent.
Click Confirm to delete the agent.
What's next
- Learn more about data agents.
- Learn how to inspect and call a data agent.