Skip to content

Comments

Add SemanticKernel rate limit middleware#180

Merged
dianadiazbisbe merged 4 commits intomainfrom
@ddiaz/migrating-middlewares
Nov 19, 2025
Merged

Add SemanticKernel rate limit middleware#180
dianadiazbisbe merged 4 commits intomainfrom
@ddiaz/migrating-middlewares

Conversation

@dianadiazbisbe
Copy link
Contributor

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 (✅).

  • [✅] The code builds clean without any errors or warnings
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

Please check all options from this checklist when validating your pull request with a (✅).

  • [✅] My code follows the style guidelines of this project
  • [✅] I have performed a self-review of my own code
  • [✅] I have commented my code, particularly in hard-to-understand areas
  • [✅] I have made corresponding changes to the documentation
  • [✅] My changes generate no new warnings
  • [✅] Any dependent changes have been merged and published in downstream modules
  • [✅] I didn't break anyone 😄

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
MarioEncamina previously approved these changes Nov 19, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LogAIRequestScopeMiddleware visibility 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.

…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.
Copy link
Member

@rliberoff rliberoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dianadiazbisbe dianadiazbisbe merged commit 37ee1c9 into main Nov 19, 2025
2 checks passed
@dianadiazbisbe dianadiazbisbe deleted the @ddiaz/migrating-middlewares branch November 19, 2025 11:25
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.

3 participants