You can use Eventarc to automatically monitor and respond to activity
from Proactive Mode in Gemini Cloud Assist.

When an agent completes a background task---such as a root-cause investigation
or a cost anomaly analysis---it publishes an event that you can route to a
webhook, a script, or a workflow.

## Before you begin

- Ensure you have [set up Proactive Mode](https://docs.cloud.google.com/cloud-assist/proactive-agents-setup).
- [Install and initialize](https://docs.cloud.google.com/sdk/docs/install-sdk) the Google Cloud CLI if you haven't already done so.

## Create an automation trigger

Gemini Cloud Assist generates a
`google.cloud.geminicloudassist.task.v1.completed` event whenever a background
investigation or optimization task finishes.

You can route these events to [supported destinations](https://docs.cloud.google.com/eventarc/standard/docs/overview#targets)
like Cloud Run, Cloud Run functions, or Workflows, to trigger
Slack notifications, PagerDuty incidents, or automated remediations.

For example, to subscribe to these events and route them to Cloud Run,
use the following command:

```
gcloud eventarc triggers create TRIGGER_NAME \
    --location=global \
    --destination-run-service=DESTINATION_SERVICE \
    --event-filters="type=google.cloud.geminicloudassist.task.v1.completed" \
    --event-filters="proactive=true" \
    --service-account=SERVICE_ACCOUNT
```

Replace the following:

- `<var>TRIGGER_NAME</var>`: A unique name for your trigger.
- `<var>DESTINATION_SERVICE</var>`: The name of your Cloud Run service that will process your Proactive Agent events.
- `<var>SERVICE_ACCOUNT</var>`: The email address of the IAM service account used to invoke the destination.

For more information on using this command, see
[Create triggers with Eventarc](https://docs.cloud.google.com/run/docs/triggering/trigger-with-events).

## Event payload

The payload of a delivered event is in Protobuf format, wrapped in Cloud Events,
or JSON. It contains the following key fields:

- `title`: A summary of the task, such as "Cost Anomaly Investigation" or "Investigation of High Latency".
- `result_object_reference`: A URI pointing to the created artifact.

### Filtering for specific agents

Because proactive mode uses the same event type, you cannot isolate specific
agents using Eventarc attributes alone.

To route events to specific channels, your destination service, such as a
Cloud Function, must parse the event payload and filter based on the
`title` field:

- To monitor cost alerts, filter for titles containing "Cost Anomaly" or "Cost Optimization".
- To monitor troubleshooting, filter for titles containing "Investigation of".

## What's next

- Learn how to [use Proactive Mode for cost optimization](https://docs.cloud.google.com/cloud-assist/proactive-cost-optimization).
- Review [IAM requirements](https://docs.cloud.google.com/cloud-assist/iam-requirements) for agents.