|
| 1 | +# Vertex Agent |
| 2 | + |
| 3 | +The Vertex Agent executes flow runs as [Vertex Custom Jobs](https://cloud.google.com/vertex-ai/docs/training/create-custom-job). |
| 4 | +Vertex describes these as "training" jobs, but they can be used to run any kind of flow. |
| 5 | + |
| 6 | +## Requirements |
| 7 | + |
| 8 | +The required dependencies for the Vertex Agent aren't [installed by |
| 9 | +default](/core/getting_started/installation.md). If you're a `pip` user you'll |
| 10 | +need to add the `gcp` extra. Likewise, with `conda` you'll need to install |
| 11 | +`google-cloud-aiplatform`: |
| 12 | + |
| 13 | +:::: tabs |
| 14 | +::: tab Pip |
| 15 | + |
| 16 | +```bash |
| 17 | +pip install prefect[gcp] |
| 18 | +``` |
| 19 | + |
| 20 | +::: |
| 21 | +::: tab Conda |
| 22 | + |
| 23 | +```bash |
| 24 | +conda install -c conda-forge prefect google-cloud-aiplatform |
| 25 | +``` |
| 26 | + |
| 27 | +::: |
| 28 | +:::: |
| 29 | + |
| 30 | +::: warning Prefect Server |
| 31 | +In order to use this agent with Prefect Server the server's GraphQL API |
| 32 | +endpoint must be accessible. This _may_ require changes to your Prefect Server |
| 33 | +deployment and/or [configuring the Prefect API |
| 34 | +address](./overview.md#prefect-api-address) on the agent. |
| 35 | +::: |
| 36 | + |
| 37 | +## Flow Configuration |
| 38 | + |
| 39 | +The Vertex Agent will deploy flows using either a |
| 40 | +[UniversalRun](/orchestration/flow_config/run_configs.md#universalrun) (the |
| 41 | +default) or [VertexRun](/orchestration/flow_config/run_configs.md#vertexrun) |
| 42 | +`run_config`. Using a `VertexRun` object lets you customize the deployment |
| 43 | +environment for a flow (exposing `env`, `image`, `machine_type`, etc...): |
| 44 | + |
| 45 | +```python |
| 46 | +from prefect.run_configs import VertexRun |
| 47 | + |
| 48 | +# Configure extra environment variables for this flow, |
| 49 | +# and set a custom image and machine type |
| 50 | +flow.run_config = VertexRun( |
| 51 | + env={"SOME_VAR": "VALUE"}, |
| 52 | + image="my-custom-image", |
| 53 | + machine_type="e2-highmem-16", |
| 54 | +) |
| 55 | +``` |
| 56 | + |
| 57 | +See the [VertexRun](/orchestration/flow_config/run_configs.md#vertexrun) |
| 58 | +documentation for more information. |
| 59 | + |
| 60 | +## Agent Configuration |
| 61 | + |
| 62 | +The Vertex agent can be started from the Prefect CLI as |
| 63 | + |
| 64 | +```bash |
| 65 | +prefect agent vertex start |
| 66 | +``` |
| 67 | + |
| 68 | +::: tip API Keys <Badge text="Cloud"/> |
| 69 | +When using Prefect Cloud, this will require a service account API key, see |
| 70 | +[here](./overview.md#api_keys) for more information. |
| 71 | +::: |
| 72 | + |
| 73 | +Below we cover a few common configuration options, see the [CLI |
| 74 | +docs](/api/latest/cli/agent.md#vertex-start) for a full list of options. |
| 75 | + |
| 76 | +### Project |
| 77 | + |
| 78 | +By default the agent will deploy flow run tasks into the current project (as defined by [google.auth.default](https://google-auth.readthedocs.io/en/latest/reference/google.auth.html)) |
| 79 | +You can specify a different project using the `--project` option: |
| 80 | + |
| 81 | +```bash |
| 82 | +prefect agent vertex start --project my-project |
| 83 | +``` |
| 84 | + |
| 85 | +This can be a different project than the agent is running in, as long as the account has permissions |
| 86 | +to start Vertex Custom Jobs in the specified project. |
| 87 | + |
| 88 | +### Region |
| 89 | + |
| 90 | +Vertex requires a region in which to run the flow, and will default to `us-central1` |
| 91 | +You can specify a different region using the `--region-name` option: |
| 92 | + |
| 93 | +```bash |
| 94 | +prefect agent vertex start --region-name us-east1 |
| 95 | +``` |
| 96 | + |
| 97 | +### Service Account |
| 98 | + |
| 99 | +Vertex jobs can run as a specified service account. Vertex provides a default, but specifying a specific |
| 100 | +account can give you more control over what resources the flow runs are allowed to access. |
| 101 | +You can specify a non-default account using the `--service-account` option: |
| 102 | + |
| 103 | +```bash |
| 104 | +prefect agent vertex start --service-account [email protected] |
| 105 | +``` |
| 106 | + |
0 commit comments