aws / aws/bedrock-agentcore-sdk-python

Use AWS MemoryCreated waiter in MemoryClient._wait_for_memory_active()

Aperta
#248 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
761
Fork
147
Merge medio
1g 23h
PR unite (30g)
7

Descrizione

## 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:

```python
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):

```python
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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da MemoryClient._wait_for_memory_active() e verifica come viene utilizzato da create_memory_and_wait(), add_*_strategy_and_wait() e update_memory_strategies_and_wait(). Verifica la configurazione del waiter memory_created e il comportamento di fallback, quindi conferma che delete_memory_and_wait() utilizzi ancora il polling manuale; il lavoro è completato quando i metodi interessati attendono correttamente preservando la retrocompatibilità.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, python
Ambito
api, backend
Tipo di issue
Refactoring
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.