|
| 1 | +# Simplified Expense Approval Agent |
| 2 | + |
| 3 | +A streamlined expense approval workflow that validates expenses and always suspends for manager review via API trigger. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Basic Validation**: Checks receipt, date, and amount limits |
| 8 | +- **Always Suspends**: Every expense goes to manager for review |
| 9 | +- **API Trigger Resume**: Manager approves/rejects via API |
| 10 | +- **Clear Audit Trail**: Processing notes track all decisions |
| 11 | +- **No LLM Required**: Pure business logic |
| 12 | + |
| 13 | +## How It Works |
| 14 | + |
| 15 | +### Workflow Steps |
| 16 | + |
| 17 | +1. **Prepare Input**: Generates unique expense ID (EXP-YYYYMMDD-XXXXXXXX) |
| 18 | +2. **Validate Expense**: Simple checks for receipt, date, and limits |
| 19 | +3. **Manager Review**: Always suspends for approval via API trigger |
| 20 | +4. **Finalize**: Returns final decision with notes |
| 21 | + |
| 22 | +### Validation Rules |
| 23 | + |
| 24 | +- **Receipt Required**: For expenses over $25 |
| 25 | +- **Date Limit**: Must be within 90 days |
| 26 | +- **Category Limits**: |
| 27 | + - Travel: $2000 |
| 28 | + - Meals: $150 |
| 29 | + - Supplies: $500 |
| 30 | + - Training: $5000 |
| 31 | + - Equipment: $3000 |
| 32 | + - Other: $300 |
| 33 | + |
| 34 | +## Setup |
| 35 | + |
| 36 | +### 1. Install Dependencies |
| 37 | + |
| 38 | +```bash |
| 39 | +cd expense-approval-agent |
| 40 | +pip install uv |
| 41 | +uv venv -p 3.11 .venv |
| 42 | +.venv\Scripts\activate # Windows |
| 43 | +source .venv/bin/activate # Linux/Mac |
| 44 | +uv sync |
| 45 | +``` |
| 46 | + |
| 47 | +### 2. Configure Environment |
| 48 | + |
| 49 | +Create `.env` file: |
| 50 | +```env |
| 51 | +UIPATH_URL=https://your-orchestrator.com |
| 52 | +UIPATH_ACCESS_TOKEN=your_token |
| 53 | +``` |
| 54 | + |
| 55 | +### 3. Test Locally |
| 56 | + |
| 57 | +```bash |
| 58 | +uipath run agent '{ |
| 59 | + "employee_id": "EMP001", |
| 60 | + "employee_name": "Jane Smith", |
| 61 | + "department": "sales", |
| 62 | + "expense_amount": 450.00, |
| 63 | + "expense_category": "travel", |
| 64 | + "expense_description": "Client meeting in Boston - flight and hotel", |
| 65 | + "receipt_attached": true, |
| 66 | + "expense_date": "2024-01-15", |
| 67 | + "manager_email": "manager@company.com" |
| 68 | +}' |
| 69 | +``` |
| 70 | + |
| 71 | +## Usage Examples |
| 72 | + |
| 73 | +### Example 1: Valid Expense |
| 74 | +```json |
| 75 | +{ |
| 76 | + "employee_id": "EMP002", |
| 77 | + "employee_name": "John Doe", |
| 78 | + "department": "engineering", |
| 79 | + "expense_amount": 45.50, |
| 80 | + "expense_category": "meals", |
| 81 | + "expense_description": "Team lunch during sprint planning", |
| 82 | + "receipt_attached": true, |
| 83 | + "expense_date": "2025-09-20" |
| 84 | +} |
| 85 | +``` |
| 86 | +Result: Validates successfully, suspends for manager review |
| 87 | + |
| 88 | +### Example 2: Expense with Warnings |
| 89 | +```json |
| 90 | +{ |
| 91 | + "employee_id": "EMP003", |
| 92 | + "employee_name": "Alice Johnson", |
| 93 | + "department": "hr", |
| 94 | + "expense_amount": 2500.00, |
| 95 | + "expense_category": "travel", |
| 96 | + "expense_description": "Flight and hotel for conference", |
| 97 | + "receipt_attached": true, |
| 98 | + "expense_date": "2025-09-10" |
| 99 | +} |
| 100 | +``` |
| 101 | +Result: Warning (exceeds $2000 limit), suspends for manager review |
| 102 | + |
| 103 | +## Resume Options |
| 104 | + |
| 105 | +When the agent suspends for manager review, you have two options: |
| 106 | + |
| 107 | +### Option 1: Orchestrator UI |
| 108 | +In the "Human review required" popup, simply type: |
| 109 | +- `true` to approve |
| 110 | +- `false` to reject |
| 111 | + |
| 112 | +### Option 2: API Call |
| 113 | +Resume via API with JSON payload: |
| 114 | +```json |
| 115 | +{ |
| 116 | + "approved": true |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +or |
| 121 | + |
| 122 | +```json |
| 123 | +{ |
| 124 | + "approved": false |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +## Output Format |
| 129 | + |
| 130 | +```json |
| 131 | +{ |
| 132 | + "expense_id": "EXP-20251001-ABC123", |
| 133 | + "status": "approved", |
| 134 | + "approval_level": "manager", |
| 135 | + "final_amount": 45.5, |
| 136 | + "processing_notes": [ |
| 137 | + "Expense report EXP-20251001-ABC123 created at 2025-10-01T11:53:07.354154", |
| 138 | + "Approved on 2025-10-01 11:54", |
| 139 | + "Reimbursement by 2025-10-06" |
| 140 | + ], |
| 141 | + "reimbursement_eta": "2025-10-06" |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +## Deployment |
| 146 | + |
| 147 | +### 1. Package and Publish |
| 148 | + |
| 149 | +```bash |
| 150 | +uipath auth |
| 151 | +uipath pack |
| 152 | +uipath publish |
| 153 | +``` |
| 154 | + |
| 155 | +### 2. Monitor in Orchestrator |
| 156 | + |
| 157 | +- View suspended expenses awaiting approval |
| 158 | +- Check processing logs and audit trails |
| 159 | +- Approve/reject directly from Orchestrator UI or call `/orchestrator_/api/JobTriggers/DeliverPayload/{inbox_id}` to resume |
| 160 | + |
| 161 | +## Test Cases |
| 162 | + |
| 163 | +The `test_cases/` folder contains comprehensive test scenarios with **deterministic outputs**: |
| 164 | +- `input/` - Test input files with various expense scenarios |
| 165 | +- `expected_output/` - Expected results for each test case |
| 166 | + |
| 167 | +**Static Values for Reliable Testing:** |
| 168 | +- Expense IDs: Generated from employee_id hash (e.g., EMP001 → EXP-20251001-B86D07B6) |
| 169 | +- Creation time: Always 2025-10-01T10:00:00.000000 |
| 170 | +- Approval time: Always 2025-10-01 10:05 |
| 171 | +- Reimbursement date: Always 2025-10-06 for approved expenses |
| 172 | + |
| 173 | +This ensures the same input always produces the same output, making tests reliable and repeatable. |
0 commit comments