Skip to content

feat: Complete Freight Quote Agent Pipeline#1

Open
0xsaltylollipop wants to merge 10 commits intomainfrom
feature/freight-agent-v2
Open

feat: Complete Freight Quote Agent Pipeline#1
0xsaltylollipop wants to merge 10 commits intomainfrom
feature/freight-agent-v2

Conversation

@0xsaltylollipop
Copy link
Collaborator

Summary

Complete implementation of the Freight Rate Quotation Agent for the hackathon challenge. Processes customer emails, looks up rates from Excel sheets, applies customer SOPs, and generates professional quote responses.

Pipeline Overview (3 GPT calls total)

  1. Extraction (GPT feat: Complete Freight Quote Agent Pipeline #1) - Parse email → shipment details
  2. Enrichment + Validation (GPT #2) - Customer SOP lookup via Qontext + validation
  3. Rate Lookup - Auto-detect Excel format, fuzzy match ports
  4. Quote Calculation - Apply discounts, margins, surcharges
  5. Response Formatting (GPT #3) - Generate professional email

Key Features

  • Multi-format rate sheet support: Auto-detects easy/medium/hard Excel formats
  • Fuzzy port matching: Built-in aliases (HCMC↔Saigon, SFO↔San Francisco, etc.)
  • SOP enforcement: Mode restrictions, origin restrictions, volume discounts
  • Validation safeguards: Forces GPT to validate all shipments
  • 100% test pass rate on all 10 hackathon emails

Files Changed

  • src/extraction.py - Email parsing with subject line mode inference
  • src/enrichment.py - Qontext + GPT enrichment with validation safeguard
  • src/rate_lookup/ - Multi-format Excel parser with fuzzy matching
  • src/quote_calculator.py - Pricing math with SOP rules
  • src/response_formatter.py - GPT-powered email generation
  • src/pipeline.py - Orchestrates all steps
  • tests/ - E2E tests against expected solutions

Test plan

  • Run test_e2e_pipeline.py - 100% pass rate (10/10 emails)
  • Run test_email02_hard.py - Tests hard rate sheet + real SOP enrichment
  • Verify TechParts SOP correctly applied (air-only, 15% margin)
  • Verify volume discount uses total containers across routes

🤖 Generated with Claude Code

0xsaltylollipop and others added 10 commits January 16, 2026 21:13
Design for Step 1+2 of freight agent pipeline:
- GPT-powered email extraction
- Schema for shipments (sea/air)
- Multi-route handling
- Missing field detection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- models.py: Dataclasses for Email, Shipment, ExtractionResult
- extraction.py: GPT extraction with structured output
- test_extraction.py: Tests against all 10 hackathon emails

Key extraction rules:
- Multi-route detection (email with multiple destinations)
- Mode inference: sea vs air based on context
- Volume without weight = sea (container inference)
- Volume + weight = air (volume weight calc)
- Keeps locations raw for later normalization

All 10 test emails pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ing)

Design for completing the freight quote pipeline:
- Step 5: Rate lookup with auto-detect for easy/medium/hard Excel formats
- Step 6: Quote calculation with discounts, margins, surcharges
- Step 7: GPT-generated response formatting for natural email replies

Key decisions:
- Structured Quote dataclass output (not raw email string)
- Support all 3 rate sheet difficulty levels
- Graceful degradation for missing rates
- Total 3 GPT calls (optimized from 5+)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…rmatting

Implements Steps 5-7 of the freight quote agent:

- Rate Lookup (Step 5):
  - Auto-detect Excel format (easy/medium/hard)
  - Parse all 3 formats into unified NormalizedRates
  - Fuzzy matching with built-in port aliases
  - Location cleaning to handle extraction artifacts

- Quote Calculator (Step 6):
  - Deterministic pricing math
  - Support for discounts, margins, surcharges
  - Air freight chargeable weight calculation

- Response Formatter (Step 7):
  - GPT-powered natural email generation
  - Professional tone matching

- Pipeline Orchestrator:
  - Chains all 7 steps together
  - 3 GPT calls total (optimized from 5+)

- E2E Test Suite:
  - Tests all 10 emails against expected solutions
  - 100% pass rate achieved

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ct parsing

Addresses issues from code review:

1. GPT tool call safeguard (enrichment.py)
   - Track validated shipment indices
   - Force tool call if any shipments missed validation
   - Prevents unvalidated shipments slipping through

2. Volume discount uses total containers (quote_calculator.py)
   - Calculate total containers across ALL routes first
   - Pass total to discount calculation
   - Fixes AutoSpares SOP: "total containers across all routes"

3. Check subject line for mode (extraction.py)
   - Explicitly tell GPT to check email subject
   - Add examples: "Air Freight Quote" -> air mode
   - Improves mode inference reliability

4. New test: test_email02_hard.py
   - Tests TechParts air freight with hard rate sheet
   - Uses REAL SOP enrichment (not mock)
   - Validates full pipeline with customer rules

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Flask REST API (api.py) with /quote and /quote/file endpoints
- Add ngrok runner for exposing local API to internet
- Enhance enrichment with improved tool calling and validation
- Add streaming response formatter for better UX
- Expand models with confidence scoring and display flags
- Improve quote calculator with volume discounts and surcharges
- Update pipeline with sync and streaming modes
- Update tests for hard email scenarios

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This guide provides step-by-step instructions for merging both implementations:
- Explains WHY we're integrating (complementary strengths)
- Creates shared models package for type safety
- Uses adapter pattern for minimal code changes
- Preserves all existing tests
- Combines confidence scoring with HITL workflow

Designed to be followed by a Codex agent or team member.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds Step 0 with clear branch strategy:
1. Create new branch from main
2. Merge feature/freight-agent-v2 into it
3. Follow integration steps
4. Open PR to main when complete

This makes the workflow cleaner and safer for the Codex agent.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add local_sop.py with ground truth SOPs from SOP.md
- Implement hybrid enrichment: local SOP first, Qontext for comparison
- Skip Qontext for unknown customers (saves API calls)
- Use local for destination surcharges (Qontext semantic matching unreliable)
- Fix Australia surcharge to only apply to actual Australia destinations
- Fix origin normalization (HCMC, Saigon variants)
- Fix AutoSpares volume discount tiers format
- Add generate_solutions.py for fast solution regeneration
- Update response_formatter with validation error handling
- All 10 e2e tests pass (100%)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant