Automate trade confirmation matching with AI agents that understand financial documents
Getting Started | Architecture | Documentation | Contributing
The AI Trade Matching System is an intelligent, cloud-native solution that automates the processing and matching of derivative trade confirmations using advanced AI capabilities. Built on AWS native services with a multi-agent swarm architecture powered by Strands SDK, the system leverages Amazon Nova Pro for document analysis and implements sophisticated trade matching algorithms for financial operations teams.
Manual trade confirmation matching is:
- Time-consuming: Hours spent comparing PDF confirmations
- Error-prone: Human mistakes lead to settlement failures
- Doesn't scale: Growing trade volumes overwhelm operations teams
An AI-powered system that:
- Extracts trade data from PDF confirmations using multimodal AI
- Matches trades across counterparties using fuzzy matching algorithms
- Handles exceptions intelligently with ML-based triage
- Scales automatically on AWS Bedrock AgentCore Runtime
|
|
The system uses AgentCore Runtime with Agent-to-Agent (A2A) communication for scalable, serverless processing:
+------------------+
| AWS Bedrock |
| Amazon Nova Pro |
+--------+---------+
|
+----------------+ +--------v---------+
| S3 Bucket | | AgentCore Runtime|
| BANK/ +------------->+ PDF Adapter +----+
| COUNTERPARTY/ | | Agent | |
+----------------+ +--------+---------+ |
| |
+--------v---------+ |
| AgentCore Runtime| |
| Trade Extractor | |
| Agent | |
+--------+---------+ |
| |
+-------------------+ +--------v---------+ |
| DynamoDB |<-----| AgentCore Runtime| |
| BankTradeData | | Trade Matcher | |
| CounterpartyData |<-----+ Agent | |
+-------------------+ +--------+---------+ |
| |
+--------v---------+ |
| AgentCore Runtime|<---+
|Exception Handler |
| Agent |
+------------------+
|
+--------v---------+
| AgentCore Memory |
| & Observability |
+------------------+
The system supports dual deployment patterns:
| Mode | Framework | Use Case | Communication |
|---|---|---|---|
| Local Development | Strands Swarm | Testing, debugging, rapid iteration | Direct agent handoffs |
| Production | AgentCore Runtime | Scalable, serverless deployment | A2A communication via AgentCore |
| Agent | Purpose | Key Operations | AgentCore Features |
|---|---|---|---|
| PDF Adapter | Document ingestion | Download PDF, extract text via Bedrock multimodal, save canonical output | Memory for document patterns |
| Trade Extractor | Data extraction | Parse trade fields, validate data, store in DynamoDB | Memory for field mappings |
| Trade Matcher | Reconciliation | Match trades by attributes, calculate confidence scores, generate reports | Memory for matching patterns |
| Exception Handler | Issue management | Triage breaks, assign severity, track SLA deadlines | Memory for exception patterns |
graph LR
A[PDF Upload] --> B[S3 Bucket]
B --> C[PDF Adapter]
C --> D[Bedrock AI]
D --> E[Trade Extractor]
E --> F[(DynamoDB)]
F --> G[Trade Matcher]
G --> H{Match?}
H -->|Yes| I[Report]
H -->|No| J[Exception Handler]
J --> K[(Exceptions Table)]
- Python 3.11+
- AWS Account with Bedrock access (us-east-1)
- AWS CLI configured with appropriate permissions
git clone git@ssh.gitlab.aws.dev:koushald/agentic-ai-reconcillation.git
cd agentic-ai-reconcillation
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txtcp .env.example .env
# Edit .env with your AWS credentialsRequired variables:
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1
S3_BUCKET_NAME=your-bucket-namecd terraform/agentcore
terraform init
terraform apply# Install AgentCore CLI
pip install bedrock-agentcore-starter-toolkit
# Deploy PDF Adapter Agent
cd deployment/pdf_adapter
agentcore configure --entrypoint pdf_adapter_agent_strands.py --non-interactive
agentcore launch
# Deploy Trade Extraction Agent
cd ../trade_extraction
agentcore configure --entrypoint trade_extraction_agent_strands.py --non-interactive
agentcore launch
# Deploy Trade Matching Agent
cd ../trade_matching
agentcore configure --entrypoint trade_matching_agent_strands.py --non-interactive
agentcore launch
# Deploy Exception Management Agent
cd ../exception_management
agentcore configure --entrypoint exception_management_agent_strands.py --non-interactive
agentcore launchLocal Development (Strands Swarm):
# Process a bank trade confirmation
python deployment/swarm/trade_matching_swarm.py \
data/BANK/FAB_26933659.pdf \
--source-type BANK \
--verbose
# Process a counterparty trade
python deployment/swarm/trade_matching_swarm.py \
s3://your-bucket/COUNTERPARTY/GCS381315_V1.pdf \
--source-type COUNTERPARTYProduction (AgentCore Runtime):
# Invoke the orchestrator agent with a trade document
agentcore invoke '{
"document_path": "s3://your-bucket/BANK/FAB_26933659.pdf",
"source_type": "BANK",
"document_id": "FAB_26933659"
}' --agent orchestrator_agent
# Check agent status
agentcore status --agent pdf_adapter_agent
agentcore status --agent trade_extraction_agentai-trade-matching-system/
├── deployment/ # Agent deployment packages
│ ├── swarm/ # Main swarm implementation
│ ├── pdf_adapter/ # PDF processing agent
│ ├── trade_extraction/ # Data extraction agent
│ ├── trade_matching/ # Matching agent
│ ├── exception_management/ # Exception handling agent
│ └── orchestrator/ # Orchestration agent
├── terraform/ # Infrastructure as Code
│ └── agentcore/ # AgentCore deployment
├── web-portal/ # React dashboard
├── web-portal-api/ # FastAPI backend
├── tests/ # Test suites
├── config/ # Configuration files
└── data/ # Sample trade PDFs
The system includes a React-based dashboard for operations teams:
- Real-time agent monitoring - Track agent health and performance
- Trade matching results - View matched/unmatched trades
- Exception management - Handle breaks and discrepancies
- Processing metrics - Monitor throughput and latency
# Start the API backend
cd web-portal-api
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8001
# Start the frontend (in another terminal)
cd web-portal
npm install
npm run dev| Service | Purpose | Integration |
|---|---|---|
| Bedrock | Amazon Nova Pro for document analysis | Direct multimodal PDF processing |
| AgentCore Runtime | Serverless agent deployment & scaling | Production agent hosting with A2A communication |
| AgentCore Memory | Persistent agent context & knowledge | Trade history and matching patterns |
| AgentCore Observability | Real-time monitoring & tracing | Agent performance and workflow tracking |
| DynamoDB | Trade data & exceptions storage | Structured data persistence |
| S3 | Document & report storage | PDF inputs and canonical outputs |
| CloudWatch | System monitoring & logging | Infrastructure and application metrics |
| IAM | Security & access control | Fine-grained permissions for agents |
| Metric | Value |
|---|---|
| PDF Processing | ~5 seconds |
| OCR Extraction (5 pages) | ~30-45 seconds |
| Trade Matching | ~10-20 seconds |
| Total per Trade | ~60-90 seconds |
| Document | Description |
|---|---|
| ARCHITECTURE.md | Detailed system architecture |
| HOW_TO_RUN_TESTS.md | Testing guide |
| terraform/agentcore/README.md | Infrastructure deployment |
| deployment/README.md | Agent deployment guide |
The system leverages AgentCore Runtime's native A2A capabilities for seamless agent communication:
# Agent 1 can invoke Agent 2 directly
from bedrock_agentcore import BedrockAgentCoreApp
app = BedrockAgentCoreApp()
@app.entrypoint
def invoke(payload, context):
# Process initial request
result = process_document(payload)
# Hand off to next agent
next_agent_response = context.invoke_agent(
agent_arn="arn:aws:bedrock-agentcore:us-east-1:YOUR_ACCOUNT_ID:runtime/trade-extraction-agent",
payload={"canonical_output": result}
)
return next_agent_responseAgentCore Memory provides persistent context across agent interactions:
- Trade History: Remember previous matching patterns
- Counterparty Profiles: Learn counterparty-specific document formats
- Exception Patterns: Improve exception classification over time
- Performance Metrics: Track and optimize agent performance
AgentCore Observability provides comprehensive monitoring:
- Real-time Tracing: Track requests across all agents
- Performance Metrics: Latency, throughput, error rates
- Token Usage: Monitor LLM costs and optimization opportunities
- Custom Metrics: Trade-specific KPIs and SLA tracking
# .bedrock_agentcore.yaml
agents:
pdf_adapter:
entrypoint: pdf_adapter_agent_strands.py
memory_enabled: true
vpc_enabled: true
trade_extraction:
entrypoint: trade_extraction_agent_strands.py
memory_enabled: true
depends_on: [pdf_adapter]
trade_matching:
entrypoint: trade_matching_agent_strands.py
memory_enabled: true
depends_on: [trade_extraction]
exception_management:
entrypoint: exception_management_agent_strands.py
memory_enabled: true
depends_on: [trade_matching]- VPC Isolation: Deploy agents in private subnets
- IAM Least Privilege: Fine-grained permissions per agent
- Encryption: End-to-end encryption for sensitive trade data
- Audit Logging: Complete audit trail via CloudTrail and AgentCore logs
# Run all tests
pytest tests/ -v
# Run property-based tests
pytest tests/property_based/ -v
# Run end-to-end tests
pytest tests/e2e/ -vFor Local Development (Strands Swarm):
- Create agent factory function in
deployment/swarm/ - Define tools with
@tooldecorator - Update swarm configuration with handoff conditions
For Production (AgentCore Runtime):
-
Create agent file with
BedrockAgentCoreAppwrapper:from bedrock_agentcore import BedrockAgentCoreApp from strands import Agent app = BedrockAgentCoreApp() @app.entrypoint def invoke(payload, context): # Your agent logic here return {"result": result} if __name__ == "__main__": app.run()
-
Deploy to AgentCore:
agentcore configure --entrypoint new_agent.py --non-interactive agentcore launch
Common Issues:
-
Missing BedrockAgentCoreApp Import
Error: Agent must import BedrockAgentCoreApp
Solution: Add
from bedrock_agentcore import BedrockAgentCoreApp -
Missing @app.entrypoint Decorator
Error: No entrypoint function found
Solution: Add
@app.entrypointdecorator to your invoke function -
Requirements.txt Issues
Error: bedrock-agentcore not found
Solution: Add
bedrock-agentcoreto requirements.txt -
Agent Communication Failures
Error: Unable to invoke target agent
Solution: Check IAM permissions for
bedrock-agentcore:InvokeAgentRuntime
- Token Usage: Monitor via AgentCore Observability dashboard
- Latency: Use AgentCore Memory for caching frequent operations
- Throughput: Scale agents independently based on workload
- Cost: Optimize model selection per agent (Nova Pro vs Claude)
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Merge Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built for derivatives operations teams worldwide