|
42 | 42 | update_todo, |
43 | 43 | view_todo_list, |
44 | 44 | ) |
| 45 | +from lib.idp_common_pkg.idp_common.utils.bedrock_utils import ( |
| 46 | + async_exponential_backoff_retry, |
| 47 | +) |
45 | 48 |
|
46 | 49 | # Use AWS Lambda Powertools Logger for structured logging |
47 | 50 | # Automatically logs as JSON with Lambda context, request_id, timestamp, etc. |
@@ -458,6 +461,16 @@ def patch_buffer_data(patches: list[dict[str, Any]], agent: Agent) -> str: |
458 | 461 | """ |
459 | 462 |
|
460 | 463 |
|
| 464 | +@async_exponential_backoff_retry( |
| 465 | + max_retries=50, |
| 466 | + initial_delay=5, |
| 467 | + max_delay=1800, |
| 468 | + jitter=0.5, |
| 469 | +) |
| 470 | +async def invoke_agent_with_retry(input: Any, agent: Agent): |
| 471 | + return await agent.invoke_async(input) |
| 472 | + |
| 473 | + |
461 | 474 | async def structured_output_async( |
462 | 475 | model_id: str, |
463 | 476 | data_format: type[TargetModel], |
@@ -755,7 +768,7 @@ async def structured_output_async( |
755 | 768 |
|
756 | 769 | for attempt in range(max_retries): |
757 | 770 | try: |
758 | | - response = await agent.invoke_async(prompt_content) |
| 771 | + response = await invoke_agent_with_retry(agent=agent, input=prompt_content) |
759 | 772 | logger.debug("Agent response received") |
760 | 773 | break # Success, exit retry loop |
761 | 774 | except Exception as e: |
@@ -885,7 +898,9 @@ async def structured_output_async( |
885 | 898 | ) |
886 | 899 | ) |
887 | 900 |
|
888 | | - review_response = await agent.invoke_async(review_prompt) |
| 901 | + review_response = await invoke_agent_with_retry( |
| 902 | + agent=agent, input=review_prompt |
| 903 | + ) |
889 | 904 | logger.debug("Review response received", extra={"review_completed": True}) |
890 | 905 |
|
891 | 906 | # Accumulate token usage from review |
|
0 commit comments