aws / aws/bedrock-agentcore-sdk-python
Use AWS MemoryCreated waiter in MemoryClient._wait_for_memory_active()
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 764
- Forks
- 148
- Merge moyen
- 1 j 23 h
- PR mergées (30 j)
- 7
Description
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()methodsupdate_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_createdwaiter is confirmed available:client.waiter_namesreturns['memory_created'] - No
memory_deletedwaiter exists, sodelete_memory_and_wait()must continue using manual polling
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par MemoryClient.wait_for_memory_active() et examinez comment create_memory_and_wait(), add*_strategy_and_wait() et update_memory_strategies_and_wait() l’utilisent. Vérifiez la configuration du waiter memory_created et le comportement de fallback, puis confirmez que delete_memory_and_wait() utilise toujours un polling manuel ; le travail est considéré comme terminé lorsque les méthodes concernées attendent correctement tout en préservant la rétrocompatibilité.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- aws, python
- Domaine
- api, backend
- Type d'issue
- Refactorisation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 48/100