Skip to content

sprint3 - #4

Merged
AlgoriThai07 merged 10 commits into
mainfrom
sprint3
Aug 10, 2026
Merged

AlgoriThai07 merged 10 commits into
mainfrom
sprint3

Conversation

@AlgoriThai07

Copy link
Copy Markdown
Owner

Description

Implements Sprint 3 changes for transfer recommendation explanations and economics.

Key Changes

  • AI Explanation Agent: Generates structured, grounded transfer explanations using the Gemini SDK (gemini-3.5-flash) with recursive number validation.
  • API Schema Updates: Extended response model to include prose explanation, ree_transfers_banked, and the short/long-term/hit cost breakdown.
  • Next.js UI Panel: Added a detailed AI Explanation panel on the recommendations page displaying the prose rationale, stats cards, and a warning banner when short/long-term signs diverge.

Verification

  • Backend tests pass: pytest tests/unit/test_recommendations_api.py tests/unit/test_explain.py
  • Frontend builds successfully:
    pm run build

Ties Task 3.2 (free_transfers_banked) and Task 3.4 (confidence decay)
into transfer recommendations: objective now maximizes short-term
(gw+1..+3) + long-term (gw+4..+8) confidence-weighted gain minus
hit cost, linearized via a slack variable so the solver never pads
hits beyond the minimum feasible value.

short_term_gain, long_term_gain, and hit_cost are returned as
separate fields, never blended, so the Task 3.6 explanation layer
can describe divergent short vs. long-term rationale.

BREAKING CHANGE: optimize_transfers() signature changed —
xp_map replaced by predictions (per-gw point_estimate/confidence),
plus new current_gameweek and free_transfers_banked params.
recommendations.py patched with a stopgap that spreads its existing
single-gw xp_map across the full horizon at confidence 1.0; real
multi-gw wiring is Task 3.7.
…(Task 3.6)

- Implemented explanation generation directly using the google-genai SDK
  with gemini-3.5-flash and structured outputs (Pydantic model validation).
- Created backend/agent/explain.py containing explanation generation, DB
  persistence, and recursive groundedness validation logic checking prose
  numbers against source payload values.
- Updated RecommendedTransfer schema and backend/api/recommendations.py to
  populate and store short_term_gain, long_term_gain, hit_cost, and
  multi-week predictions in recommendation payload_json.
- Added tests/unit/test_explain.py covering mock Gemini SDK responses, success
  persistence flow, and groundedness check pass/fail assertions.
- Added scratch_manual_test_explain.py for easy manual end-to-end live testing.
@AlgoriThai07
AlgoriThai07 merged commit 2379181 into main Aug 10, 2026
5 checks passed
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