feat: agent orchestration pipeline with guaranteed 3-card fallback (Phase 4)#33
Merged
Merged
Conversation
- Add src/lpi/agent_pipeline.py: 7-node LangGraph orchestration pipeline
(fetch -> classify -> reason -> validate -> enrich -> fallback -> finalise)
run_pipeline() never raises, always returns exactly n_cards recommendations
- Add POST /api/v1/recommendations/{user_id}/run endpoint (demo-safe,
guaranteed 3 cards regardless of LLM or DB availability)
- Fix HTTP_422_UNPROCESSABLE_CONTENT -> HTTP_422_UNPROCESSABLE_ENTITY
in routers/goals.py (wrong Starlette constant, caused 500 on invalid
SMILE phase transition)
- Fix tests/conftest.py: clear rate limit store between tests to prevent
429s mid-suite when running all 164 tests against cloud Supabase
All 164 tests passing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I Verified
✅ Introduces a dedicated
agent_pipeline.pyimplementing a clear 7-node LangGraph orchestration workflow (fetch → classify → reason → validate → enrich → fallback → finalise).✅ Maintains proper separation of concerns by reusing the existing reasoning components (
run_agent()andrecommendation_engine.py) without modifying their internal implementation.✅ The multi-layer fallback strategy is well designed:
This ensures the demo-safe requirement of always returning exactly
n_cardsrecommendations is satisfied even during database or LLM failures.✅ New endpoint
POST /api/v1/recommendations/{user_id}/runis additive and does not introduce regression risk to the existing GET endpoint.Additional Fixes
The fixes in:
routers/goals.pytests/conftest.pyappear justified and resolve pre-existing issues uncovered once the full test suite executed against a live Supabase environment.
Testing
Test progression demonstrates good validation of the implementation:
This provides strong confidence in the stability of the orchestration pipeline and related fixes.
Architecture Assessment
The producer-consumer relationship between the orchestration layer and the reasoning layer is clean:
agent_pipeline.py → run_agent() / recommendation_engine.pyThis avoids overlap with parallel Phase 4 work while preserving modularity and future extensibility.