Skip to content

Commit 3c81823

Browse files
committed
invoke extraction with long retries
1 parent 9ce5766 commit 3c81823

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/idp_common_pkg/idp_common/extraction/agentic_idp.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
update_todo,
4343
view_todo_list,
4444
)
45+
from lib.idp_common_pkg.idp_common.utils.bedrock_utils import (
46+
async_exponential_backoff_retry,
47+
)
4548

4649
# Use AWS Lambda Powertools Logger for structured logging
4750
# 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:
458461
"""
459462

460463

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+
461474
async def structured_output_async(
462475
model_id: str,
463476
data_format: type[TargetModel],
@@ -755,7 +768,7 @@ async def structured_output_async(
755768

756769
for attempt in range(max_retries):
757770
try:
758-
response = await agent.invoke_async(prompt_content)
771+
response = await invoke_agent_with_retry(agent=agent, input=prompt_content)
759772
logger.debug("Agent response received")
760773
break # Success, exit retry loop
761774
except Exception as e:
@@ -885,7 +898,9 @@ async def structured_output_async(
885898
)
886899
)
887900

888-
review_response = await agent.invoke_async(review_prompt)
901+
review_response = await invoke_agent_with_retry(
902+
agent=agent, input=review_prompt
903+
)
889904
logger.debug("Review response received", extra={"review_completed": True})
890905

891906
# Accumulate token usage from review

0 commit comments

Comments
 (0)