Use AWS MemoryCreated waiter in MemoryClient._wait_for_memory_active()

Đang mở
#248 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

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

Hướng nghiên cứu

Bắt đầu tại MemoryClient.wait_for_memory_active() và kiểm tra cách create_memory_and_wait(), add*_strategy_and_wait() và update_memory_strategies_and_wait() sử dụng nó. Xác minh cấu hình waiter memory_created và hành vi fallback, sau đó xác nhận rằng delete_memory_and_wait() vẫn sử dụng polling thủ công; hoàn thành khi các phương thức bị ảnh hưởng chờ thành công mà vẫn duy trì khả năng tương thích ngược.

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

Mô tả

Summary

Replace manual polling in MemoryClient._wait_for_memory_active() with the AWS memory_created waiter for more efficient waiting.

Current Implementation

The current _wait_for_memory_active() method uses manual polling with a default 10-second interval:

def _wait_for_memory_active(self, memory_id: str, max_wait: int, poll_interval: int) -> Dict[str, Any]:
    start_time = time.time()
    while time.time() - start_time < max_wait:
        status = self.get_memory_status(memory_id)
        if status == MemoryStatus.ACTIVE.value:
            return memory
        elif status == MemoryStatus.FAILED.value:
            raise RuntimeError(...)
        time.sleep(poll_interval)  # Default: 10 seconds
    raise TimeoutError(...)

Proposed Implementation

Use the memory_created waiter (confirmed available in boto3):

def _wait_for_memory_active(self, memory_id: str, max_wait: int = 300, poll_interval: int = 2) -> Dict[str, Any]:
    try:
        waiter = self.gmcp_client.get_waiter('memory_created')
        waiter.wait(
            memoryId=memory_id,
            WaiterConfig={
                'Delay': poll_interval,
                'MaxAttempts': max_wait // poll_interval
            }
        )
        # Get final memory state
        response = self.gmcp_client.get_memory(memoryId=memory_id)
        return self._normalize_memory_response(response["memory"])
    except Exception:
        # Fallback to manual polling for backwards compatibility
        return self._wait_for_memory_active_polling(memory_id, max_wait, poll_interval)

Benefits

Aspect Manual Polling AWS Waiter
Default poll interval 10s 2s
Error handling Custom AWS-managed
Retry logic Custom Built-in
Maintenance SDK team AWS/botocore

Affected Methods

This change would improve the following methods that use _wait_for_memory_active():

  • create_memory_and_wait()
  • add_*_strategy_and_wait() methods
  • update_memory_strategies_and_wait()

Backwards Compatibility

Include fallback to manual polling if:

  • Waiter is not available in older boto3 versions
  • Waiter fails unexpectedly

Notes

  • The memory_created waiter is confirmed available: client.waiter_names returns ['memory_created']
  • No memory_deleted waiter exists, so delete_memory_and_wait() must continue using manual polling
Ngôn ngữ chính
Python
Star
786
Fork
163
Merge trung bình
4 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aws/bedrock-agentcore-sdk-python

Tất cả issue của aws/bedrock-agentcore-sdk-python

Issue tương tự

Thêm issue về Python

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.