![[新サービス] ADK で開発した AI エージェントを Vertex AI Agent Engine にデプロイする #GoogleCloudNext](https://images.ctfassets.net/ct0aopd36mqt/mfvnpH15PsVPOaNIwYZ33/4e17c25441441bdd9f44672815983fd3/eyechatch_googlecloudnext25.png)
[新サービス] ADK で開発した AI エージェントを Vertex AI Agent Engine にデプロイする #GoogleCloudNext
はじめに
2025/4/9-11 の 3日間の日程で Google Cloud Next '25 がラスベガスで開催されています!
開催期間中には AI エージェントの開発や運用に関する様々なサービスやアップデートがリリースされました。今回はリリースの中から Agent Development Kit(ADK) と Vertex AI Agent Engine を実際に試してみます。ADK で開発した AI エージェントを Vertex AI Agent Engine にデプロイする検証をしてみます。
Agent Development Kit(ADK) とは
Agent Development Kit(ADK) とは、エージェントを設計するためのオープンソースフレームワークです。
ADK を利用することで直感的かつ少ないコード量でAIエージェントを構築することができます。
詳細は以下をご参照ください。
Vertex AI Agent Engine とは
Vertex AI Agent Engine は Google Cloud Next '25 にてプレビューリリースが発表された新たなサービスで、開発者が本番環境で AI エージェントをデプロイ、管理、スケールできるようにするためのフルマネージドな Vertex AI 組み込みのサービスです。 VPC-SC サポートなどエンタープライズレベルのセキュリティ、コントロール、監視、ログ機能に加え、評価や品質のフレームワークも提供されます。
詳細は以下をご参照ください。
やってみた
ドキュメントを参考に、ADK で開発した AI エージェントを Agent Engine にデプロイしていきます。なお、こちらの機能については 現在プレビュー となっています。
本検証では Colab を使って手順を追って動作確認していきます。
なお、Colab を実行するユーザには Google Cloud 上でオーナー権限を持たせています。Google Cloud プロジェクトの操作もオーナー権限を持つユーザで実行しています。
Google Cloud プロジェクトの準備
デプロイ対象の Google Cloud プロジェクトの Vertex AI API を有効化します。Cloud Shell から以下コマンドを実行します。
gcloud services enable aiplatform.googleapis.com
必要に応じて Agent Engine のステージング用 Cloud Storage バケットを準備します。
gcloud storage buckets create gs://<Backet Name> \
--location=us-central1 \
Vertex AI SDK と ADK のインストール
ここから Colab で実行していきます。
Vertex AI SDK のライブラリを利用してデプロイを行うため、Vertex AI SDK をインストールします。また、エージェント開発のため ADK をインストールします。
pip install --upgrade google-cloud-aiplatform[adk,agent_engines] google-adk
Vertex AI SDK と ADK のインストール
Colab を実行するユーザで Google Cloud の認証ができるよう以下を実行します。
from google.colab import auth
auth.authenticate_user()
Vertex AI Agent Engine の初期化
以下を実行し、Agent Engine を初期化します。
ステージング用の STAGING_BUCKET には先ほど作成した Cloud Storage バケットを指定します。
import vertexai
PROJECT_ID = "your-project-id"
LOCATION = "us-central1"
STAGING_BUCKET = "gs://your-google-cloud-storage-bucket"
vertexai.init(
project=PROJECT_ID,
location=LOCATION,
staging_bucket=STAGING_BUCKET,
)
AI エージェントの準備
ADK で開発した AI エージェントを用意します。
import datetime
from zoneinfo import ZoneInfo
from google.adk.agents import Agent
def get_weather(city: str) -> dict:
"""Retrieves the current weather report for a specified city.
Args:
city (str): The name of the city for which to retrieve the weather report.
Returns:
dict: status and result or error msg.
"""
if city.lower() == "new york":
return {
"status": "success",
"report": (
"The weather in New York is sunny with a temperature of 25 degrees"
" Celsius (41 degrees Fahrenheit)."
),
}
else:
return {
"status": "error",
"error_message": f"Weather information for '{city}' is not available.",
}
def get_current_time(city: str) -> dict:
"""Returns the current time in a specified city.
Args:
city (str): The name of the city for which to retrieve the current time.
Returns:
dict: status and result or error msg.
"""
if city.lower() == "new york":
tz_identifier = "America/New_York"
else:
return {
"status": "error",
"error_message": (
f"Sorry, I don't have timezone information for {city}."
),
}
tz = ZoneInfo(tz_identifier)
now = datetime.datetime.now(tz)
report = (
f'The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}'
)
return {"status": "success", "report": report}
root_agent = Agent(
name="weather_time_agent",
model="gemini-2.0-flash-exp",
description=(
"Agent to answer questions about the time and weather in a city."
),
instruction=(
"I can answer your questions about the time and weather in a city."
),
tools=[get_weather, get_current_time],
)
このエージェントは以下ブログで構築したものと同様です。動作については以下ブログをご参照ください。
Agent Engine デプロイの準備
reasoning_engines.AdkApp()
で AI エージェントをラップし、Agent Engine にデプロイできるようにします。
from vertexai.preview import reasoning_engines
app = reasoning_engines.AdkApp(
agent=root_agent,
enable_tracing=True,
)
デプロイ前の動作確認
デプロイ前にローカルで動作確認します。user_id="u_123"
でセッションを作成します。
session = app.create_session(user_id="u_123")
session
セッションが作成され、以下のような結果が返ってくるはずです。
Session(id='c6a33dae-26ef-410c-9135-b434a528291f', app_name='default-app-name', user_id='u_123', state={}, events=[], last_update_time=1743440392.8689594)
セッションを利用して AI エージェントにクエリを実行します。
for event in app.stream_query(
user_id="u_123",
session_id=session.id,
message="whats the weather in new york",
):
print(event)
以下のようなレスポンスが返ってきます。
{'content': {'parts': [{'function_call': {'id': 'adk-80c8f20e-b92a-410b-b915-8ad2ebacda37', 'args': {'city': 'new york'}, 'name': 'get_weather'}}], 'role': 'model'}, 'invocation_id': 'e-830061f5-aee3-43a4-9d16-85d4abe05040', 'author': 'weather_time_agent', 'actions': {'state_delta': {}, 'artifact_delta': {}, 'requested_auth_configs': {}}, 'long_running_tool_ids': set(), 'id': 'tpspNQjQ', 'timestamp': 1744400733.18087}
{'content': {'parts': [{'function_response': {'id': 'adk-80c8f20e-b92a-410b-b915-8ad2ebacda37', 'name': 'get_weather', 'response': {'status': 'success', 'report': 'The weather in New York is sunny with a temperature of 25 degrees Celsius (41 degrees Fahrenheit).'}}}], 'role': 'user'}, 'invocation_id': 'e-830061f5-aee3-43a4-9d16-85d4abe05040', 'author': 'weather_time_agent', 'actions': {'state_delta': {}, 'artifact_delta': {}, 'requested_auth_configs': {}}, 'id': 'AvbMQVSe', 'timestamp': 1744400734.342737}
{'content': {'parts': [{'text': 'OK. The weather in New York is sunny with a temperature of 25 degrees Celsius (41 degrees Fahrenheit).\n'}], 'role': 'model'}, 'invocation_id': 'e-830061f5-aee3-43a4-9d16-85d4abe05040', 'author': 'weather_time_agent', 'actions': {'state_delta': {}, 'artifact_delta': {}, 'requested_auth_configs': {}}, 'id': '5EhIO6qA', 'timestamp': 1744400734.344951}
Agent Engine へのデプロイ
以下コードを入力し、Agent Engine に AI エージェントをデプロイします。
from vertexai import agent_engines
remote_app = agent_engines.create(
agent_engine=root_agent,
requirements=[
"google-cloud-aiplatform[adk,agent_engines]"
]
)
Google Cloud の Cloud Logging ログエクスプローラーからデプロイプロセスが確認できます。
Colab 上の実行ログから以下のようなリソース名も確認できます。
projects/<Project No>/locations/us-central1/reasoningEngines/3536038191020638208
数分でデプロイが完了します。
Agent Engine を生成するとサービスアカウント(Vertex AI Reasoning Engine サービスエージェント)が生成されるので、 Vertex AI ユーザー(roles/aiplatform.user の IAM ロールを付与します。Google Cloud の Cloud Shell から以下コマンドを実行します。
gcloud projects add-iam-policy-binding <Project ID> \
--member="serviceAccount:service-<Project Number>@gcp-sa-aiplatform-re.iam.gserviceaccount.com" \
--role="roles/aiplatform.user"
ちなみに Agent Engine は Cloud Console の UI がまだ用意されておらず、UI 上からはデプロイされたことが確認できません。[Vertex AI] -> [Agent Engine] をクリックすると、以下の画面が確認できます。
クエリを投げてみる
Agent Engine にデプロイした AI エージェントにクエリを実行してみます。
Colab に戻り user_id="u_456"
でセッションを作成します。
remote_session = remote_app.create_session(user_id="u_456")
remote_session
クエリを実行します。
for event in remote_app.stream_query(
user_id="u_456",
session_id=remote_session["id"],
message="whats the weather in new york",
):
print(event)
レスポンスが返ってきました。
{'content': {'parts': [{'function_call': {'id': 'adk-c926b680-e1d4-4ef9-930a-909f2718c947', 'args': {'city': 'new york'}, 'name': 'get_weather'}}], 'role': 'model'}, 'invocation_id': 'e-1ac5560d-3c48-4c4f-b86d-3ac74d70ffeb', 'author': 'weather_time_agent', 'actions': {'state_delta': {}, 'artifact_delta': {}, 'requested_auth_configs': {}}, 'long_running_tool_ids': [], 'id': 'na7IE32q', 'timestamp': 1744401768.538494}
{'content': {'parts': [{'function_response': {'id': 'adk-c926b680-e1d4-4ef9-930a-909f2718c947', 'name': 'get_weather', 'response': {'status': 'success', 'report': 'The weather in New York is sunny with a temperature of 25 degrees Celsius (41 degrees Fahrenheit).'}}}], 'role': 'user'}, 'invocation_id': 'e-1ac5560d-3c48-4c4f-b86d-3ac74d70ffeb', 'author': 'weather_time_agent', 'actions': {'state_delta': {}, 'artifact_delta': {}, 'requested_auth_configs': {}}, 'id': 'vukpsM4P', 'timestamp': 1744401769.417328}
{'content': {'parts': [{'text': 'OK. The weather in New York is sunny with a temperature of 25 degrees Celsius (41 degrees Fahrenheit).\n'}], 'role': 'model'}, 'invocation_id': 'e-1ac5560d-3c48-4c4f-b86d-3ac74d70ffeb', 'author': 'weather_time_agent', 'actions': {'state_delta': {}, 'artifact_delta': {}, 'requested_auth_configs': {}}, 'id': 'U1Q5Kqnb', 'timestamp': 1744401769.501067}
クリーンアップ
Agent Engine は Cloud Console 上からデプロイの確認ができないため、現時点ではステータスが確認しづらいです。
デプロイされたエージェントは vCPU とメモリの使用時間で課金されるため、検証が終わったら忘れずにクリーンアップします。(料金についての詳細)
remote_app.delete(force=True)
おわりに
Google Cloud Next '25 の Developer Keynote セッションでは、ADK で開発したマルチエージェントシステムを Agent Engine にデプロイし、Google Agentspace で利用するといったユースケースを紹介していました。セッションの内容は以下ブログでもレポートしていますので、実際のユースケースの参考にしていただければと思います。