TaskRouter + Pareto Routing Integration â Document Index â
Project Status: Design Complete, Ready for Implementation Created: 2026-02-15 Timeline: 3 Weeks (15 Working Days) Goal: 18% Cost Reduction ($550 â $450/mo) with Hard Constraint Enforcement
Quick Navigation â
For Different Audiences â
Architects & Technical Leads Start here â Read in this order:
- INTEGRATION_ARCHITECTURE.md § 1â3 (Executive Summary + Module Map + Data Flow)
- INTEGRATION_ARCHITECTURE.md § 5 (Constraint Enforcement Matrix)
- INTEGRATION_ARCHITECTURE.md § 7 (Phase Breakdown)
Software Engineers (Implementers) Start here â Read in this order:
- INTEGRATION_QUICK_START.md (25-action checklist)
- INTEGRATION_ARCHITECTURE.md § 2 (Module-by-module changes with code examples)
- INTEGRATION_ARCHITECTURE.md § 4 (File Changes Summary table)
- INTEGRATION_ARCHITECTURE.md § 8 (Testing Strategy)
Operations & Monitoring Start here â Read in this order:
- INTEGRATION_QUICK_START.md § "Risky Spots"
- INTEGRATION_QUICK_START.md § "Debugging & Troubleshooting"
- INTEGRATION_ARCHITECTURE.md § 9 (Monitoring & Metrics)
- INTEGRATION_ARCHITECTURE.md § 10 (Rollback Plan)
Document Summary â
INTEGRATION_ARCHITECTURE.md (1,482 lines) â
Comprehensive technical design document covering all aspects of TaskRouter + Pareto routing integration.
Key Sections:
Executive Summary Context, 3-phase approach, hard constraints (perf, cost, speed)
Module Integration Map
- execution.py: RunMeta extensions (+15 LOC)
- cli_impl.py: TaskRouter integration point (+20 LOC)
- governance/cost.py: Per-category cost tracking (+40 LOC)
- models/catalog.py: Pareto-aware routing (+50 LOC, Phase 2 optional)
- config.py: TaskRouter configuration schema (+20 LOC)
- routing/: New module (360 LOC total)
Data Flow Diagram (ASCII) 7-step flow from user command â TaskRouter.classify() â ConstraintValidator â PolicyEngine â resolve_route_for_category() â dispatch
File Changes Summary Table: 9 files, ~1,205 LOC total, LOC breakdown by priority
Constraint Enforcement Matrix Hard constraints (all must pass):
- Performance: Quality thresholds 60%â80% by category
- Instantaneous: $0.002â$0.85 per-call limits
- Cumulative: Monthly $50â$200 budgets by category
- Speed: 1sâ60s SLAs by category
Configuration Schema YAML/env var reference for all routing settings (task classification, constraints, budgets)
Phase Breakdown (3 Weeks)
- Week 1 (Days 1â5): Core routing (TaskRouter module, config, integration)
- Week 2 (Days 6â10): Policy + cost integration (CostAggregator, PolicyEngine, Pareto routing)
- Week 3 (Days 11â15): Testing + rollout (shadow run, enforcement, post-launch)
Testing Strategy
- Unit: TaskClassifier, ConstraintValidator, CostAggregator (70%)
- Integration: Full flow, cost tracking, budget enforcement (20%)
- E2E: FAST/HIGH_COMPLEX routing, budget exhaustion (10%)
- Target coverage: âĨ90% for routing/
Monitoring & Metrics
- SLOs: Routing latency <100ms p99, budget accuracy <10%, violation rate <1%
- Dashboard queries: Cost by category, utilization %, fallback frequency
- Metric thresholds and alert conditions
Rollback Plan Disable flags, restore backups, git revert procedures
INTEGRATION_QUICK_START.md (467 lines) â
1-page action checklist targeting 2-hour understanding + implementation kickoff.
Key Sections:
Overview 2-hour target audience, status, timeline
25-Action Implementation Checklist Ordered by dependency, with time estimates and success criteria:
- Phase 1 (Days 1â5): Actions 1â18 (routing module + integration)
- Phase 2 (Days 6â10): Actions 19â25 (cost enforcement + Pareto routing)
- Phase 3 (Days 11â15): Shadow run + rollout (passive)
File Changes at a Glance Visual tree of new/modified files with LOC counts
Risky Spots (5 Identified)
- Concurrent cost tracking (file lock needed)
- Policy ordering (TaskRouter before PolicyEngine)
- Classifier accuracy (token estimation can be off by 2â3x)
- Config parsing (JSON can fail silently)
- Fallback chain unbounding (memory leak risk) Each with risk, mitigation, and action
Success Criteria by Phase Checkpoints for Phase 1 (core routing), Phase 2 (cost enforcement), Phase 3 (production)
Dependency Graph Execution order for implementation (config â routing â cli_impl â execution â governance)
Debugging & Troubleshooting Commands to diagnose token estimation, budget enforcement, constraint violations, config issues
Rollback (Quick Reference) Immediate disable, restore from backup, git revert
Implementation Roadmap â
Pre-Work (Week 0) â
- [ ] Read architecture + quick-start documents
- [ ] Set up feature branches (feature/taskrouter-phase1, etc.)
- [ ] Prepare test environment
- [ ] Schedule code review pairing sessions
Week 1: Core Routing (Days 1â5) â
- [ ] Action 1â6: Create routing/ module (TaskRouter, TaskClassifier, ConstraintValidator)
- [ ] Action 7â10: Extend config.py + RunMeta
- [ ] Action 11â13: Integrate into cli_impl.py
- [ ] Action 14â18: Unit + E2E testing
- Deliverable: TaskRouter integrated, 90%+ tested, 100 test tasks classified
Week 2: Policy + Cost (Days 6â10) â
- [ ] Action 19â21: Extend CostAggregator + PolicyEngine
- [ ] Action 22â24: Pareto routing (Phase 2, optional)
- [ ] Action 25: Monitoring setup
- Deliverable: Cost enforcement working, integration tests pass, dashboard ready
Week 3: Testing + Rollout (Days 11â15) â
- [ ] Day 11â12: Shadow run (no enforcement, collect calibration data)
- [ ] Day 13: Full enforcement rollout
- [ ] Day 14: Tuning + documentation
- [ ] Day 15: Post-launch monitoring
- Deliverable: 18% cost reduction, metrics stable, post-launch report
Key Metrics & SLOs â
Success Criteria (End of Phase 3) â
| Metric | Target | Current | Owner |
|---|---|---|---|
| Cost Reduction | 18% ($550â$450/mo) | TBD | Finance |
| Routing Latency (p99) | < 100ms | Baseline | Eng |
| Budget Accuracy | < 10% error | Baseline | Eng |
| Constraint Violation Rate | < 1% (false positives) | Baseline | Eng |
| Fallback Frequency (HIGH_COMPLEX) | < 5% | Baseline | Eng |
| Code Coverage (routing/) | âĨ90% | Baseline | Eng |
Hard Constraints (Must Pass) â
Performance (Quality Thresholds):
FAST: âĨ 60%
NORMAL: âĨ 70%
COMPLEX: âĨ 75%
HIGH_COMPLEX: âĨ 80%
Instantaneous Cost (per-call):
FAST: ⤠$0.002
NORMAL: ⤠$0.05
COMPLEX: ⤠$0.15
HIGH_COMPLEX: ⤠$0.85
Cumulative (monthly):
FAST: ⤠$50 (warn $40, block $50)
NORMAL: ⤠$200 (warn $160, block $200)
COMPLEX: ⤠$150 (warn $120, block $150)
HIGH_COMPLEX: ⤠$50 (warn $40, block $50)
Speed (SLA):
FAST: ⤠1s
NORMAL: ⤠5s
COMPLEX: ⤠20s
HIGH_COMPLEX: ⤠60sFile Structure â
docs/reference/
âââ INTEGRATION_INDEX.md â You are here
âââ INTEGRATION_ARCHITECTURE.md (1,482 lines, comprehensive design)
âââ INTEGRATION_QUICK_START.md (467 lines, implementation checklist)
src/thegent/
âââ routing/ [NEW MODULE]
â âââ __init__.py [+10 LOC]
â âââ models.py [+50 LOC]
â âââ task_router.py [+300 LOC]
âââ execution.py [+30 LOC] RunMeta + register_end
âââ cli_impl.py [+20 LOC] TaskRouter integration
âââ config.py [+20 LOC] Routing settings
âââ governance/cost.py [+40 LOC] Per-category tracking
âââ models/catalog.py [+50 LOC] Pareto routing (Phase 2)
tests/
âââ test_unit_routing.py [NEW, +200 LOC]
âââ test_integration_routing.py [NEW, +150 LOC]
âââ test_unit_config.py [+50 LOC]
âââ test_unit_governance.py [+80 LOC]Critical Path (Dependency Order) â
1. config.py (routing settings schema)
â
2. routing/models.py (TaskMetadata enums)
â
3. routing/task_router.py (TaskClassifier, ConstraintValidator, TaskRouter)
â
4. execution.py (RunMeta extensions)
â
5. cli_impl.py (TaskRouter integration point)
â
6. governance/cost.py (per-category tracking)
â
7. tests/* (unit + integration tests)Must Complete Before Week 2 Starts: All of Week 1 (Actions 1â18)
Common Questions â
Q: Can we start Phase 2 before Phase 1 is complete? A: No. Phase 1 (TaskRouter integration) is blocking. Phase 2 depends on task_category being available in RunMeta.
Q: What if constraint violations are too strict? A: That's expected. Phase 3 shadow run (Days 11â12) will calibrate thresholds before full enforcement (Day 13).
Q: How do we handle cost estimation errors? A: Conservative estimate (word_count_div_1.3) is built in. Shadow run will reveal if classifier needs tuning.
Q: Can we disable routing without code changes? A: Yes. Set THGENT_ROUTING_ENABLED=false. Old code that doesn't use task_category continues to work (backward compatible).
Q: What's the worst-case impact of a bug in TaskRouter? A: Tasks might be misclassified (e.g., FAST â HIGH_COMPLEX) or constraint validation might false-positive. Both caught by unit tests + shadow run.
Q: How do we monitor for production issues? A: 4 SLOs with alerts: routing latency, budget accuracy, violation rate, fallback frequency.
Communication & Escalation â
Daily Standup (Week 1â3) â
- [ ] Update checklist items (â completed, â blocked, âŗ in progress)
- [ ] Report blockers to tech lead
- [ ] Share risky spot updates
Code Review Pairing (Suggested) â
- [ ] routing/task_router.py (classifier accuracy + complexity scoring)
- [ ] cli_impl.py integration (early TaskRouter call)
- [ ] governance/cost.py (per-category tracking logic)
Metrics Review (Weekly) â
- [ ] Shadow run metrics (Days 11â12): Cost estimates within 20%?
- [ ] Phase 2 metrics (Days 6â10): Integration tests green?
- [ ] Phase 1 metrics (Days 1â5): Coverage âĨ90%?
Post-Launch (Day 15+) â
- [ ] Daily monitoring of 4 SLOs
- [ ] On-call response to alerts
- [ ] Weekly retrospective on cost reduction, incidents, improvements
References & Resources â
| Document | Purpose | Where |
|---|---|---|
| INTEGRATION_ARCHITECTURE.md | Full technical design | docs/reference/ |
| INTEGRATION_QUICK_START.md | 25-action checklist | docs/reference/ |
| src/thegent/config.py | Config schema reference | Source code |
| src/thegent/execution.py | RunMeta + RunRegistry API | Source code |
| tests/test_unit_routing.py | Unit test examples | Tests |
| tests/test_integration_routing.py | Integration test examples | Tests |
Next Actions â
Immediate (Today)
- [ ] Share this index with team
- [ ] Schedule 30-min walkthrough of INTEGRATION_ARCHITECTURE.md § 1â3
- [ ] Schedule 30-min walkthrough of INTEGRATION_QUICK_START.md
This Week 4. [ ] Assign Week 1 owner (Action 1â18) 5. [ ] Set up feature branches 6. [ ] Prepare test environment
Week 1 Kickoff 7. [ ] Begin Action #1 (routing/models.py) 8. [ ] Daily standup on progress vs. checklist 9. [ ] Pair on Action #3 (task_router.py)
Document Version: 1.0 Last Updated: 2026-02-15 Status: Ready for Implementation Contact: [Core Team]
EXTENSION_SUMMARY â
Extended on: 2026-02-17 Extended by: Claude Code
Changes Made â
- Added practical implementation patterns
- Added configuration examples
- Enhanced cross-references to related documentation
Cross-References Added â
- Related research and implementation guides
- WORK_STREAM.md for tracking
Practical Additions â
- Implementation templates
- Configuration examples
- Best practices