googleapis / googleapis/python-aiplatform

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

Aperta
#6,112 0 commenti 4 reazioni 0 assegnatari Vedi su GitHub
api: vertex-ai
Lingua principale
Python
Stelle
905
Fork
465
Merge medio
1g 13h
PR unite (30g)
44

Descrizione

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!

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.