googleapis / googleapis/python-aiplatform

[Agent Engine][Adk] app_name mismatch between AdkApp._tmpl_attrs and Runner causes GCS artifact lookup failures in Agent Engine

未关闭
#6,521 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
api: vertex-ai
主要语言
Python
星标
907
派生
466
平均合并
1 天 13 小时
30 天内合并 PR
44

描述

#### Environment details

- **OS type and version**: Linux (Vertex AI Agent Engine environment)
- **Python version**: `Python 3.11+`
- **`google-cloud-aiplatform` version**: `1.143.0`

#### Steps to reproduce

1. Create an agent via Google ADK exposing tools that generate or return visual artifacts (images/videos) using `tool_context.save_artifact()`.
2. Instantiate and wrap the ADK agent into a Vertex AI SDK template using `AdkApp` (from `vertexai.agent_engines.templates.adk`).
3. Deploy this agent to **Agent Engine** (Vertex AI platform container mapping to Gemini Enterprise).
4. Trigger any tool that saved an artifact from the UI chat.

#### Root Cause Analysis

The issue occurs because the application name used by the container falls back onto the ID assigned by the Cloud platform if not explicitly provided, while the Runner defaults to the name defined in the ADK `App` instance.

In `AdkApp.set_up()`, the fallback logic is as follows:

```python
# AdkApp.set_up() fallback logic
if not self._tmpl_attrs.get("app_name"):
if "GOOGLE_CLOUD_AGENT_ENGINE_ID" in os.environ:
self._tmpl_attrs["app_name"] = os.environ.get(
"GOOGLE_CLOUD_AGENT_ENGINE_ID",
)
else:
self._tmpl_attrs["app_name"] = _DEFAULT_APP_NAME
```

However, the `Runner` created later defaults to `app.name` (the static default `"app"` in ADK if not overridden):

```python
# Runner._validate_runner_params defaults to app.name
app_name = app_name or app.name # resolves to "app" instead of the ID
```

This creates a mismatch failure during session artifact reads in `_convert_response_events`.

#### Actual Behavior

- **Save Path** evaluates using `app.name` (e.g., `"app"` or a custom name like `"mova"`):
`GCS_BUCKET/app/{user_id}/{session_id}/artifact.png`

- **Load Path** evaluates using `AdkApp._tmpl_attrs["app_name"]` (e.g., the numerical ID assigned by Google Cloud):
`GCS_BUCKET/8269664996770709504/{user_id}/{session_id}/artifact.png`

Because strings like `"app"` and `"8269664996770709504"` on bucket paths do not map identically, files aren't found on state loads, and the Gemini Enterprise UI draws empty boxes or fails to render the media.

Moreover, if the user tries to use `GOOGLE_CLOUD_AGENT_ENGINE_ID` directly to solve the mismatch, the purely numerical ID causes Pydantic validation failures on boot because it is not a valid Python identifier (starts with a digit).

#### Expected Behavior

The `AdkApp` should ensure that the `app_name` in its template attributes matches the `name` of the ADK `App` being wrapped, or provide a clean way to synchronize them, rather than falling back to the numerical `GOOGLE_CLOUD_AGENT_ENGINE_ID`.

#### Workaround Applied

To fix this manually in user code, one can override `_tmpl_attrs["app_name"]` after calling `super().set_up()` in the custom `AdkApp` class:

```python
class AgentEngineApp(AdkApp):

def set_up(self) -> None:
super().set_up()
# Enforce that AdkApp uses the same name as the ADK App
self._tmpl_attrs["app_name"] = adk_app.name
```

贡献指南

打开贡献指南

调研方向

从 vertexai.agent_engines.templates.adk 开始,检查 AdkApp.set_up(),然后将其模板 app_name 与 Runner._validate_runner_params 和 _convert_response_events 进行比较。使用所述的 Agent Engine 环境复现工件保存/加载路径,并确认使用的是被包装的 ADK App 名称,且不依赖数值型 GOOGLE_CLOUD_AGENT_ENGINE_ID。

由索引模型根据 Issue 内容生成。

评估

技术栈
google-cloud, python
领域
ai, backend, cloud
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。