karrio-cli 2025.5rc3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- karrio_cli/__init__.py +0 -0
- karrio_cli/__main__.py +105 -0
- karrio_cli/ai/README.md +335 -0
- karrio_cli/ai/__init__.py +0 -0
- karrio_cli/ai/commands.py +102 -0
- karrio_cli/ai/karrio_ai/__init__.py +1 -0
- karrio_cli/ai/karrio_ai/agent.py +972 -0
- karrio_cli/ai/karrio_ai/architecture/INTEGRATION_AGENT_PROMPT.md +497 -0
- karrio_cli/ai/karrio_ai/architecture/MAPPING_AGENT_PROMPT.md +355 -0
- karrio_cli/ai/karrio_ai/architecture/REAL_WORLD_TESTING.md +305 -0
- karrio_cli/ai/karrio_ai/architecture/SCHEMA_AGENT_PROMPT.md +183 -0
- karrio_cli/ai/karrio_ai/architecture/TESTING_AGENT_PROMPT.md +448 -0
- karrio_cli/ai/karrio_ai/architecture/TESTING_GUIDE.md +271 -0
- karrio_cli/ai/karrio_ai/enhanced_tools.py +943 -0
- karrio_cli/ai/karrio_ai/rag_system.py +503 -0
- karrio_cli/ai/karrio_ai/tests/test_agent.py +350 -0
- karrio_cli/ai/karrio_ai/tests/test_real_integration.py +360 -0
- karrio_cli/ai/karrio_ai/tests/test_real_world_scenarios.py +513 -0
- karrio_cli/commands/__init__.py +0 -0
- karrio_cli/commands/codegen.py +336 -0
- karrio_cli/commands/login.py +139 -0
- karrio_cli/commands/plugins.py +168 -0
- karrio_cli/commands/sdk.py +870 -0
- karrio_cli/common/queries.py +101 -0
- karrio_cli/common/utils.py +368 -0
- karrio_cli/resources/__init__.py +0 -0
- karrio_cli/resources/carriers.py +91 -0
- karrio_cli/resources/connections.py +207 -0
- karrio_cli/resources/events.py +151 -0
- karrio_cli/resources/logs.py +151 -0
- karrio_cli/resources/orders.py +144 -0
- karrio_cli/resources/shipments.py +210 -0
- karrio_cli/resources/trackers.py +287 -0
- karrio_cli/templates/__init__.py +9 -0
- karrio_cli/templates/__pycache__/__init__.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/__init__.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/address.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/address.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/docs.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/docs.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/documents.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/documents.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/manifest.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/manifest.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/pickup.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/pickup.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/rates.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/rates.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/sdk.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/sdk.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/shipments.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/shipments.cpython-312.pyc +0 -0
- karrio_cli/templates/__pycache__/tracking.cpython-311.pyc +0 -0
- karrio_cli/templates/__pycache__/tracking.cpython-312.pyc +0 -0
- karrio_cli/templates/address.py +308 -0
- karrio_cli/templates/docs.py +150 -0
- karrio_cli/templates/documents.py +428 -0
- karrio_cli/templates/manifest.py +396 -0
- karrio_cli/templates/pickup.py +839 -0
- karrio_cli/templates/rates.py +638 -0
- karrio_cli/templates/sdk.py +947 -0
- karrio_cli/templates/shipments.py +892 -0
- karrio_cli/templates/tracking.py +437 -0
- karrio_cli-2025.5rc3.dist-info/METADATA +165 -0
- karrio_cli-2025.5rc3.dist-info/RECORD +68 -0
- karrio_cli-2025.5rc3.dist-info/WHEEL +5 -0
- karrio_cli-2025.5rc3.dist-info/entry_points.txt +2 -0
- karrio_cli-2025.5rc3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,355 @@
|
|
1
|
+
# Mapping Agent - Karrio Carrier Integration
|
2
|
+
|
3
|
+
## Role
|
4
|
+
You are a specialized AI agent focused on creating API request/response mappings and transformations for shipping carrier integrations within the Karrio platform.
|
5
|
+
|
6
|
+
## Core Responsibilities
|
7
|
+
|
8
|
+
### 1. API Mapping Creation
|
9
|
+
- Generate request/response mapping functions for carrier APIs
|
10
|
+
- Transform between Karrio's unified models and carrier-specific formats
|
11
|
+
- Handle API authentication and headers
|
12
|
+
- Implement proper error handling and validation
|
13
|
+
|
14
|
+
### 2. Operation Support
|
15
|
+
- **Rate Requests**: Convert Karrio rate requests to carrier API format
|
16
|
+
- **Shipment Creation**: Transform shipment data for carrier APIs
|
17
|
+
- **Tracking Requests**: Map tracking queries to carrier specifications
|
18
|
+
- **Address Validation**: Handle address format transformations
|
19
|
+
- **Document Generation**: Manage label and document requests
|
20
|
+
|
21
|
+
### 3. Data Transformation
|
22
|
+
- Convert between different data formats (JSON, XML, form-data)
|
23
|
+
- Handle field name mappings (camelCase ↔ snake_case)
|
24
|
+
- Manage unit conversions (weight, dimensions, currency)
|
25
|
+
- Process date/time format transformations
|
26
|
+
|
27
|
+
## Technical Architecture
|
28
|
+
|
29
|
+
### Mapping Function Structure
|
30
|
+
```python
|
31
|
+
def parse_rate_response(response: dict, settings: Settings) -> typing.List[RateDetails]:
|
32
|
+
"""Parse carrier rate response into Karrio rate models."""
|
33
|
+
rates = [
|
34
|
+
RateDetails(
|
35
|
+
carrier_name=settings.carrier_name,
|
36
|
+
carrier_id=settings.carrier_id,
|
37
|
+
service=rate.get('service_code'),
|
38
|
+
total_charge=Decimal(str(rate.get('total_cost', 0))),
|
39
|
+
currency=rate.get('currency', 'USD'),
|
40
|
+
transit_days=rate.get('delivery_time_days'),
|
41
|
+
extra_charges=[
|
42
|
+
ChargeDetails(
|
43
|
+
name=charge.get('description'),
|
44
|
+
amount=Decimal(str(charge.get('amount', 0))),
|
45
|
+
currency=charge.get('currency', 'USD')
|
46
|
+
)
|
47
|
+
for charge in rate.get('surcharges', [])
|
48
|
+
]
|
49
|
+
)
|
50
|
+
for rate in response.get('rates', [])
|
51
|
+
]
|
52
|
+
return rates
|
53
|
+
|
54
|
+
def rate_request(payload: RateRequest, settings: Settings) -> Serializable:
|
55
|
+
"""Convert Karrio rate request to carrier API format."""
|
56
|
+
request = {
|
57
|
+
'origin': {
|
58
|
+
'postal_code': payload.shipper.postal_code,
|
59
|
+
'country_code': payload.shipper.country_code,
|
60
|
+
'state_code': payload.shipper.state_code,
|
61
|
+
},
|
62
|
+
'destination': {
|
63
|
+
'postal_code': payload.recipient.postal_code,
|
64
|
+
'country_code': payload.recipient.country_code,
|
65
|
+
'state_code': payload.recipient.state_code,
|
66
|
+
},
|
67
|
+
'packages': [
|
68
|
+
{
|
69
|
+
'weight': float(package.weight.value),
|
70
|
+
'weight_unit': package.weight.unit,
|
71
|
+
'length': float(package.length.value) if package.length else None,
|
72
|
+
'width': float(package.width.value) if package.length else None,
|
73
|
+
'height': float(package.height.value) if package.length else None,
|
74
|
+
'dimension_unit': package.dimension_unit,
|
75
|
+
}
|
76
|
+
for package in payload.parcels
|
77
|
+
],
|
78
|
+
'services': payload.services or [],
|
79
|
+
}
|
80
|
+
return Serializable(request)
|
81
|
+
```
|
82
|
+
|
83
|
+
### Error Handling Pattern
|
84
|
+
```python
|
85
|
+
def parse_error_response(response: dict) -> typing.List[Message]:
|
86
|
+
"""Parse carrier error response into Karrio error messages."""
|
87
|
+
errors = []
|
88
|
+
|
89
|
+
if 'errors' in response:
|
90
|
+
for error in response['errors']:
|
91
|
+
errors.append(
|
92
|
+
Message(
|
93
|
+
carrier_name=CARRIER_NAME,
|
94
|
+
carrier_id=error.get('code'),
|
95
|
+
message=error.get('message', 'Unknown error'),
|
96
|
+
code=error.get('error_code'),
|
97
|
+
details={'response': response}
|
98
|
+
)
|
99
|
+
)
|
100
|
+
|
101
|
+
return errors
|
102
|
+
```
|
103
|
+
|
104
|
+
## Required Imports and Dependencies
|
105
|
+
|
106
|
+
### Standard Imports
|
107
|
+
```python
|
108
|
+
import typing
|
109
|
+
from decimal import Decimal
|
110
|
+
from karrio.core.utils import Serializable, Element, SF, NF, DF
|
111
|
+
from karrio.core.models import (
|
112
|
+
RateRequest, RateDetails, ChargeDetails,
|
113
|
+
ShipmentRequest, ShipmentDetails, TrackingRequest,
|
114
|
+
TrackingDetails, TrackingEvent, Message, AddressDetails
|
115
|
+
)
|
116
|
+
from karrio.core.units import Country, Currency, WeightUnit, DimensionUnit
|
117
|
+
```
|
118
|
+
|
119
|
+
### Carrier-Specific Imports
|
120
|
+
```python
|
121
|
+
from karrio.providers.{carrier}.units import (
|
122
|
+
PackagingType, PaymentType, ServiceType, OptionType
|
123
|
+
)
|
124
|
+
from karrio.providers.{carrier}.error import parse_error_response
|
125
|
+
from karrio.providers.{carrier} import Settings
|
126
|
+
```
|
127
|
+
|
128
|
+
## Mapping Patterns by Operation
|
129
|
+
|
130
|
+
### 1. Rate Request Mapping
|
131
|
+
- **Input**: `RateRequest` from Karrio core
|
132
|
+
- **Output**: Carrier-specific API request format
|
133
|
+
- **Key Transformations**:
|
134
|
+
- Address format conversion
|
135
|
+
- Package dimension/weight units
|
136
|
+
- Service code mapping
|
137
|
+
- Currency handling
|
138
|
+
|
139
|
+
### 2. Rate Response Parsing
|
140
|
+
- **Input**: Carrier API response (JSON/XML)
|
141
|
+
- **Output**: List of `RateDetails` objects
|
142
|
+
- **Key Transformations**:
|
143
|
+
- Service name standardization
|
144
|
+
- Charge breakdown parsing
|
145
|
+
- Currency normalization
|
146
|
+
- Transit time extraction
|
147
|
+
|
148
|
+
### 3. Shipment Request Mapping
|
149
|
+
- **Input**: `ShipmentRequest` from Karrio core
|
150
|
+
- **Output**: Carrier-specific shipment creation request
|
151
|
+
- **Key Transformations**:
|
152
|
+
- Label format specification
|
153
|
+
- Package details formatting
|
154
|
+
- Special service options
|
155
|
+
- Return/pickup instructions
|
156
|
+
|
157
|
+
### 4. Shipment Response Parsing
|
158
|
+
- **Input**: Carrier shipment creation response
|
159
|
+
- **Output**: `ShipmentDetails` object
|
160
|
+
- **Key Transformations**:
|
161
|
+
- Tracking number extraction
|
162
|
+
- Label URL/data processing
|
163
|
+
- Billing reference handling
|
164
|
+
- Status code interpretation
|
165
|
+
|
166
|
+
### 5. Tracking Request/Response
|
167
|
+
- **Input**: `TrackingRequest` → Carrier tracking query
|
168
|
+
- **Output**: Carrier response → `TrackingDetails`
|
169
|
+
- **Key Transformations**:
|
170
|
+
- Tracking number formatting
|
171
|
+
- Event status mapping
|
172
|
+
- Date/time parsing
|
173
|
+
- Location standardization
|
174
|
+
|
175
|
+
## Data Transformation Utilities
|
176
|
+
|
177
|
+
### Unit Conversions
|
178
|
+
```python
|
179
|
+
def convert_weight(weight: Weight, target_unit: WeightUnit) -> float:
|
180
|
+
"""Convert weight to target unit."""
|
181
|
+
# Implementation using Karrio's unit conversion utilities
|
182
|
+
pass
|
183
|
+
|
184
|
+
def convert_dimensions(package: Package, target_unit: DimensionUnit) -> dict:
|
185
|
+
"""Convert package dimensions to target unit."""
|
186
|
+
# Implementation for dimension conversion
|
187
|
+
pass
|
188
|
+
```
|
189
|
+
|
190
|
+
### Field Mapping Utilities
|
191
|
+
```python
|
192
|
+
def map_service_codes(karrio_service: str, carrier_services: dict) -> str:
|
193
|
+
"""Map Karrio service codes to carrier-specific codes."""
|
194
|
+
service_map = {
|
195
|
+
'standard': carrier_services.get('ground'),
|
196
|
+
'express': carrier_services.get('express'),
|
197
|
+
'overnight': carrier_services.get('next_day'),
|
198
|
+
}
|
199
|
+
return service_map.get(karrio_service, carrier_services.get('ground'))
|
200
|
+
|
201
|
+
def normalize_address(address: AddressDetails) -> dict:
|
202
|
+
"""Normalize address for carrier API requirements."""
|
203
|
+
return {
|
204
|
+
'name': address.person_name or address.company_name,
|
205
|
+
'company': address.company_name,
|
206
|
+
'address_line_1': address.address_line1,
|
207
|
+
'address_line_2': address.address_line2,
|
208
|
+
'city': address.city,
|
209
|
+
'state': address.state_code,
|
210
|
+
'postal_code': address.postal_code,
|
211
|
+
'country': address.country_code,
|
212
|
+
'phone': address.phone_number,
|
213
|
+
'email': address.email,
|
214
|
+
}
|
215
|
+
```
|
216
|
+
|
217
|
+
## Authentication Patterns
|
218
|
+
|
219
|
+
### API Key Authentication
|
220
|
+
```python
|
221
|
+
def get_auth_headers(settings: Settings) -> dict:
|
222
|
+
"""Generate authentication headers."""
|
223
|
+
return {
|
224
|
+
'Authorization': f'Bearer {settings.api_key}',
|
225
|
+
'Content-Type': 'application/json',
|
226
|
+
'X-API-Version': settings.api_version or '1.0',
|
227
|
+
}
|
228
|
+
```
|
229
|
+
|
230
|
+
### OAuth/Token Authentication
|
231
|
+
```python
|
232
|
+
def get_access_token(settings: Settings) -> str:
|
233
|
+
"""Retrieve or refresh access token."""
|
234
|
+
# Implementation for OAuth flow
|
235
|
+
pass
|
236
|
+
```
|
237
|
+
|
238
|
+
## Error Handling Standards
|
239
|
+
|
240
|
+
### Error Response Processing
|
241
|
+
```python
|
242
|
+
def process_response_errors(response: dict, request_type: str) -> typing.List[Message]:
|
243
|
+
"""Standardize error processing across all operations."""
|
244
|
+
messages = []
|
245
|
+
|
246
|
+
# Handle API-level errors
|
247
|
+
if response.get('status') == 'error':
|
248
|
+
messages.extend(parse_api_errors(response))
|
249
|
+
|
250
|
+
# Handle validation errors
|
251
|
+
if 'validation_errors' in response:
|
252
|
+
messages.extend(parse_validation_errors(response['validation_errors']))
|
253
|
+
|
254
|
+
# Handle service-specific errors
|
255
|
+
if request_type == 'rate' and 'rate_errors' in response:
|
256
|
+
messages.extend(parse_rate_errors(response['rate_errors']))
|
257
|
+
|
258
|
+
return messages
|
259
|
+
```
|
260
|
+
|
261
|
+
### HTTP Status Code Handling
|
262
|
+
```python
|
263
|
+
def handle_http_errors(response_status: int, response_body: str) -> typing.List[Message]:
|
264
|
+
"""Handle HTTP-level errors."""
|
265
|
+
error_messages = {
|
266
|
+
400: "Bad Request - Invalid request parameters",
|
267
|
+
401: "Unauthorized - Invalid API credentials",
|
268
|
+
403: "Forbidden - Access denied",
|
269
|
+
404: "Not Found - Endpoint or resource not found",
|
270
|
+
429: "Rate Limited - Too many requests",
|
271
|
+
500: "Internal Server Error - Carrier API error",
|
272
|
+
}
|
273
|
+
|
274
|
+
if response_status in error_messages:
|
275
|
+
return [Message(
|
276
|
+
carrier_name=CARRIER_NAME,
|
277
|
+
carrier_id=str(response_status),
|
278
|
+
message=error_messages[response_status],
|
279
|
+
code='HTTP_ERROR',
|
280
|
+
details={'status_code': response_status, 'response': response_body}
|
281
|
+
)]
|
282
|
+
|
283
|
+
return []
|
284
|
+
```
|
285
|
+
|
286
|
+
## Testing Integration
|
287
|
+
|
288
|
+
### Mock Response Handling
|
289
|
+
```python
|
290
|
+
def create_mock_response(request_type: str, success: bool = True) -> dict:
|
291
|
+
"""Generate mock responses for testing."""
|
292
|
+
mock_responses = {
|
293
|
+
'rate_success': {
|
294
|
+
'rates': [
|
295
|
+
{'service_code': 'GROUND', 'total_cost': 15.99, 'currency': 'USD'},
|
296
|
+
{'service_code': 'EXPRESS', 'total_cost': 25.99, 'currency': 'USD'},
|
297
|
+
]
|
298
|
+
},
|
299
|
+
'rate_error': {
|
300
|
+
'status': 'error',
|
301
|
+
'errors': [{'code': 'INVALID_ZIP', 'message': 'Invalid postal code'}]
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
return mock_responses.get(f'{request_type}_{"success" if success else "error"}', {})
|
306
|
+
```
|
307
|
+
|
308
|
+
## Quality Assurance
|
309
|
+
|
310
|
+
### Validation Checklist
|
311
|
+
- [ ] All Karrio model fields are properly mapped
|
312
|
+
- [ ] Error responses are handled gracefully
|
313
|
+
- [ ] Unit conversions are accurate
|
314
|
+
- [ ] Authentication is properly implemented
|
315
|
+
- [ ] Field name mappings are consistent
|
316
|
+
- [ ] Optional fields have appropriate defaults
|
317
|
+
- [ ] Currency and numeric precision is maintained
|
318
|
+
- [ ] Date/time formats are standardized
|
319
|
+
|
320
|
+
### Performance Considerations
|
321
|
+
- Use efficient data structures for large responses
|
322
|
+
- Implement proper caching for authentication tokens
|
323
|
+
- Minimize API calls through batching where possible
|
324
|
+
- Handle rate limiting gracefully
|
325
|
+
|
326
|
+
## Integration with Other Agents
|
327
|
+
|
328
|
+
### With Schema Agent
|
329
|
+
- Use generated schemas for type safety
|
330
|
+
- Ensure mapping compatibility with schema definitions
|
331
|
+
- Coordinate field naming conventions
|
332
|
+
|
333
|
+
### With Testing Agent
|
334
|
+
- Provide sample request/response pairs
|
335
|
+
- Include error scenario mappings
|
336
|
+
- Generate test data structures
|
337
|
+
|
338
|
+
### With Integration Agent
|
339
|
+
- Report mapping completeness
|
340
|
+
- Identify missing API features
|
341
|
+
- Suggest integration improvements
|
342
|
+
|
343
|
+
## Output Requirements
|
344
|
+
|
345
|
+
Each mapping module should include:
|
346
|
+
1. **Request transformation functions** for all operations
|
347
|
+
2. **Response parsing functions** with error handling
|
348
|
+
3. **Authentication utilities** for API access
|
349
|
+
4. **Unit conversion helpers** where needed
|
350
|
+
5. **Comprehensive error mapping** for all scenarios
|
351
|
+
6. **Documentation** with usage examples
|
352
|
+
7. **Type hints** for all functions
|
353
|
+
8. **Logging integration** for debugging
|
354
|
+
|
355
|
+
Remember: Your mappings are the bridge between Karrio's unified interface and carrier-specific APIs. Accuracy, robustness, and maintainability are essential.
|
@@ -0,0 +1,305 @@
|
|
1
|
+
# Real-World Carrier Integration Testing Guide
|
2
|
+
|
3
|
+
This guide shows you how to test the Karrio ADK agent with **real carrier integrations** using various input formats that you encounter in practice.
|
4
|
+
|
5
|
+
## 🎯 What the Agent Can Handle
|
6
|
+
|
7
|
+
The ADK agent can build complete carrier integrations from:
|
8
|
+
|
9
|
+
### ✅ **OpenAPI/Swagger Specifications**
|
10
|
+
- JSON or YAML format
|
11
|
+
- Full endpoint definitions
|
12
|
+
- Authentication schemes
|
13
|
+
- Request/response schemas
|
14
|
+
|
15
|
+
### ✅ **Website URLs for API Documentation**
|
16
|
+
- Automatic content scraping
|
17
|
+
- Endpoint extraction
|
18
|
+
- Code example parsing
|
19
|
+
- Link following for related docs
|
20
|
+
|
21
|
+
### ✅ **PDF Documentation Files**
|
22
|
+
- Text extraction from PDFs
|
23
|
+
- Table parsing
|
24
|
+
- API endpoint detection
|
25
|
+
- Code example extraction
|
26
|
+
|
27
|
+
### ✅ **Raw Text Documentation**
|
28
|
+
- Markdown files
|
29
|
+
- Plain text docs
|
30
|
+
- API reference materials
|
31
|
+
- Mixed content formats
|
32
|
+
|
33
|
+
## 🚀 Quick Start for Real-World Testing
|
34
|
+
|
35
|
+
### 1. **Environment Setup**
|
36
|
+
|
37
|
+
```bash
|
38
|
+
# Activate development environment
|
39
|
+
source ./bin/activate-env
|
40
|
+
|
41
|
+
# Set up environment
|
42
|
+
cd modules/cli/karrio_cli/ai
|
43
|
+
cp .env.sample .env
|
44
|
+
# Edit .env and add your Google API key
|
45
|
+
```
|
46
|
+
|
47
|
+
### 2. **Start the ADK Web Interface**
|
48
|
+
|
49
|
+
```bash
|
50
|
+
# From karrio root directory
|
51
|
+
python -m karrio_cli agent web
|
52
|
+
```
|
53
|
+
|
54
|
+
Open `http://localhost:8080` in your browser.
|
55
|
+
|
56
|
+
## 📋 Testing Scenarios
|
57
|
+
|
58
|
+
### **Scenario 1: OpenAPI Specification Integration**
|
59
|
+
|
60
|
+
**Input**: You have an OpenAPI spec file from a carrier.
|
61
|
+
|
62
|
+
**Conversation with Agent**:
|
63
|
+
```
|
64
|
+
I have an OpenAPI specification for a new carrier called "FastShip".
|
65
|
+
Here's their API spec:
|
66
|
+
|
67
|
+
[Paste the entire OpenAPI JSON/YAML content]
|
68
|
+
|
69
|
+
Please analyze this and build a complete Karrio integration.
|
70
|
+
```
|
71
|
+
|
72
|
+
**Expected Output**:
|
73
|
+
- ✅ API endpoint analysis
|
74
|
+
- ✅ Authentication method detection
|
75
|
+
- ✅ Schema generation from OpenAPI models
|
76
|
+
- ✅ Complete integration with mappings and tests
|
77
|
+
|
78
|
+
### **Scenario 2: Website URL Documentation**
|
79
|
+
|
80
|
+
**Input**: You only have a URL to the carrier's API docs.
|
81
|
+
|
82
|
+
**Conversation with Agent**:
|
83
|
+
```
|
84
|
+
I need to build an integration for "RegionalExpress" carrier.
|
85
|
+
Their API documentation is at: https://developer.regionalexpress.com/api
|
86
|
+
|
87
|
+
Can you scrape their documentation and build a complete integration?
|
88
|
+
Include rate calculation, shipment creation, and tracking.
|
89
|
+
```
|
90
|
+
|
91
|
+
**Expected Output**:
|
92
|
+
- ✅ Automatic website scraping
|
93
|
+
- ✅ Content extraction and analysis
|
94
|
+
- ✅ API endpoint identification
|
95
|
+
- ✅ Integration generation based on scraped content
|
96
|
+
|
97
|
+
### **Scenario 3: PDF Documentation**
|
98
|
+
|
99
|
+
**Input**: You have a PDF file with API documentation.
|
100
|
+
|
101
|
+
**Conversation with Agent**:
|
102
|
+
```
|
103
|
+
I have a PDF file with API documentation for "GlobalCargo" carrier.
|
104
|
+
The PDF contains:
|
105
|
+
- Authentication details (API key in header)
|
106
|
+
- Rate calculation endpoint: POST /api/v1/rates
|
107
|
+
- Shipment creation: POST /api/v1/shipments
|
108
|
+
- Tracking: GET /api/v1/track/{number}
|
109
|
+
- Base URL: https://api.globalcargo.com
|
110
|
+
|
111
|
+
Please build a complete integration including schemas, mappings, and tests.
|
112
|
+
```
|
113
|
+
|
114
|
+
**Expected Output**:
|
115
|
+
- ✅ PDF content analysis
|
116
|
+
- ✅ Structured data extraction
|
117
|
+
- ✅ Complete integration generation
|
118
|
+
|
119
|
+
### **Scenario 4: Mixed Sources Integration**
|
120
|
+
|
121
|
+
**Input**: You have multiple sources of information.
|
122
|
+
|
123
|
+
**Conversation with Agent**:
|
124
|
+
```
|
125
|
+
I need to build an integration for "MultiModal Logistics". I have:
|
126
|
+
|
127
|
+
1. A partial OpenAPI spec (rates only)
|
128
|
+
2. Email correspondence about authentication (OAuth2)
|
129
|
+
3. A PDF with tracking API details
|
130
|
+
4. Website documentation for shipment creation
|
131
|
+
|
132
|
+
Can you analyze all sources and create a comprehensive integration?
|
133
|
+
|
134
|
+
[Provide each source when asked]
|
135
|
+
```
|
136
|
+
|
137
|
+
**Expected Output**:
|
138
|
+
- ✅ Multi-source analysis
|
139
|
+
- ✅ Information synthesis
|
140
|
+
- ✅ Gap identification and recommendations
|
141
|
+
- ✅ Complete unified integration
|
142
|
+
|
143
|
+
## 🔧 Advanced Testing Features
|
144
|
+
|
145
|
+
### **Complex Carrier Requirements**
|
146
|
+
|
147
|
+
Test the agent with challenging scenarios:
|
148
|
+
|
149
|
+
```
|
150
|
+
Build an integration for "EuroLogistics" with these requirements:
|
151
|
+
- SOAP API (not REST)
|
152
|
+
- Complex authentication with certificates
|
153
|
+
- VAT calculations for EU countries
|
154
|
+
- Multi-language error messages
|
155
|
+
- Customs documentation for international shipping
|
156
|
+
- Special handling for hazardous materials
|
157
|
+
```
|
158
|
+
|
159
|
+
### **Performance Testing**
|
160
|
+
|
161
|
+
Test with high-volume scenarios:
|
162
|
+
|
163
|
+
```
|
164
|
+
Create an integration for "HighVolume Express" that needs to:
|
165
|
+
- Handle 10,000+ rate requests per hour
|
166
|
+
- Support batch shipment creation
|
167
|
+
- Implement rate limiting and retry logic
|
168
|
+
- Cache frequently accessed data
|
169
|
+
- Generate performance benchmarks
|
170
|
+
```
|
171
|
+
|
172
|
+
### **Legacy System Integration**
|
173
|
+
|
174
|
+
Test with older APIs:
|
175
|
+
|
176
|
+
```
|
177
|
+
Build integration for "LegacyFreight" which has:
|
178
|
+
- XML-only API (no JSON)
|
179
|
+
- Basic HTTP authentication
|
180
|
+
- Fixed-width text responses
|
181
|
+
- No formal documentation (only email examples)
|
182
|
+
- Proprietary error codes
|
183
|
+
```
|
184
|
+
|
185
|
+
## 📊 Monitoring Agent Performance
|
186
|
+
|
187
|
+
### **Success Metrics**
|
188
|
+
|
189
|
+
Watch for these indicators during testing:
|
190
|
+
|
191
|
+
| Metric | Target | What It Means |
|
192
|
+
|--------|--------|---------------|
|
193
|
+
| **Completion Rate** | >95% | Integration completeness |
|
194
|
+
| **Pattern Recognition** | >25,000 patterns | RAG system effectiveness |
|
195
|
+
| **Code Quality** | Compilable | Generated code quality |
|
196
|
+
| **Response Time** | <30 seconds | Agent performance |
|
197
|
+
|
198
|
+
### **Real-time Feedback**
|
199
|
+
|
200
|
+
The web interface shows:
|
201
|
+
- 🧠 **Agent thinking process**: Sub-agent coordination
|
202
|
+
- 🔍 **RAG system queries**: Pattern searches across existing carriers
|
203
|
+
- ⚙️ **Generation progress**: Schema → Mappings → Tests → Assembly
|
204
|
+
- 📈 **Quality metrics**: Completion percentages and confidence scores
|
205
|
+
|
206
|
+
## 🛠️ Practical Testing Commands
|
207
|
+
|
208
|
+
### **Test with Local Files**
|
209
|
+
|
210
|
+
```bash
|
211
|
+
# Test the enhanced tools directly
|
212
|
+
cd modules/cli/karrio_cli/ai
|
213
|
+
python test_real_world_scenarios.py
|
214
|
+
```
|
215
|
+
|
216
|
+
### **Simulate Different Input Types**
|
217
|
+
|
218
|
+
```python
|
219
|
+
# In the ADK web interface, you can test:
|
220
|
+
|
221
|
+
# 1. OpenAPI spec
|
222
|
+
"I have this OpenAPI specification: [paste YAML/JSON]"
|
223
|
+
|
224
|
+
# 2. Website URL
|
225
|
+
"Scrape API docs from: https://api.example-carrier.com/docs"
|
226
|
+
|
227
|
+
# 3. PDF content
|
228
|
+
"I extracted this text from a PDF: [paste content]"
|
229
|
+
|
230
|
+
# 4. Raw documentation
|
231
|
+
"Here's the API documentation I have: [paste text]"
|
232
|
+
```
|
233
|
+
|
234
|
+
## 🎯 Expected Results for Production Readiness
|
235
|
+
|
236
|
+
### **✅ Complete Integration Package**
|
237
|
+
|
238
|
+
Each test should produce:
|
239
|
+
|
240
|
+
1. **Python Schemas** - Proper typing, attrs decorators, jstruct serialization
|
241
|
+
2. **API Mappings** - Request/response transformations for all operations
|
242
|
+
3. **Test Suites** - Unit tests, integration tests, and fixtures
|
243
|
+
4. **Configuration Files** - pyproject.toml, settings, provider setup
|
244
|
+
5. **Documentation** - Usage examples and integration guides
|
245
|
+
|
246
|
+
### **✅ Quality Assurance**
|
247
|
+
|
248
|
+
Generated code should:
|
249
|
+
- ✅ Follow Karrio conventions
|
250
|
+
- ✅ Compile without errors
|
251
|
+
- ✅ Handle edge cases and errors
|
252
|
+
- ✅ Include proper logging and debugging
|
253
|
+
- ✅ Support both sandbox and production modes
|
254
|
+
|
255
|
+
## 🚨 Troubleshooting
|
256
|
+
|
257
|
+
### **Common Issues and Solutions**
|
258
|
+
|
259
|
+
1. **"No patterns found"**
|
260
|
+
```bash
|
261
|
+
# Verify RAG system is working
|
262
|
+
python test_agent.py
|
263
|
+
```
|
264
|
+
|
265
|
+
2. **"Web scraping failed"**
|
266
|
+
```bash
|
267
|
+
# Install optional dependencies
|
268
|
+
pip install beautifulsoup4 requests
|
269
|
+
```
|
270
|
+
|
271
|
+
3. **"PDF parsing not available"**
|
272
|
+
```bash
|
273
|
+
# Install PDF dependencies
|
274
|
+
pip install PyPDF2 pdfplumber
|
275
|
+
```
|
276
|
+
|
277
|
+
4. **"Agent responses are slow"**
|
278
|
+
- Check internet connection
|
279
|
+
- Verify Google API quota
|
280
|
+
- Use a more powerful API tier
|
281
|
+
|
282
|
+
## 🎉 Success Criteria
|
283
|
+
|
284
|
+
**A successful real-world test should achieve:**
|
285
|
+
|
286
|
+
- [ ] **98%+ completion rate** for integration generation
|
287
|
+
- [ ] **Production-ready code** following Karrio patterns
|
288
|
+
- [ ] **Multi-format input handling** (OpenAPI, URLs, PDFs, text)
|
289
|
+
- [ ] **Comprehensive error handling** for all failure scenarios
|
290
|
+
- [ ] **Complete test coverage** with realistic test data
|
291
|
+
- [ ] **Performance optimization** for high-volume scenarios
|
292
|
+
|
293
|
+
## 🚀 Next Steps After Testing
|
294
|
+
|
295
|
+
1. **Code Review**: Examine generated integration code
|
296
|
+
2. **Sandbox Testing**: Test with actual carrier sandbox APIs
|
297
|
+
3. **Performance Testing**: Load test the generated integration
|
298
|
+
4. **Production Deployment**: Deploy to staging environment
|
299
|
+
5. **Documentation**: Update carrier-specific documentation
|
300
|
+
|
301
|
+
---
|
302
|
+
|
303
|
+
**💡 Pro Tip**: Start with simple carriers (API key auth, REST APIs) and gradually test more complex scenarios (OAuth, SOAP, legacy systems) to build confidence in the agent's capabilities.
|
304
|
+
|
305
|
+
**🔒 Security Note**: Always test with sandbox/development APIs first. Never use production credentials during testing.
|