mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Refactor middleware layering and split Anthropic raw client (#4746)
* [BREAKING] Refactor middleware layering and raw clients Reorder chat client layers so function invocation wraps chat middleware, and chat middleware stays outside telemetry while still running for each inner model call. Add middleware pipeline caching, refresh docs and samples, and split Anthropic into raw and public clients to match the standard layering model. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Tighten typing ignores in ancillary modules Add targeted typing ignores in workflow visualization and lab modules so pyright stays clean alongside the middleware refactor work. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix categorize_middleware to unpack tuple/Sequence and use relative MRO assertions - Broaden isinstance check in categorize_middleware from list to Sequence so tuples and other Sequence types are properly unpacked instead of being appended as a single item. - Replace fragile hardcoded MRO index assertions in anthropic test with relative ordering via mro.index(). - Add regression tests for categorize_middleware with tuple, list, and None inputs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix middleware string decomposition, add middleware param to FunctionInvocationLayer, and add tests (#4710) - Guard categorize_middleware Sequence check against str/bytes to prevent character-by-character decomposition of accidentally passed strings - Add explicit middleware parameter to FunctionInvocationLayer.get_response and merge it into client_kwargs before categorization, fixing the inconsistency where only OpenAIChatClient supported this parameter - Add assertions that RawAnthropicClient does not inherit convenience layers - Add chat middleware cache test with non-empty base middleware - Add tests for single unwrapped middleware item and string input Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Apply pre-commit auto-fixes * Apply pre-commit auto-fixes * Address review feedback for #4710: review comment fixes --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
cefda44283
commit
0cd40f8354
@@ -114,10 +114,11 @@ class RetryingAzureOpenAIChatClient(AzureOpenAIChatClient):
|
||||
|
||||
|
||||
class RateLimitRetryMiddleware(ChatMiddleware):
|
||||
"""Chat middleware that retries the full request pipeline on rate limit errors.
|
||||
"""Chat middleware that retries a single model-call pipeline on rate limit errors.
|
||||
|
||||
Register this middleware on an agent (or at the run level) to automatically
|
||||
retry any call_next() invocation that raises RateLimitError.
|
||||
retry any chat-model call that raises RateLimitError. In tool-loop scenarios,
|
||||
the middleware applies independently to each inner model call.
|
||||
"""
|
||||
|
||||
def __init__(self, *, max_attempts: int = RETRY_ATTEMPTS) -> None:
|
||||
@@ -154,8 +155,9 @@ async def rate_limit_retry_middleware(
|
||||
"""Function-based chat middleware that retries on rate limit errors.
|
||||
|
||||
Wrap call_next() with a tenacity @retry decorator so any RateLimitError
|
||||
raised during model inference triggers an automatic retry with exponential
|
||||
back-off.
|
||||
raised during a single model call triggers an automatic retry with exponential
|
||||
back-off. In tool-loop scenarios, the middleware applies independently to
|
||||
each inner model call.
|
||||
"""
|
||||
|
||||
@retry(
|
||||
|
||||
Reference in New Issue
Block a user