Skip to content

Conversation

kazmer97
Copy link

@kazmer97 kazmer97 commented Sep 4, 2025

Summary

• Add agentic extraction module using Strands agents for structured data output without JSON parsing errors • Enhance
extraction service with dynamic Pydantic model generation from configuration attributes • Maintain full backward
compatibility - traditional extraction remains default behavior

Changes Made

• New: lib/idp_common_pkg/idp_common/extraction/agentic_idp.py - Core agentic functionality with tool-based
extraction
• Modified: lib/idp_common_pkg/idp_common/extraction/service.py - Added dynamic model generation and agentic
integration
• Updated: lib/idp_common_pkg/idp_common/extraction/README.md - Comprehensive documentation with usage examples

Benefits

• Eliminates JSON parsing errors through validated Pydantic models
• Improves extraction accuracy with self-correcting agent tools
• Provides dual extraction paths (traditional vs agentic) based on configuration
• Zero breaking changes - existing workflows continue unchanged

This enhancement significantly improves extraction reliability while preserving all existing functionality and
configuration patterns.

Screenshot 2025-09-18 at 12 45 55 Screenshot 2025-09-18 at 12 45 44 Screenshot 2025-09-18 at 12 46 20

@kazmer97 kazmer97 changed the title feat(agentic idp): First version of agentic IDP using strands Draft: feat(agentic idp): First version of agentic IDP using strands Sep 4, 2025
@kazmer97 kazmer97 marked this pull request as draft September 4, 2025 17:31
@kazmer97 kazmer97 force-pushed the feat/agentic-idp branch 4 times, most recently from cd18bbb to c3345ea Compare September 12, 2025 13:21
@kazmer97 kazmer97 marked this pull request as ready for review September 18, 2025 09:09
@kazmer97 kazmer97 changed the title Draft: feat(agentic idp): First version of agentic IDP using strands feat(agentic idp): First version of agentic IDP using strands Sep 18, 2025
@kazmer97 kazmer97 force-pushed the feat/agentic-idp branch 2 times, most recently from 239141a to 99565e2 Compare September 22, 2025 12:13
- system_prompt
- task_prompt
properties:
agentic:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do prompts work.. Does the agent still use the existing System prompt and Task prompt? (I had imagined the agent would need different prompt variants, but if not, that's great!)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How Prompts Work with Agentic Extraction
The agentic extraction uses the existing System and Task prompts, but in a different way than traditional extraction:

Traditional Extraction
System prompt: Sent directly to Bedrock as system message
Task prompt: Sent as user message
Model responds with JSON text that needs parsing
Agentic Extraction
System prompt → Passed via custom_instruction parameter and appended to agentic system prompt
Task prompt → Sent as user message (content blocks with text/images)
Uses Strands agent with tools for structured output
No JSON parsing needed - returns validated Pydantic model
Key Difference
The agentic system prompt (in agentic_idp.py) provides extraction guidelines and tool usage instructions. Your existing system/task prompts are incorporated as custom instructions to guide the extraction without changing the core agent behavior.

@kazmer97 kazmer97 force-pushed the feat/agentic-idp branch 2 times, most recently from eabe44b to 4b23c91 Compare October 2, 2025 11:21
@kazmer97
Copy link
Author

kazmer97 commented Oct 2, 2025

How Prompts Work with Agentic Extraction

The agentic extraction uses the existing System and Task prompts, but in a different way than traditional extraction:

Traditional Extraction

  • System prompt: Sent directly to Bedrock as system message
  • Task prompt: Sent as user message
  • Model responds with JSON text that needs parsing

Agentic Extraction

  • System prompt → Passed via custom_instruction parameter and appended to agentic system prompt
  • Task prompt → Sent as user message (content blocks with text/images)
  • Uses Strands agent with tools for structured output
  • No JSON parsing needed - returns validated Pydantic model

Key Difference

The agentic system prompt (in agentic_idp.py) provides extraction guidelines and tool usage instructions. Your existing system/task prompts are incorporated as custom instructions to guide the extraction without changing the core agent behavior.

Result: Same prompts work for both methods, just applied differently under the hood.

@kazmer97 kazmer97 force-pushed the feat/agentic-idp branch 4 times, most recently from 9b9c42b to db43335 Compare October 7, 2025 16:47
@kazmer97 kazmer97 force-pushed the feat/agentic-idp branch 2 times, most recently from d2373c5 to 83fd4a8 Compare October 7, 2025 20:58
description: This introduces a second agent to review the first agents work. Only use with highly complex workflows as it increases token usage.
order: 1
default: false
enable_caching:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to automate this.. already in idp_common bedrock client we have a list of models that support caching, so use that to auto detect and cache if model supports it.


Configure extraction behavior through several components:

### Agentic Extraction (Recommended for Production)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it too soon to say this.. Better to say (Preview) or (Experimental) for now, IMHO, till we have more testing and ironed out bugs..


#### When to Enable Agentic Extraction

Enable agentic extraction when you need:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we say something about this enabling future extensions involving MCP servers to integrate validation or enrichment into the extraction process... (eg validate names, addresses, etc from external services)

When a field is not present, indicate this explicitly rather than guessing.
task_prompt: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain how the system_prompt and task_prompts apply to the agentic extraction.. Does the agent use the same prompt as 'traditional' method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See slack comment on throttle catching..

it failed with
Execution Failed
Error: ValueError: Agent invocation failed: An error occurred (ThrottlingException) when calling the ConverseStream operation (reached max retries: 4): Too many tokens, please wait before trying again.
We need to keep retrying... for much much longer.. @kaznb can you check
idp_common bedrock client for exponential backoff/retry logic
state machine for retries at lambda invocation level..
We should never fail due to throttling.. at least not for several hours..
Note - I seem to get this error every time with Sonnet 4.5 in my isengard account when processing just 1 lending_package.pdf (Isengard has really low quota), but, whatever the customer quota is, we still need to defend against throttling when volumes are large and demand exceeds quota

@kazmer97 kazmer97 force-pushed the feat/agentic-idp branch 2 times, most recently from 1de7a71 to b4c1f69 Compare October 8, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants