Menyiapkan lingkungan

Sebelum menggunakan Vertex AI Agent Engine, Anda harus memastikan lingkungan Anda sudah disiapkan. Anda harus memiliki Google Cloud project dengan penagihan yang diaktifkan, memiliki izin yang diperlukan, menyiapkan bucket Cloud Storage, dan menginstal Vertex AI SDK untuk Python. Gunakan topik berikut untuk memastikan Anda siap mulai menggunakan Vertex AI Agent Engine.

Untuk contoh Terraform referensi guna menyederhanakan penyiapan dan deployment lingkungan Vertex AI Agent Engine, pertimbangkan untuk menjelajahi agent-starter-pack.

Menyiapkan Google Cloud project

Setiap project dapat diidentifikasi dengan dua cara: nomor project atau project ID. PROJECT_NUMBER dibuat secara otomatis saat Anda membuat project, sedangkan PROJECT_ID dibuat oleh Anda, atau siapa pun yang membuat project. Untuk menyiapkan project:

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI, Cloud Storage, Cloud Logging, Cloud Monitoring, and Cloud Trace APIs.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI, Cloud Storage, Cloud Logging, Cloud Monitoring, and Cloud Trace APIs.

    Enable the APIs

Mendapatkan peran yang diperlukan

Untuk mendapatkan izin yang Anda perlukan untuk menggunakan Vertex AI Agent Engine, minta administrator untuk memberi Anda peran IAM berikut di project Anda:

Untuk mengetahui informasi selengkapnya tentang cara memberikan peran, lihat Mengelola akses ke project, folder, dan organisasi.

Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran khusus atau peran bawaan lainnya.

Menyiapkan izin agen layanan

Agen yang Anda deploy di Vertex AI Agent Engine berjalan menggunakan akun layanan Agen Layanan AI Platform Reasoning Engine. Akun ini memiliki peran Vertex AI Reasoning Engine Service Agent yang memberikan izin default yang diperlukan untuk agen yang di-deploy. Anda dapat melihat daftar lengkap izin default di dokumentasi IAM.

Jika memerlukan izin tambahan, Anda dapat memberikan peran tambahan kepada Agen Layanan ini dengan melakukan langkah-langkah berikut:

  1. Buka halaman IAM, lalu centang kotak "Sertakan pemberian peran yang disediakan Google".

    Buka IAM

  2. Temukan akun utama yang cocok dengan service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com.

  3. Tambahkan peran yang diperlukan ke akun utama dengan mengklik tombol edit, lalu tombol simpan.

Membuat Agen Layanan Secara Manual

Meskipun Agen Layanan Reasoning Engine disediakan secara otomatis selama deployment Vertex AI Agent Engine, mungkin ada skenario saat Anda perlu membuatnya secara manual terlebih dahulu. Hal ini sangat penting saat Anda perlu memberikan peran tertentu kepada agen layanan untuk memastikan proses deployment memiliki izin yang diperlukan dan menghindari potensi kegagalan deployment.

Berikut adalah langkah-langkah untuk membuat Agen Layanan Reasoning Engine secara manual:

  1. Buat Agen Layanan Reasoning Engine menggunakan Google Cloud CLI.

    gcloud beta services identity create --service=aiplatform.googleapis.com --project=PROJECT-ID-OR-PROJECT-NUMBER
  2. Buka halaman IAM, lalu klik Berikan Akses.

    Buka IAM

  3. Di bagian Add principals, di kolom New principals, masukkan service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com.

  4. Di bagian Assign roles, cari dan pilih peran yang Anda perlukan.

  5. Klik tombol Save.

Membuat bucket Cloud Storage

Vertex AI Agent Engine melakukan staging artefak agen yang di-deploy di bucket Cloud Storage sebagai bagian dari proses deployment. Pastikan akun utama yang diautentikasi untuk menggunakan Vertex AI (baik Anda sendiri maupun akun layanan) memiliki akses Storage Admin ke bucket ini. Hal ini diperlukan karena Vertex AI SDK untuk Python menulis kode Anda ke bucket ini.

