Add SemanticKernel rate limit middleware#180
Merged
dianadiazbisbe merged 4 commits intomainfrom Nov 19, 2025
Merged
Conversation
Introduces SemanticKernelRateLimitMiddleware to handle 429 rate limit exceptions from Semantic Kernel and return appropriate HTTP responses. Also updates LogAIRequestScopeMiddleware to public and adds Microsoft.SemanticKernel package reference. Version suffix updated to preview-09.
MarioEncamina
previously approved these changes
Nov 19, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds rate limit handling for Semantic Kernel operations by introducing a new SemanticKernelRateLimitMiddleware that intercepts HTTP 429 (Too Many Requests) exceptions. It also makes the LogAIRequestScopeMiddleware public for external usage, adds the Microsoft.SemanticKernel package dependency, and updates the version suffix to preview-09.
Key changes:
- New middleware to handle rate limiting from Semantic Kernel APIs with retry-after header support
- Changed
LogAIRequestScopeMiddlewarevisibility from internal to public - Added Microsoft.SemanticKernel 1.64.0 package reference
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Encamina.Enmarcha.Agents/Middlewares/SemanticKernelRateLimitMiddleware.cs | New ASP.NET Core middleware that catches HttpOperationException with 429 status codes from Semantic Kernel and returns appropriate HTTP responses with retry-after headers |
| src/Encamina.Enmarcha.Agents/Middlewares/LogAIRequestScopeMiddleware.cs | Changed class visibility from internal to public for external consumption |
| src/Encamina.Enmarcha.Agents/Encamina.Enmarcha.Agents.csproj | Added Microsoft.SemanticKernel package reference (version 1.64.0) to support the new middleware |
| Directory.Build.props | Updated version suffix from preview-08 to preview-09 for the next release |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Encamina.Enmarcha.Agents/Middlewares/SemanticKernelRateLimitMiddleware.cs
Show resolved
Hide resolved
src/Encamina.Enmarcha.Agents/Middlewares/SemanticKernelRateLimitMiddleware.cs
Outdated
Show resolved
Hide resolved
src/Encamina.Enmarcha.Agents/Middlewares/SemanticKernelRateLimitMiddleware.cs
Outdated
Show resolved
Hide resolved
…itMiddleware.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Updated SemanticKernelRateLimitMiddleware to serialize error messages as JSON when handling 429 exceptions, improving API consistency and client error handling.
rliberoff
requested changes
Nov 19, 2025
src/Encamina.Enmarcha.Agents/Middlewares/SemanticKernelRateLimitMiddleware.cs
Outdated
Show resolved
Hide resolved
src/Encamina.Enmarcha.Agents/Middlewares/SemanticKernelRateLimitMiddleware.cs
Show resolved
Hide resolved
MarioEncamina
approved these changes
Nov 19, 2025
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.
Description
Introduces SemanticKernelRateLimitMiddleware . Also updates LogAIRequestScopeMiddleware to public and adds Microsoft.SemanticKernel package reference. Version suffix updated to preview-09.
Motivation and Context
Migrating a new middleware to handle 429 rate limit exceptions from Semantic Kernel and return appropriate HTTP responses, and necessary packages.
Type of change
Please check only those options that are relevant with a (✅).
Checklist
Please check all options from this checklist when validating your pull request with a (✅).