Large API Response Handling Enhancement
Version Implemented: 0.229.001
Issue Summary
WorldNewsAPI and other APIs were returning very large responses (960k+ characters) that were being truncated to 50k characters, resulting in loss of useful data and poor user experience.
Root Cause Analysis
The large response was coming from the external API service (WorldNewsAPI), not our agent:
- API response: 961,677 characters (~1MB)
- System limit: 50,000 characters
- Result: Aggressive truncation losing valuable news data
Solution Implemented
Enhanced the OpenAPI plugin with smart response truncation for news APIs:
🎯 Smart News API Handling:
- Detects news API responses by looking for common keys:
articles,news,results,data,items,stories,headlines - Preserves more items (10 instead of 5) for news content
- Truncates article content instead of removing entire articles
- Maintains article metadata (title, URL, author, date) while shortening content/description
🔧 Enhanced Truncation Logic:
# Before: Lost entire articles
result = result[:5] # Only 5 items
# After: Keep more articles, truncate content
for item in result[key][:10]: # 10 items
if item['content'] > 500 chars:
item['content'] = item['content'][:500] + "... [truncated]"
📊 Improvements:
- More Articles: Shows 10 articles instead of 5
- Better Content: Preserves titles, URLs, metadata
- Smart Truncation: Shortens content but keeps article structure
- Clear Indicators: Shows truncation status and original counts
- Helpful Guidance: Suggests API parameters for better filtering
Files Modified
semantic_kernel_plugins/openapi_plugin.py- Enhanced response handlingconfig.py- Version bump to 0.226.088
Testing Recommendations
- Test with WorldNewsAPI - Should now show more articles with summarized content
- Test with other news APIs - Enhanced handling should work for similar APIs
- Monitor response sizes - Check that truncation still prevents context overflow
Benefits
✅ Better User Experience - More useful news content returned
✅ Preserved Context - Article titles and metadata maintained
✅ Performance Protection - Still prevents context overflow
✅ Future-Proof - Handles other news APIs with similar patterns
Version
Enhanced in version 0.226.088