googleapis / googleapis/python-aiplatform

In the "agent_engine" module, the function "async_stream_query" on a remote app, blocks the thread

オープン
#6,112 コメント 0 件 リアクション 4 件 担当者 0 名 GitHub で見る
api: vertex-ai
主要言語
Python
スター
905
フォーク
465
平均マージ
1日 13時間
マージ済み PR(30日)
44

説明

There seems to be an issue with the "async_stream_query" function, when trying to invoke it on a remote app deployed in Vertex AI Agents Engine
This should be an asynchronous generator, but it blocks the entire thread until all the results are returned from the app
When using the same function on a local running agent, it does work as expected

#### Environment details

- OS type and version: macOS 15.6.1
- Python version: 3.12.8
- uv version: 0.5.7
- `google-cloud-aiplatform` version: 1.126.1

#### Steps to reproduce

1. Deploy to GCP Agents Engine an agent with tool that take long time to run
2. Run the following code:

```python
import asyncio
from vertexai import agent_engines
import vertexai

PROJECT_ID = "..."
LOCATION = "..."
STAGING_BUCKET = "..."

vertexai.init(
project=PROJECT_ID,
location=LOCATION,
staging_bucket=STAGING_BUCKET,
)

async def run_local_loop():
while True:
await asyncio.sleep(1)
print("ping")

async def run_remote_app():
await asyncio.sleep(3)
remote_app = agent_engines.get(
resource_name="...",
)

async for event in remote_app.async_stream_query(
user_id="test_user",
message="test message",
):
print(event)

async def main():
await asyncio.gather(run_local_loop(), run_remote_app())

asyncio.run(main())
```
The above code will start printing "ping" every second, but once it reaches the "async_stream_query", it will stop, blocking the thread

But if instead of using the "agent_engines.get" to get a remote app, you create a local app:
```
agent_engines.AdkApp(
agent=root_agent,
enable_tracing=True,
)
```
The code does work as expected and it will keep printing "ping" every second, while waiting for events from the app

Please take a look and let me know if it is indeed an issue or am I missing something here
Thanks!

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。