googleapis / googleapis/python-aiplatform

[Agent Engines] `_wrap_async_stream_query_operation` blocks asyncio event loop due to synchronous gRPC iteration

Đang mở
#7,136 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
api: vertex-ai
Ngôn ngữ chính
Python
Star
905
Fork
465
Merge trung bình
1 ngày 13 giờ
Pull request đã merge (30 ngày)
44

Mô tả

`agent_engine.async_stream_query(...)` blocks the calling `asyncio` event loop thread during stream generation.

In `vertexai/agent_engines/_agent_engines.py`, `_wrap_async_stream_query_operation` wraps a synchronous client call in an `async def` and uses a blocking `for` loop:

```python
# CURRENT IMPLEMENTATION (vertexai/agent_engines/_agent_engines.py)
def _wrap_async_stream_query_operation(*, method_name: str):
async def _method(self, **kwargs):
# 1. Uses sync client instead of self.execution_async_client
response = self.execution_api_client.stream_query_reasoning_engine(...)
# 2. Synchronous iteration blocks the asyncio event loop on socket reads
for chunk in response:
for parsed_json in _utils.yield_parsed_json(chunk):
if parsed_json is not None:
yield parsed_json
return _method
```

### Reproduction:
```python
import asyncio
from vertexai import agent_engines

agent = agent_engines.get("projects/

/locations//reasoningEngines/")

async def main():
async for chunk in agent.async_stream_query(user_id="u", message="Long prompt"):
pass

asyncio.run(main(), debug=True)
# Result: Emits "Executing took X.XX seconds" because the thread is blocked on socket reads without yielding.
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start in vertexai/agent_engines/_agent_engines.py at _wrap_async_stream_query_operation and compare the synchronous execution_api_client call with self.execution_async_client. Reproduce the stream with asyncio.run(..., debug=True); done means async_stream_query no longer blocks the event-loop thread during socket reads while still yielding parsed chunks.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
grpc, python
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
72/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.