Skip to content

Commit 653350d

Browse files
committed
assesment update
1 parent 72e4dbe commit 653350d

File tree

6 files changed

+72
-58
lines changed

6 files changed

+72
-58
lines changed

lib/idp_common_pkg/idp_common/assessment/granular_service.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
import json
1515
import os
1616
import time
17-
from typing import Any, Dict, List, Optional, Tuple, Union
17+
from typing import Any
1818

1919
from aws_lambda_powertools import Logger
20+
from mypy_boto3_dynamodb.service_resource import DynamoDBServiceResource
2021

2122
from idp_common import image, metrics, s3, utils
2223
from idp_common.assessment.models import AssessmentResult, AssessmentTask
@@ -31,7 +32,7 @@
3132
X_AWS_IDP_CONFIDENCE_THRESHOLD,
3233
X_AWS_IDP_DOCUMENT_TYPE,
3334
)
34-
from idp_common.extraction.models import ExtractionData, ExtractionMetadata
35+
from idp_common.extraction.models import ExtractionData
3536
from idp_common.models import Document, Status
3637
from idp_common.utils import check_token_limit
3738
from idp_common.utils.grid_overlay import add_ruler_edges

lib/idp_common_pkg/idp_common/assessment/strands_service.py

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
from aws_lambda_powertools import Logger
1414
from botocore.config import Config
15-
from strands import Agent, tool
15+
from idp_common.utils.bedrock_utils import (
16+
async_exponential_backoff_retry,
17+
)
18+
from strands import Agent
1619
from strands.agent.conversation_manager import SummarizingConversationManager
1720
from strands.models.bedrock import BedrockModel
1821
from strands.types.content import ContentBlock, Message
@@ -24,48 +27,6 @@
2427
logger = Logger(service="assessment", level=os.getenv("LOG_LEVEL", "INFO"))
2528

2629

