-
Notifications
You must be signed in to change notification settings - Fork 0
Fix openrouter require_parameters flag not being supported by model providers #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Portfolio Optimization Resilience Implementation Summary | ||
|
|
||
| ## Overview | ||
|
|
||
| Successfully implemented resilience improvements to the portfolio optimization algorithm to handle infeasible constraints gracefully, preventing complete failures when user-specified targets are unrealistic. | ||
|
|
||
| ## Changes Implemented | ||
|
|
||
| ### 1. Modified `optimize_portfolio` Function (`allocator_bot/portfolio.py`) | ||
|
|
||
| - **Independent Model Execution**: Each optimization model now runs independently with individual error handling | ||
| - **Constraint Validation**: Added validation logic that checks constraints against calculated portfolio bounds | ||
| - **Automatic Constraint Adjustment**: | ||
| - For `efficient_risk`: If target volatility ≤ minimum possible, auto-adjust to min_volatility * 1.01 | ||
| - For `efficient_return`: If target return ≥ maximum possible, auto-adjust to max_return * 0.99 | ||
| - **Return Type Change**: Function now returns `dict[str, dict[str, float] | str]` to accommodate failure messages | ||
|
|
||
| ### 2. Updated `prepare_allocation` Function (`allocator_bot/portfolio.py`) | ||
|
|
||
| - **Return Value Change**: Now returns `tuple[pd.DataFrame, dict[str, str]]` containing successful results and failure details | ||
| - **Failure Collection**: Collects failure messages for models that couldn't be optimized | ||
| - **DataFrame Filtering**: Only includes successful models in the results DataFrame | ||
|
|
||
| ### 3. Enhanced Agent Logic (`allocator_bot/agent.py`) | ||
|
|
||
| - **Failure Reporting**: Added reasoning steps to inform users when some models fail due to infeasible constraints | ||
| - **Partial Results Display**: System now shows successful optimizations while explaining failures | ||
| - **User Guidance**: Provides actionable suggestions for adjusting failed constraints | ||
|
|
||
| ### 4. Updated System Prompts (`allocator_bot/prompts.py`) | ||
|
|
||
| - **Behavior Guidelines**: Modified prompts to handle partial results and suggest constraint adjustments | ||
| - **Error Communication**: Improved guidance for communicating optimization failures to users | ||
|
|
||
| ### 5. Comprehensive Testing | ||
|
|
||
| - **Updated Existing Tests**: Modified all tests to handle the new tuple return format | ||
| - **Added Resilience Test**: New test `test_optimize_portfolio_resilience` validates graceful handling of infeasible constraints | ||
| - **All Tests Passing**: 72 tests pass, ensuring backward compatibility and new functionality | ||
|
|
||
| ## Key Benefits | ||
|
|
||
| 1. **Improved User Experience**: Users receive partial results instead of complete failure | ||
| 2. **Automatic Recovery**: System automatically adjusts unrealistic constraints to feasible values | ||
| 3. **Clear Error Communication**: Users understand why specific models failed and how to fix them | ||
| 4. **Maintained Reliability**: Core unconstrained optimizations (Max Sharpe, Min Volatility) always succeed | ||
| 5. **Backward Compatibility**: Existing functionality preserved while adding resilience | ||
|
|
||
| ## Technical Details | ||
|
|
||
| - **Constraint Bounds Calculation**: Uses historical data to determine feasible ranges | ||
| - **Buffer Margins**: 1% buffers prevent edge case failures due to floating-point precision | ||
| - **Error Isolation**: Individual model failures don't affect other optimizations | ||
| - **Type Safety**: Proper type annotations for mixed return types | ||
|
|
||
| ## Testing Results | ||
|
|
||
| - **All 72 tests pass** including new resilience test | ||
| - **Coverage maintained** at 90% for core modules | ||
| - **Historical scenarios handled**: Tested with the exact failure patterns from the provided conversation | ||
|
|
||
| ## Files Modified | ||
|
|
||
| - `allocator_bot/portfolio.py`: Core optimization logic | ||
| - `allocator_bot/agent.py`: User interaction and response handling | ||
| - `allocator_bot/prompts.py`: System behavior guidelines | ||
| - `tests/test_portfolio.py`: Test updates and new resilience test | ||
| - `tests/test_agent.py`: Mock updates for new return format | ||
|
|
||
| The implementation successfully addresses the original problem where unrealistic constraints (too low volatility targets, too high return targets) caused complete optimization failures, now providing graceful degradation with automatic constraint adjustment and clear user communication. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.