Jika sudah menyiapkan bucket, Anda dapat melewati langkah ini. Jika tidak, Anda dapat mengikuti petunjuk standar untuk membuat bucket.

Google Cloud console

  1. In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets

  2. Click Create.
  3. On the Create a bucket page, enter your bucket information. To go to the next step, click Continue.
    1. In the Get started section, do the following:
      • Enter a globally unique name that meets the bucket naming requirements.
      • To add a bucket label, expand the Labels section (), click Add label, and specify a key and a value for your label.
    2. In the Choose where to store your data section, do the following:
      1. Select a Location type.
      2. Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
      3. To set up cross-bucket replication, select Add cross-bucket replication via Storage Transfer Service and follow these steps:

        Set up cross-bucket replication

        1. In the Bucket menu, select a bucket.
        2. In the Replication settings section, click Configure to configure settings for the replication job.

          The Configure cross-bucket replication pane appears.

          • To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
          • To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
          • Click Done.
    3. In the Choose how to store your data section, do the following:
      1. Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
      2. To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
    4. In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
    5. In the Choose how to protect object data section, do the following:
      • Select any of the options under Data protection that you want to set for your bucket.
        • To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
        • To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
        • To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
          • To enable Object Retention Lock, click the Enable object retention checkbox.
          • To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
      • To choose how your object data will be encrypted, expand the Data encryption section (), and select a Data encryption method.
  4. Click Create.

Command line

    Create a Cloud Storage bucket and configure it as follows:
    • Ganti STORAGE_CLASS dengan kelas penyimpanan pilihan Anda.
    • Ganti LOCATION dengan lokasi pilihan Anda (ASIA, EU, atau US)
    • Ganti BUCKET_NAME dengan nama bucket yang memenuhi persyaratan nama bucket.
    • gcloud storage buckets create gs://BUCKET_NAME --default-storage-class STORAGE_CLASS --location LOCATION

Menginstal dan melakukan inisialisasi Vertex AI SDK untuk Python

Bagian ini mengasumsikan bahwa Anda telah menyiapkan lingkungan pengembangan Python, atau menggunakan Colab (atau runtime lain yang sesuai yang telah menyiapkannya untuk Anda).

(Opsional) Menyiapkan lingkungan virtual

Sebaiknya siapkan lingkungan virtual untuk mengisolasi dependensi Anda.

Penginstalan

Untuk meminimalkan kumpulan dependensi yang harus Anda instal, kami telah memisahkan dependensi menjadi:

  • agent_engines: kumpulan paket yang diperlukan untuk deployment ke Vertex AI Agent Engine.
  • adk: kumpulan paket Agent Development Kit yang kompatibel.
  • langchain: kumpulan paket LangChain dan LangGraph yang kompatibel.
  • ag2: kumpulan paket AG2 yang kompatibel.
  • llama_index: kumpulan paket LlamaIndex yang kompatibel.

Saat menginstal Vertex AI SDK untuk Python, Anda dapat menentukan dependensi yang diperlukan (dipisahkan koma). Untuk menginstal semuanya:

pip install google-cloud-aiplatform[agent_engines,adk,langchain,ag2,llama_index]>=1.88.0

Autentikasi

Colab

Jalankan kode berikut:

from google.colab import auth

auth.authenticate_user(project_id="PROJECT_ID")

Cloud Shell

Tindakan tidak diperlukan.

Shell Lokal

Jalankan perintah berikut:

gcloud auth application-default login

Mengimpor dan melakukan inisialisasi SDK

Jalankan kode berikut untuk mengimpor dan melakukan inisialisasi SDK untuk Vertex AI Agent Engine:

import vertexai
from vertexai import agent_engines

vertexai.init(
    project="PROJECT_ID",
    location="LOCATION",
    staging_bucket="gs://BUCKET_NAME",
)

di mana

Langkah berikutnya