27-
def create_submit_assessment_tool():
28-
"""
29-
Create a tool for submitting assessment results.
30-
31-
Returns:
32-
A Strands tool function for submitting assessments
33-
"""
34-
35-
@tool
36-
def submit_assessment(assessment: AssessmentOutput, agent: Agent) -> str:
37-
"""
38-
Submit your final confidence assessment.
39-
40-
Use this tool when you have:
41-
1. Located the values in the document images
42-
2. Determined precise bounding box coordinates using ruler markings
43-
3. Assessed the confidence based on clarity and accuracy
44-
45-
Args:
46-
assessment: Dictionary with:
47-
- assessments: dict mapping attribute names to ConfidenceAssessment
48-
- alerts: list of any threshold alerts (optional)
49-
50-
Returns:
51-
Success confirmation message or validation error details
52-
"""
53-
# Validate assessment structure and return helpful errors
54-
validated_assessment = AssessmentOutput(**assessment) # pyright: ignore[reportCallIssue]
55-
56-
# Store in agent state
57-
agent.state.set("assessment_output", validated_assessment.model_dump())
58-
59-
logger.info(
60-
"Assessment submitted successfully",
61-
extra={"assessment": validated_assessment.model_dump()},
62-
)
63-
64-
return "Assessment submitted successfully. You can now finish the task."
65-
66-
return submit_assessment
67-
68-
6930
async def assess_attribute_with_strands(
7031
task: AssessmentTask,
7132
extraction_results: dict[str, Any],
@@ -105,9 +66,7 @@ async def assess_attribute_with_strands(
10566
try:
10667
# 1. Create tools (image viewer + todo list + submit assessment)
10768
base_tools = create_strands_tools(page_images, sorted_page_ids)
108-
submit_tool = create_submit_assessment_tool()
109-
tools = base_tools + [submit_tool]
110-
69+
tools = base_tools
11170
# 2. Build enhanced system prompt with schema and extraction (for caching)
11271
enhanced_system_prompt = _build_system_prompt_with_context(
11372
system_prompt, document_schema, extraction_results, len(page_images)
@@ -161,8 +120,17 @@ async def assess_attribute_with_strands(
161120
},
162121
)
163122

164-
response = await agent.invoke_async([user_message])
123+
@async_exponential_backoff_retry(
124+
max_retries=30,
125+
initial_delay=5,
126+
exponential_base=2,
127+
jitter=0.5,
128+
max_delay=900,
129+
)
130+
async def invoke_agent_with_retry():
131+
return await agent.invoke_async([user_message])
165132

133+
response = await invoke_agent_with_retry()
166134
logger.debug("Agent response received", extra={"task_id": task.task_id})
167135

168136
# 7. Extract assessment from agent state

lib/idp_common_pkg/idp_common/assessment/strands_tools.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
from aws_lambda_powertools import Logger
1212
from pydantic import BaseModel, Field
1313
from strands import Agent, tool
14-
from strands.types.content import ContentBlock, ImageContent
15-
from strands.types.tools import ToolResult, ToolResultContent, ToolResultStatus
1614

17-
from idp_common.assessment.strands_models import BoundingBox
15+
from idp_common.assessment.strands_models import AssessmentOutput, BoundingBox
1816
from idp_common.utils.grid_overlay import draw_bounding_boxes
1917
from idp_common.utils.strands_agent_tools.todo_list import (
2018
create_todo_list,
@@ -37,6 +35,38 @@ class ViewImageInput(BaseModel):
3735
label: str | None = Field(None, description="Optional label for the bounding box")
3836

3937

38+
@tool
39+
def submit_assessment(assessment: AssessmentOutput, agent: Agent) -> str:
40+
"""
41+
Submit your final confidence assessment.
42+
43+
Use this tool when you have:
44+
1. Located the values in the document images
45+
2. Determined precise bounding box coordinates using ruler markings
46+
3. Assessed the confidence based on clarity and accuracy
47+
48+
Args:
49+
assessment: Dictionary with:
50+
- assessments: dict mapping attribute names to ConfidenceAssessment
51+
- alerts: list of any threshold alerts (optional)
52+
53+
Returns:
54+
Success confirmation message or validation error details
55+
"""
56+
# Validate assessment structure and return helpful errors
57+
validated_assessment = AssessmentOutput(**assessment) # pyright: ignore[reportCallIssue]
58+
59+
# Store in agent state
60+
agent.state.set("assessment_output", validated_assessment.model_dump())
61+
62+
logger.info(
63+
"Assessment submitted successfully",
64+
extra={"assessment": validated_assessment.model_dump()},
65+
)
66+
67+
return "Assessment submitted successfully. You can now finish the task."
68+
69+
4070
def create_view_image_tool(page_images: list[bytes], sorted_page_ids: list[str]) -> Any:
4171
"""
4272
Create a view_image tool that has access to page images.
@@ -163,4 +193,5 @@ def create_strands_tools(
163193
create_todo_list,
164194
update_todo,
165195
view_todo_list,
196+
submit_assessment,
166197
]

lib/idp_common_pkg/idp_common/config/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class AssessmentConfig(BaseModel):
256256
image: ImageConfig = Field(default_factory=ImageConfig)
257257
# Granular assessment settings (always enabled, no longer nested)
258258
max_workers: int = Field(
259-
default=20, gt=0, description="Max concurrent workers for parallel assessment"
259+
default=50, gt=0, description="Max concurrent workers for parallel assessment"
260260
)
261261

262262
@field_validator(

lib/idp_common_pkg/pyproject.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ description = "Common utilities for GenAI IDP Accelerator patterns"
2121
authors = [{ name = "AWS", email = "[email protected]" }]
2222
requires-python = ">=3.12,<3.14"
2323
dependencies = [
24-
"boto3==1.39.7", # Core dependency for AWS services
24+
"boto3==1.39.7", # Core dependency for AWS services
2525
"jsonschema>=4.25.1",
2626
"pydantic>=2.12.0",
2727
"deepdiff>=6.0.0",
28+
"mypy-boto3-bedrock-runtime>=1.40.76",
2829
]
2930
readme = "README.md"
3031
classifiers = [
@@ -73,6 +74,8 @@ extraction = [
7374
assessment = [
7475
"Pillow==11.2.1", # For image handling
7576
"aws-lambda-powertools>=3.2.0", # Structured logging and observability
77+
"mypy-boto3-dynamodb>=1.40.56",
78+
"strands-agents==1.17.0",
7679
]
7780

7881
# Evaluation module dependencies
@@ -98,15 +101,15 @@ appsync = ["requests==2.32.4"]
98101

99102
# Agents module dependencies
100103
agents = [
101-
"strands-agents==1.14.0; python_version>='3.10'",
104+
"strands-agents==1.17.0; python_version>='3.10'",
102105
"strands-agents-tools==0.2.13; python_version>='3.10'",
103106
"bedrock-agentcore>=0.1.1; python_version>='3.10'", # Specifically for the code interpreter tool
104107
]
105108

106109
# Code intelligence module dependencies
107110
code_intel = [
108111
"requests==2.32.4",
109-
"strands-agents==1.14.0",
112+
"strands-agents==1.17.0",
110113
"strands-agents-tools==0.2.13",
111114
"bedrock-agentcore>=0.1.1",
112115
"PyYAML>=6.0.0",
@@ -158,14 +161,14 @@ all = [
158161
"pyarrow==20.0.0",
159162
"openpyxl==3.1.5",
160163
"python-docx==1.2.0",
161-
"strands-agents==1.14.0; python_version>='3.10'",
164+
"strands-agents==1.17.0; python_version>='3.10'",
162165
"strands-agents-tools==0.2.13; python_version>='3.10'",
163166
"bedrock-agentcore>=0.1.1; python_version>='3.10'",
164167
# "s3fs==2023.12.2" - - disabled till we fix package dependencies
165168
]
166169
agentic-extraction = [
167170
"jsonpatch==1.33",
168-
"strands-agents==1.14.0 ; python_full_version >= '3.10'",
171+
"strands-agents==1.17.0 ; python_full_version >= '3.10'",
169172
"pandas>=2.2.3",
170173
"pymupdf==1.25.5", # Pinned to 1.25.5 - has pre-built ARM64 wheels, 1.26.x requires compilation
171174
"email-validator>=2.3.0",

lib/idp_common_pkg/uv.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)