Lab 2: Business Process Automation - Invoice Processing Agent¶
Lab Overview¶
Duration: 3-4 hours Difficulty: Intermediate Prerequisites: Lab 1 completed, basic understanding of business processes
In this lab, you'll build a complete invoice processing automation system that handles everything from receipt capture to payment tracking, demonstrating how agents can eliminate manual business processes.
Learning Objectives¶
By the end of this lab, you will: - ✅ Design and implement a multi-step business process automation - ✅ Integrate agents with business systems (accounting, email, file storage) - ✅ Create intelligent decision-making workflows - ✅ Implement error handling and human escalation - ✅ Measure and optimize business process efficiency
The Business Challenge¶
Current Invoice Processing Pain Points: - 2-3 hours weekly spent on invoice data entry - Frequent errors in manual transcription - Delayed payments due to processing bottlenecks - Difficulty tracking invoice status and approvals - Poor visibility into cash flow and obligations
What You'll Build: A complete invoice automation system that: - Captures invoices from email, scans, and uploads - Extracts data using OCR and AI analysis - Validates against purchase orders and budgets - Routes for appropriate approvals - Updates accounting systems automatically - Tracks payments and sends reminders
Part 1: Process Analysis and Design (45 minutes)¶
Step 1: Current State Documentation¶
Map your existing invoice process:
Current Invoice Process:
1. Invoice Receipt Method:
- Email attachments: _____%
- Postal mail scans: _____%
- Direct vendor uploads: _____%
- Other: _____%
2. Manual Steps Currently Required:
- [ ] Open email and download PDF
- [ ] Read invoice details
- [ ] Type data into accounting system
- [ ] Match to purchase order
- [ ] Get manager approval
- [ ] Update status and file
- [ ] Schedule payment
3. Current Performance Metrics:
- Average processing time: _____ minutes per invoice
- Monthly invoice volume: _____ invoices
- Error rate: _____%
- Late payment penalties: $_____ per month
- Staff time cost: $_____ per month
Step 2: Future State Design¶
Automated Process Flow:
1. Invoice Capture (Automated)
- Email monitoring for new invoices
- OCR processing of PDF attachments
- Data extraction and standardization
2. Validation & Matching (Automated)
- Purchase order matching
- Budget approval checking
- Duplicate detection
- Vendor verification
3. Approval Routing (Automated/Human)
- Automatic approval for routine invoices
- Manager routing for higher amounts
- Exception handling for discrepancies
4. System Integration (Automated)
- Accounting system updates
- Payment scheduling
- Status notifications
- Compliance logging
Step 3: Integration Requirements¶
Systems to Connect:
Required Integrations:
Accounting System: ________________
Email Platform: ___________________
File Storage: _____________________
Purchase Order System: ____________
Optional Integrations:
Banking/Payment System: ___________
Vendor Portal: ____________________
ERP System: _______________________
Part 2: Core Agent Development (90 minutes)¶
Step 1: Create the Invoice Processing Agent¶
Agent Configuration:
Name: InvoiceBot Pro
Role: Accounts Payable Processing Specialist
Department: Finance
Processing Volume: 50-200 invoices per month
Core Agent Instructions:
## Your Primary Role
You are responsible for processing vendor invoices from receipt
to payment, ensuring accuracy, compliance, and timely processing
while minimizing manual intervention.
## Invoice Processing Workflow
### Step 1: Invoice Capture and Analysis
1. Monitor designated email addresses for new invoices
2. Extract invoice data using OCR and document analysis
3. Standardize data format for consistent processing
4. Store original documents with extracted data
Required Data Extraction:
- Vendor name and contact information
- Invoice number and date
- Total amount and currency
- Line items with descriptions and amounts
- Tax information
- Payment terms (net 30, net 60, etc.)
- Purchase order references (if present)
### Step 2: Validation and Verification
1. Validate vendor against approved vendor list
2. Check for duplicate invoice numbers
3. Verify mathematical accuracy of totals
4. Match against purchase orders when available
5. Confirm budget availability for expenses
Validation Rules:
- Invoice total must match sum of line items
- Vendor must be in approved vendor database
- Purchase order amounts must match within 5% tolerance
- Department budgets must have sufficient funds
### Step 3: Approval Routing
Route invoices based on approval matrix:
Auto-Approve (No Human Required):
- Pre-approved vendors with standing orders
- Amounts under $500 with matching PO
- Recurring monthly services (utilities, subscriptions)
- Mathematical accuracy confirmed
Manager Approval Required:
- Amounts $500-$2,500 without PO match
- New vendors or modified vendor terms
- Budget variances over 10%
- Disputed or corrected invoices
Executive Approval Required:
- Amounts over $2,500
- Capital expenditures
- Legal or professional services
- Emergency or rush processing
### Step 4: System Integration and Payment
1. Create or update vendor records in accounting system
2. Generate accounting entries with proper GL codes
3. Schedule payments according to terms and cash flow
4. Send confirmation notifications to stakeholders
5. Update invoice status and maintain audit trail
## Error Handling Procedures
When OCR or data extraction fails:
- Flag for manual review with specific error details
- Provide extracted data for human verification
- Learn from corrections to improve accuracy
When validation fails:
- Document specific validation failures
- Route to appropriate reviewer with context
- Provide recommended actions for resolution
When system integration fails:
- Queue invoice for retry with exponential backoff
- Escalate to IT team after 3 failed attempts
- Maintain invoice in pending status until resolved
## Communication and Notifications
Keep stakeholders informed:
- Daily processing summaries to AP manager
- Weekly cash flow forecasts to finance team
- Immediate alerts for high-value or urgent invoices
- Monthly accuracy and efficiency reports
Step 2: Data Extraction Configuration¶
OCR and AI Analysis Setup:
Document Processing:
Supported Formats: PDF, JPG, PNG, TIFF
OCR Engine: Advanced text recognition
Data Extraction: AI-powered field identification
Key Fields to Extract:
- vendor_name (text)
- vendor_address (text)
- invoice_number (text/numeric)
- invoice_date (date)
- due_date (date)
- subtotal (currency)
- tax_amount (currency)
- total_amount (currency)
- line_items (array of objects)
- purchase_order_ref (text)
Confidence Scoring:
- High Confidence (>90%): Auto-process
- Medium Confidence (70-90%): Flag for review
- Low Confidence (<70%): Manual verification required
Example Extracted Data Structure:
{
"invoice_id": "INV-2024-001",
"extraction_timestamp": "2024-01-15T10:30:00Z",
"confidence_score": 0.92,
"vendor_info": {
"name": "Office Supply Co",
"address": "123 Business St, City, ST 12345",
"tax_id": "12-3456789"
},
"invoice_details": {
"number": "OS-98765",
"date": "2024-01-10",
"due_date": "2024-02-09",
"terms": "Net 30"
},
"financial_data": {
"subtotal": 847.50,
"tax": 67.80,
"total": 915.30,
"currency": "USD"
},
"line_items": [
{
"description": "Office chairs (qty 5)",
"amount": 750.00,
"account_code": "6100"
},
{
"description": "Shipping & handling",
"amount": 97.50,
"account_code": "6200"
}
],
"purchase_order": "PO-2024-156"
}
Step 3: Business Logic Implementation¶
Approval Rules Engine:
# Approval Logic (Pseudo-code)
def determine_approval_required(invoice_data):
amount = invoice_data['total']
has_po = invoice_data['purchase_order'] is not None
vendor_status = check_vendor_status(invoice_data['vendor'])
# Auto-approval criteria
if (amount < 500 and
has_po and
vendor_status == 'approved' and
po_match_within_tolerance(invoice_data)):
return 'AUTO_APPROVE'
# Manager approval
elif amount < 2500:
return 'MANAGER_APPROVAL'
# Executive approval
else:
return 'EXECUTIVE_APPROVAL'
def validate_invoice(invoice_data):
validation_results = {
'math_correct': validate_math(invoice_data),
'vendor_approved': check_vendor_status(invoice_data),
'no_duplicate': check_duplicate(invoice_data),
'budget_available': check_budget(invoice_data),
'po_match': validate_po_match(invoice_data)
}
return all(validation_results.values()), validation_results
GL Code Assignment Logic:
Account Code Mapping:
Office Supplies: 6100
Marketing Expenses: 6200
Professional Services: 6300
Utilities: 6400
Travel & Entertainment: 6500
Equipment Purchases: 1500
Software Subscriptions: 6150
Assignment Rules:
- Use PO account codes when available
- Apply vendor-specific default codes
- Use AI description analysis for unmapped items
- Flag unusual categorizations for review
Part 3: System Integrations (75 minutes)¶
Step 1: Email Integration Setup¶
Email Monitoring Configuration:
Monitored Accounts:
- invoices@yourcompany.com
- ap@yourcompany.com
- billing@yourcompany.com
Processing Rules:
- Attachments only (PDF, images)
- Minimum file size: 50KB
- Maximum file size: 10MB
- Sender whitelist: approved vendors
Folder Structure:
- Inbox: New invoices to process
- Processing: Currently being analyzed
- Completed: Successfully processed
- Errors: Failed processing attempts
Email Trigger Setup:
When new email received:
1. Check sender against approved vendor list
2. Scan for attachment files
3. Download and virus scan attachments
4. Queue for OCR processing
5. Send acknowledgment email to sender
6. Create processing record with timestamp
Step 2: Accounting System Integration¶
QuickBooks Online Integration Example:
API Connection:
Base URL: https://sandbox-quickbooks.api.intuit.com
Authentication: OAuth 2.0
Scopes: com.intuit.quickbooks.accounting
Required Operations:
- Create/Update Vendor records
- Create Bills (invoices)
- Create Journal Entries
- Read Chart of Accounts
- Read Purchase Orders
- Update Payment status
Bill Creation Process:
# QuickBooks Bill Creation (Pseudo-code)
def create_qb_bill(invoice_data):
bill_data = {
"Vendor": {
"name": invoice_data['vendor_name']
},
"VendorAddr": {
"Line1": invoice_data['vendor_address']
},
"TxnDate": invoice_data['invoice_date'],
"DueDate": invoice_data['due_date'],
"DocNumber": invoice_data['invoice_number'],
"Line": []
}
# Add line items
for item in invoice_data['line_items']:
line_item = {
"Amount": item['amount'],
"DetailType": "AccountBasedExpenseLineDetail",
"AccountBasedExpenseLineDetail": {
"AccountRef": {"value": item['account_code']},
"TaxCodeRef": {"value": "NON"}
}
}
bill_data["Line"].append(line_item)
return create_bill_api_call(bill_data)
Step 3: File Storage and Document Management¶
Document Storage Structure:
Cloud Storage Organization:
/invoices/
/2024/
/01-january/
/processed/
invoice_001.pdf
invoice_002.pdf
/pending/
invoice_pending_001.pdf
/errors/
invoice_error_001.pdf
File Naming Convention:
Format: YYYY-MM-DD_VENDOR_INVOICE#.pdf
Example: 2024-01-15_OfficeSupplyCo_OS98765.pdf
Retention Policy:
- Original files: 7 years
- Processed data: 7 years
- Error logs: 3 years
- Audit trails: 7 years
Part 4: Testing and Validation (60 minutes)¶
Step 1: Create Test Scenarios¶
Test Case 1: Perfect Invoice Processing
Scenario: Standard vendor invoice with PO
Test Data:
- Known vendor (Office Supply Co)
- Invoice amount: $450.00
- Has matching purchase order
- All required fields present
Expected Results:
- OCR extraction: >90% accuracy
- Validation: All checks pass
- Approval: Auto-approved
- Processing time: <3 minutes
- Integration: Bill created in QB
Test Case 2: High-Value Invoice Routing
Scenario: New vendor with large invoice
Test Data:
- Unknown vendor (Consulting Firm ABC)
- Invoice amount: $3,500.00
- No purchase order
- Professional services
Expected Results:
- OCR extraction: >85% accuracy
- Validation: Vendor check fails
- Approval: Escalated to executive
- Integration: Pending approval status
- Notifications: Alert sent to approvers
Test Case 3: Error Handling
Scenario: Poor quality scan with missing data
Test Data:
- Blurry PDF scan
- Partial vendor information
- Unclear total amount
- Missing invoice number
Expected Results:
- OCR extraction: <70% confidence
- Validation: Multiple failures
- Approval: Flagged for manual review
- Integration: Queued for correction
- Notifications: Error alert sent
Step 2: Run Comprehensive Testing¶
Testing Checklist:
Data Extraction Testing:
- [ ] Clear, high-quality invoices
- [ ] Poor quality scans
- [ ] Different invoice layouts
- [ ] International formats
- [ ] Multiple page invoices
Validation Testing:
- [ ] Valid vendor processing
- [ ] Invalid/new vendor handling
- [ ] Duplicate detection
- [ ] Mathematical accuracy checking
- [ ] Budget validation
Approval Workflow Testing:
- [ ] Auto-approval triggers correctly
- [ ] Manager approval routing works
- [ ] Executive escalation functions
- [ ] Notification delivery
Integration Testing:
- [ ] Accounting system connection
- [ ] Bill creation accuracy
- [ ] GL code assignment
- [ ] Vendor record management
- [ ] Error handling and recovery
Step 3: Performance Measurement¶
Baseline Metrics (Before Automation):
Current Performance:
- Processing time per invoice: _____ minutes
- Data entry errors: _____%
- Late payment penalties: $_____ per month
- Staff time required: _____ hours per week
- Approval delays: _____ days average
Target Metrics (After Automation):
Automation Goals:
- Processing time per invoice: <5 minutes
- Data entry errors: <2%
- Late payment penalties: <$100 per month
- Staff time required: <2 hours per week
- Approval delays: <1 day average
Part 5: Production Deployment (45 minutes)¶
Step 1: Gradual Rollout Strategy¶
Phase 1: Pilot Testing (Week 1)
Scope: 10 invoices from 3 trusted vendors
Monitoring: Real-time review of all processing
Approval: Human verification of all decisions
Goal: Validate basic functionality
Phase 2: Limited Production (Week 2-3)
Scope: 25% of normal invoice volume
Monitoring: Daily performance reviews
Approval: Auto-approve only low-risk invoices
Goal: Identify edge cases and improvements
Phase 3: Full Deployment (Week 4+)
Scope: All invoices except high-risk categories
Monitoring: Weekly performance reviews
Approval: Full automation within defined parameters
Goal: Achieve target performance metrics
Step 2: Monitoring and Alerts¶
Real-Time Monitoring Dashboard:
Key Metrics Display:
- Invoices processed today
- Current processing queue length
- Error rate (last 24 hours)
- Average processing time
- Approval backlog
Alert Conditions:
- Processing queue >10 invoices
- Error rate >5% in past hour
- Integration failures
- High-value invoice received
- Unusual vendor activity
Weekly Performance Report:
Automated Report Contents:
- Volume processed vs. manual baseline
- Accuracy rates and error analysis
- Cost savings and ROI calculation
- Vendor payment status summary
- System performance metrics
- Improvement recommendations
Step 3: Continuous Improvement Process¶
Weekly Review Cycle:
Monday Morning Review:
1. Analyze previous week's performance
2. Review error patterns and causes
3. Update vendor approval status
4. Refine processing rules based on learnings
Monthly Optimization:
1. Update OCR training data
2. Refine approval thresholds
3. Optimize GL code assignments
4. Review integration performance
Troubleshooting Guide¶
Common Issue 1: Poor OCR Accuracy¶
Symptoms: - Confidence scores consistently <80% - Frequent manual review requirements - Wrong vendor names or amounts
Solutions: 1. Improve Source Document Quality
Vendor Education:
- Request digital invoices instead of scanned PDFs
- Provide vendor portal for direct uploads
- Specify required invoice formatting standards
- OCR Engine Optimization
Common Issue 2: Integration Failures¶
Symptoms: - Bills not appearing in accounting system - Error messages in logs - Processing stuck in "pending" status
Solutions: 1. Connection Troubleshooting
Check List:
- API credentials still valid
- Rate limits not exceeded
- Accounting system accessible
- Network connectivity stable
- Data Mapping Verification
Common Issue 3: Approval Bottlenecks¶
Symptoms: - Large number of invoices pending approval - Approvers not receiving notifications - Missed payment deadlines
Solutions: 1. Workflow Optimization
Adjustments:
- Lower auto-approval thresholds
- Add backup approvers
- Implement escalation timers
- Improve notification delivery
Success Measurement and ROI¶
Calculate Your Automation ROI¶
Time Savings Calculation:
Before Automation:
Average processing time: _____ minutes per invoice
Monthly volume: _____ invoices
Total monthly time: _____ hours
After Automation:
Average processing time: _____ minutes per invoice
Monthly volume: _____ invoices
Total monthly time: _____ hours
Time Savings: _____ hours per month
Value of time saved: $_____ (hourly rate × time saved)
Error Reduction Value:
Reduction in late payment penalties: $_____ per month
Reduction in duplicate payments: $_____ per month
Improved vendor relationships value: $_____ per month
Total Monthly ROI:
Total monthly benefits: $_____
Agent and integration costs: $_____
Net monthly benefit: $_____
Annual ROI: ____% ((benefits - costs) / costs × 100)
Lab Completion Checklist¶
- Invoice processing agent created and configured
- OCR and data extraction working accurately (>85%)
- Business validation rules implemented
- Approval workflow routing correctly
- Accounting system integration functional
- Error handling and escalation working
- Testing completed with real invoices
- Production deployment successful
- Monitoring and reporting established
- ROI calculation completed
Final Metrics: - Processing time reduction: _____% - Error rate improvement: _____% - Monthly time savings: _____ hours - Monthly cost savings: $_____ - System accuracy rate: _____%
Congratulations! You've built a sophisticated business process automation that demonstrates the power of intelligent agents to handle complex, multi-step workflows. This invoice processing system showcases how AgentKit can integrate with business systems, make intelligent decisions, and provide significant operational value.
In Lab 3, you'll apply these integration skills to build a research and data analysis agent that automatically gathers competitive intelligence and market insights for your business.