# Gemini integration

This document explains how to register Google Cloud Cortex Framework
[BigQuery conversational analytics data
agents](https://docs.cloud.google.com/cortex/docs/conversational-analytics) in
[Gemini](https://docs.cloud.google.com/gemini/enterprise/docs.md.txt) so business users across your
organization can query enterprise data products using natural language.

After you provision domain-specific data agents from your deployed
Cortex Framework data products using
[`uv run cortex-create-ca-agents`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-create-ca-agents.md.txt),
you can register and synchronize those agents automatically with
[`uv run cortex-register-gemini-agents`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-register-gemini-agents.md.txt),
or publish them manually in the Google Cloud console through
[Agent Registry](https://docs.cloud.google.com/agent-registry/overview.md.txt) or the Agent2Agent (A2A)
protocol for cross-project setups.

> [!NOTE]
> **Note:** In the Google Cloud console, the Gemini administration page is labeled **Gemini Enterprise** , and the predefined Identity and Access Management (IAM) administrator role is Gemini Enterprise Admin (`roles/discoveryengine.agentspaceAdmin`).

## Key benefits

Integrating Cortex Framework data agents with
Gemini provides the following benefits:

- **Declarative CLI registration and reconciliation** : Configure your target app and agents in `config/config.yaml` and run `uv run cortex-register-gemini-agents` to fetch A2A agent cards, configure shared Google-managed OAuth credentials, sync `starterPrompts`, and reconcile updates idempotently from CI/CD pipelines.
- **Organization-wide discovery and routing** : Business users can browse Cortex Framework domain agents in the [Agent Gallery](https://docs.cloud.google.com/gemini/enterprise/docs/agent-gallery.md.txt), invoke a specific agent using `@mention`, or ask general analytical questions in Gemini that automatically route to the matching data agent.
- **Centralized agent governance** : Administrators can preserve custom OAuth and sharing policies configured in the Google Cloud console, or govern cross-project discovery and regional traffic routing manually through Agent Registry and [Agent Gateway](https://docs.cloud.google.com/gemini-enterprise-agent-platform/govern/gateways/agent-gateway-overview.md.txt).
- **End-user IAM security**: Queries execute in BigQuery using each signed-in user's OAuth 2.0 and IAM credentials, preserving dataset, table, column, and row-level access controls.
- **Preserved semantic context** : Retains all Cortex Framework knowledge sources, table and column descriptions (`annotations/*.yaml`), `schemaRelationships`, `glossaryTerms`, and verified queries (`goldenQueries`) synchronized by `uv run cortex-create-ca-agents`.

## How the integration works

Registering Cortex Framework data agents in
Gemini with `uv run cortex-register-gemini-agents` follows these
stages:

1. Data engineers configure `conversationalAnalytics` in `config/config.yaml` with `contextVersion: published` and run [`uv run cortex-create-ca-agents`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-create-ca-agents.md.txt) to create and synchronize BigQuery conversational analytics data agents. For instructions, see [Conversational analytics integration](https://docs.cloud.google.com/cortex/docs/conversational-analytics.md.txt).
2. Administrators configure the `gemini` block in `config/config.yaml` and run [`uv run cortex-register-gemini-agents`](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-register-gemini-agents.md.txt) (optionally previewing with `--dry-run`, or creating and updating the app on demand with `--create-app`).
3. The CLI verifies required Google Cloud APIs, confirms location support in the Discovery Engine API, validates that each referenced data agent exists with a `published` context, retrieves each agent's canonical A2A card from the Conversational Analytics API, configures default Google-managed OAuth credentials, syncs `starterPrompts` from `goldenQueries`, and registers or updates each agent in place.
4. Business users sign in to Gemini, complete a one-time OAuth 2.0 authorization prompt shared across Cortex Framework-managed agents in that project and location, and ask natural-language questions against your Cortex Framework data products.

For cross-project deployments where BigQuery and
Gemini reside in different Google Cloud projects, or when
you prefer console-driven registration, see
[Alternative: Manual or cross-project registration in the Google Cloud console](https://docs.cloud.google.com/cortex/docs/gemini.md.txt#manual-registration).

## Before you begin

Before registering your data agents in Gemini, verify the
following prerequisites:

### Provision published data agents

Deploy your Cortex Framework data product pipelines and run
`uv run cortex-create-ca-agents` with `contextVersion: published` (the default)
so that each referenced data agent exists in BigQuery with a
populated `published` context. Agents that only have a `staging` context fail
pre-flight validation during `uv run cortex-register-gemini-agents`. For setup
instructions, see
[Conversational analytics integration](https://docs.cloud.google.com/cortex/docs/conversational-analytics.md.txt).

### Enable Google Cloud APIs

Enable the Discovery Engine API (`discoveryengine.googleapis.com`) and
the Conversational Analytics API (`geminidataanalytics.googleapis.com`) in
`buildEnvironment.buildProjectId`, or pass `--enable-apis` when running
`uv run cortex-register-gemini-agents`:

```bash
gcloud services enable discoveryengine.googleapis.com \
    geminidataanalytics.googleapis.com \
    --project=BUILD_PROJECT_ID
```

Replace the following:

- `BUILD_PROJECT_ID`: the Google Cloud project ID configured in `buildEnvironment.buildProjectId`, for example: `my-cortex-project`.

### Verify license and regional alignment

`uv run cortex-register-gemini-agents` resolves the
Discovery Engine API location from `gemini.app.location` (normalized
to lowercase), defaulting to lowercased `data.bigQueryLocation` when omitted.

> [!IMPORTANT]
> **Important:** Your target location must have an active Gemini license allocated. If your license is provisioned in `global` while `data.bigQueryLocation` is a regional or multi-regional value (such as `US` or `EU`), set `gemini.app.location: global` in `config/config.yaml`. Otherwise, app creation fails with an unavailable license error.

If you register agents manually through Agent Registry, the
storage region of your BigQuery data agent (configured in
`conversationalAnalytics.location` or `data.bigQueryLocation`) must also match
the Agent Registry region binding configured in your
Agent Gateway. You can't change a data agent's region after the
agent is created.

### Identify or create an app in Gemini

Identify an existing Gemini app ID (`appId`) in
`buildEnvironment.buildProjectId`, or pass `--create-app` to
`uv run cortex-register-gemini-agents` (with `gemini.app.displayName`
configured) to create or update the app on demand. To create an app manually in
the Google Cloud console, see
[Create an app](https://docs.cloud.google.com/gemini/enterprise/docs/create-app.md.txt).

### Get the required roles


To get the permissions that
you need to register, publish, and query Cortex Framework data agents in Gemini,

ask your administrator to grant you the
following IAM roles:

- Register agents and manage apps (`uv run cortex-register-gemini-agents`):
  - Gemini Enterprise Admin (`roles/discoveryengine.agentspaceAdmin`) or Discovery Engine Admin (`roles/discoveryengine.admin`) on `buildProjectId`
  - Gemini Data Analytics Data Agent Viewer (`roles/geminidataanalytics.dataAgentViewer`), Data Agent User (`roles/geminidataanalytics.dataAgentUser`), or Data Agent Editor (`roles/geminidataanalytics.dataAgentEditor`) on `buildProjectId`
  - [Service Usage Consumer](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageConsumer) (`roles/serviceusage.serviceUsageConsumer`) on `buildProjectId`
  - [Service Usage Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/serviceusage.md.txt#serviceusage.serviceUsageAdmin) (`roles/serviceusage.serviceUsageAdmin`) on `buildProjectId` (required only when passing `--enable-apis`)
- Publish and share data agents manually in BigQuery (optional console workflow): Gemini Data Analytics Data Agent Owner (`roles/geminidataanalytics.dataAgentOwner`) or Gemini Data Analytics Data Agent Editor (`roles/geminidataanalytics.dataAgentEditor`) on `buildProjectId`
- Discover and query published data agents (business user):
  - [Gemini Data Analytics Data Agent User](https://docs.cloud.google.com/iam/docs/roles-permissions/geminidataanalytics.md.txt#geminidataanalytics.dataAgentUser) (`roles/geminidataanalytics.dataAgentUser`) on `buildProjectId`
  - BigQuery Studio User (`roles/bigquery.studioUser`) or Gemini for Google Cloud User (`roles/cloudaicompanion.user`) on `buildProjectId`
  - [BigQuery Job User](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.jobUser) (`roles/bigquery.jobUser`) on the query execution project
  - [BigQuery Data Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataViewer) (`roles/bigquery.dataViewer`) on the underlying data product datasets


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

For complete permission details, see
[Required roles for data
agents](https://docs.cloud.google.com/bigquery/docs/create-data-agents#required-roles) and
[Register and manage A2A agents](https://docs.cloud.google.com/gemini/enterprise/docs/register-and-manage-an-a2a-agent.md.txt).

## Configure `gemini` in `config/config.yaml`

Add a top-level `gemini` section to `config/config.yaml` alongside
`buildEnvironment.buildProjectId` and your enabled `conversationalAnalytics`
agents:

```yaml
buildEnvironment:
  buildProjectId: BUILD_PROJECT_ID

gemini:
  enabled: true
  app:
    appId: cortex-gemini-assistant
    displayName: "Cortex Gemini Assistant"
    location: global
    companyName: "Example Corp"
  agents:
    - agentId: cortex-sap-financial-analysis-agent
      # Optional: defaults to the conversationalAnalytics agent displayName.
      # displayName: "Financial Analysis Agent"
      enabled: true
    - agentId: cortex-sales-revenue-forecast-assistant
      # displayName: "Sales Performance & Revenue Forecast Assistant"
      enabled: false
    - agentId: cortex-sap-inbound-logistics-risk-analyst
      # displayName: "SAP Inbound Logistics Risk Agent"
      enabled: false
```

Replace the following:

- `BUILD_PROJECT_ID`: the Google Cloud project ID hosting both your provisioned BigQuery data agents and the Gemini app, for example: `my-cortex-project`.

The following table describes the `gemini` configuration fields:

| Field | Type | Required | Default | Description |
| `gemini.enabled` | `boolean` | No | `true` | Enable or disable execution of `uv run cortex-register-gemini-agents`. |
| `gemini.app.appId` | `string` | Yes | None | Target Gemini app (Discovery Engine) ID. Must be 1--63 characters of lowercase letters, digits, hyphens, and underscores, starting with a lowercase letter or digit and not ending with a hyphen. |
| `gemini.app.displayName` | `string` | With `--create-app` | None | Human-readable app display name (1--256 characters). Required when passing `--create-app`; optional when only registering agents into an existing app. |
| `gemini.app.location` | `string` | No | Lowercased `data.bigQueryLocation` | Discovery Engine API location (such as `global`, `us`, or `eu`). Set to match your active Gemini license location. |
| `gemini.app.companyName` | `string` | No | None | Company name stored in the app's `commonConfig.companyName`. When omitted on update, any existing server-side value is preserved. |
| `gemini.agents[].agentId` | `string` | Yes | None | ID of an enabled, `published` conversational analytics data agent provisioned in `buildEnvironment.buildProjectId`. |
| `gemini.agents[].displayName` | `string` | No | Inherited from data agent | Optional display name override shown in Gemini (1--256 characters). Falls back to the conversational analytics agent's `displayName` or `agentId`. |
| `gemini.agents[].enabled` | `boolean` | No | `true` | Whether to register or update this agent during `uv run cortex-register-gemini-agents`. |
|---|---|---|---|---|

## Register agents with `uv run cortex-register-gemini-agents`

First preview pre-flight validation and planned registration status with
`--dry-run` (no resources are created or modified and telemetry is suppressed):

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-register-gemini-agents --config $CORTEX_CONFIG_FILE --dry-run
```

Register or update all enabled agents into an existing Gemini
app:

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-register-gemini-agents --config $CORTEX_CONFIG_FILE
```

To create or update the configured Gemini app on demand before
registering agents, and automatically enable any missing required APIs, add
`--create-app` and `--enable-apis` (note that `--enable-apis` is mutually
exclusive with `--dry-run`):

```bash
export CORTEX_CONFIG_FILE=config/config.yaml
uv run cortex-register-gemini-agents \
    --config $CORTEX_CONFIG_FILE \
    --create-app \
    --enable-apis
```

For full CLI options and exit codes, see the
[`uv run cortex-register-gemini-agents` CLI reference](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-register-gemini-agents.md.txt).

### Automated card, authentication, prompt, and reconciliation behavior

During each run, `uv run cortex-register-gemini-agents` manages registered
agents as follows:

- **Automatic A2A card retrieval** : Fetches each agent's canonical A2A card JSON from `/v1beta/a2a/<ca_agent_name>/v1/card` on the resolved Conversational Analytics API endpoint and applies the effective `displayName` and `description`.
- **Shared Google-managed OAuth (`authorizationConfig.agentAuthorization`)** : New registrations attach a deterministic first-party authorization resource (`projects/<project>/locations/<location>/authorizations/geminidataanalytics_<uuid>`) seeded by `(project_id, location)` so all Cortex Framework data agents in that project and location share a single per-user OAuth consent grant without manual client setup. On update, any existing non-empty `authorizationConfig` configured in the Google Cloud console (such as custom OAuth) is preserved, while a missing authorization configuration is backfilled automatically.
- **`starterPrompts` synchronization** : Copies each `natural_language_question` from the live data agent's `published_context.example_queries` (`goldenQueries`) into `starterPrompts`. Updates always include `starterPrompts` in the patch `updateMask` (defaulting to an empty list) so removing an upstream verified query clears the stale starter prompt.
- **`sharingConfig` defaults and preservation** : Newly registered agents are created with `sharingConfig: {"scope": "ALL_USERS"}`. On subsequent updates, `sharingConfig` is excluded from the patch `updateMask` so sharing scopes customized by administrators in the Google Cloud console are preserved.
- **Idempotent reconciliation statuses** :
  - **`NEEDS_CREATION`** : Creates the app (when `--create-app` is passed) or registers the agent.
  - **`NEEDS_UPDATE`** : Updates mutable managed fields (`displayName`, `companyName` on the app; `displayName`, `description`, `starterPrompts`, A2A card, or missing authorization on the agent) in place.
  - **`NO_CHANGE`**: Resource already matches the target configuration; no write calls are issued.
  - **`NOT_MANAGED`** : Protects incompatible or unmanaged resources---such as an existing Discovery Engine engine with an incompatible solution type (other than `SOLUTION_TYPE_SEARCH` or `SOLUTION_TYPE_GENERATIVE_CHAT`), or an existing agent whose card URL doesn't target `/projects/<buildProjectId>/locations/<caLocation>/dataAgents/<agentId>`. Unmanaged resources are never overwritten and cause the command to exit with status code `1`.

## Alternative: Manual or cross-project registration in the Google Cloud console

If your BigQuery data agents and Gemini app
reside in different Google Cloud projects, or if you prefer configuring
Agent Registry and Agent Gateway manually in the
Google Cloud console, use the following workflow instead of
`uv run cortex-register-gemini-agents`.

### Configure Agent Gateway

If you publish your data agents through Agent Registry, your
Gemini administrator must configure an
Agent Gateway with a matching region binding:

1. [Set up an Agent Gateway](https://docs.cloud.google.com/gemini-enterprise-agent-platform/govern/gateways/set-up-agent-gateway.md.txt) that includes an Agent Registry binding matching your data agent's location (`conversationalAnalytics.location` or `data.bigQueryLocation`), such as **US** , **EU** , or **Global**.
2. In the Google Cloud console, go to the
   **Gemini** page and open your app.

   [Go to Gemini](https://console.cloud.google.com/gemini-enterprise/)
3. Go to **Security** \> **Configuration** , and then enter the gateway
   resource name in the **Agent Gateway configuration** section.
   For detailed instructions, see
   [Route Gemini traffic through Agent Gateway](https://docs.cloud.google.com/gemini-enterprise-agent-platform/govern/gateways/agent-gateway-ge-deploy.md.txt).

If you instead import agents directly using the A2A card JSON, skip to
[Publish data agents in BigQuery](https://docs.cloud.google.com/cortex/docs/gemini.md.txt#publish-agents-bigquery).

### Publish data agents in BigQuery

After `uv run cortex-create-ca-agents` synchronizes your data agent, publish the
agent to additional channels in BigQuery Studio:

1. In the Google Cloud console, go to the BigQuery Studio
   **Agents** page.

   [Go to Agents](https://console.cloud.google.com/bigquery/agents_hub)
2. Select the project configured in `buildEnvironment.buildProjectId`.

3. Select the **Agent Catalog** tab and click your provisioned
   Cortex Framework data agent.

4. Verify that the **Region** matches your agent's configured location
   (`conversationalAnalytics.location` or `data.bigQueryLocation`) and, if
   applicable, your Agent Gateway configuration.

5. Click **Publish** , or click **Publish updates** if the agent was previously
   published.

6. In the **Publishing channels** pane, under **Additional channels**, choose
   your publishing method:

   - **Same project (Agent Registry)** : If BigQuery and Gemini are in the same project, in the **Agent Registry** section, select the **Register
     this agent** checkbox.
   - **Cross-project (A2A endpoint JSON)** : If BigQuery and Gemini are in different projects, in the **Integrate via
     A2A (Agent2Agent)** section, click **Copy JSON** to copy the A2A endpoint JSON data and share it with your Gemini administrator.
7. Click **Publish** or **Publish updates**.

8. [Share the data agent](https://docs.cloud.google.com/bigquery/docs/create-data-agents.md.txt#share-a-data-agent)
   in BigQuery with the users and groups who need access,
   granting them the roles listed in [Get the required roles](https://docs.cloud.google.com/cortex/docs/gemini.md.txt#required-roles).

### Register data agents in the Google Cloud console

As a Gemini administrator, register the published
BigQuery data agent in your app using either
Agent Registry or the A2A card JSON.

#### Option 1: Import from Agent Registry

1. If Gemini is in a different project from your BigQuery project, [manually register the agent](https://docs.cloud.google.com/agent-registry/manual-registration.md.txt#register-remote-agent) in Agent Registry in your Gemini project first (otherwise, skip this step):
   1. In the Google Cloud console, open **Agent Registry** in your Gemini project, select the **Agents** tab, and then click **Add agent**.
   2. In the **Agent details** pane, for **Type** , select **A2A** , and for **Region**, select the region that matches your data agent and Agent Gateway configuration.
   3. Select **Paste JSON** , enter the A2A endpoint JSON data copied from BigQuery, and then click **Save**.
2. In the Google Cloud console, go to the
   **Gemini Enterprise** page and open your app.

   [Go to Gemini Enterprise](https://console.cloud.google.com/gemini-enterprise/)
3. In the navigation menu, click **Agents** \> click **Add agent**.

4. In the **Choose an agent type** pane, locate **Agents from
   Agent Registry** and click **Add**.

5. Select your Cortex Framework data agent card, click **Add
   agent** , review the populated agent metadata, and then click **Next**.

6. In the **Authenticate agent** step, select how Gemini
   authenticates against the agent:

   - **Default Google-managed credentials**: Google manages OAuth 2.0 credentials automatically without manual client setup.
   - **Custom OAuth** : Select this option if your organization requires [custom OAuth 2.0 credentials](https://docs.cloud.google.com/gemini/enterprise/docs/register-and-manage-an-a2a-agent.md.txt#authorize-your-agent), and then enter your client ID, client secret, authorization URL, and token URL.
7. Click **Finish**.

8. [Share the registered agent](https://docs.cloud.google.com/gemini/enterprise/docs/share-custom-agents.md.txt#share_an_agent)
   with authorized users and groups.

#### Option 2: Import using A2A card JSON

> [!WARNING]
>
> **Preview**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

If BigQuery and Gemini are in different projects
and you aren't using Agent Registry, import the A2A card JSON
directly:

1. In the Google Cloud console, go to the
   **Gemini Enterprise** page and select your app.

   [Go to Gemini Enterprise](https://console.cloud.google.com/gemini-enterprise/)
2. In the navigation menu, click **Agents** \> click **Add agent**.

3. In the **Choose an agent type** pane, locate **Custom agent via A2A** and
   click **Add**.

4. In the **Agent card JSON** field, enter the A2A card JSON copied from
   BigQuery.

5. Click **Preview agent details** \> click **Next**.

6. In the **Agent authorization** step, select **Default Google-managed
   credentials** or configure
   [Custom OAuth](https://docs.cloud.google.com/gemini/enterprise/docs/register-and-manage-an-a2a-agent.md.txt#authorize-your-agent),
   and then click **Finish**.

7. [Share the registered agent](https://docs.cloud.google.com/gemini/enterprise/docs/share-custom-agents.md.txt#share_an_agent)
   with authorized users and groups.

## Discover and query agents

After the administrator registers and shares the agent, business users can query
Cortex Framework data products in
[Gemini](https://docs.cloud.google.com/gemini/enterprise/docs/get-started.md.txt):

1. Open Gemini for your organization.
2. Discover or invoke the Cortex Framework data agent using any of the following methods:
   - **Browse the [Agent Gallery](https://docs.cloud.google.com/gemini/enterprise/docs/agent-gallery.md.txt)**: Select the data agent card to start a dedicated conversation.
   - **Use `@mention` in chat** : Enter `@` followed by the agent name (for example, `@Financial Analysis Agent`) in the main chat prompt to direct a question to that agent.
   - **Ask a question in the main chat** : Ask a natural-language question (for example, one of your configured verified queries (`goldenQueries`)) and let Gemini route the query to the matching data agent.
3. Complete the one-time OAuth 2.0 sign-in prompt to authorize queries against BigQuery with your user credentials, and then verify the returned SQL analysis, tables, or charts.

For full administrator prerequisites, region requirements, and discovery
options, see
[Publish a data agent in Gemini](https://docs.cloud.google.com/bigquery/docs/create-data-agents.md.txt#publish-agent-gemini-enterprise).

## What's next

- Review CLI flags in [CLI register Gemini
  agents](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-register-gemini-agents).
- Configure and synchronize data agents in [Conversational analytics integration](https://docs.cloud.google.com/cortex/docs/conversational-analytics.md.txt).
- Review data agent CLI flags in [CLI create conversational analytics
  agents](https://docs.cloud.google.com/cortex/docs/uv-run-cortex-create-ca-agents).
- View `conversationalAnalytics` and `gemini` schema settings in [Deployment configuration](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt#gemini-config).
- Synchronize governance metadata in [Knowledge Catalog
  integration](https://docs.cloud.google.com/cortex/docs/knowledge-catalog).
- Manage and monitor data agents in [Create data agents](https://docs.cloud.google.com/bigquery/docs/create-data-agents.md.txt).