Skip to content
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

Python: Bug: retry_machanism is not used #9015

Closed
CBumann opened this issue Sep 27, 2024 · 3 comments · Fixed by #9965
Closed

Python: Bug: retry_machanism is not used #9015

CBumann opened this issue Sep 27, 2024 · 3 comments · Fixed by #9965
Assignees
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel

Comments

@CBumann
Copy link

CBumann commented Sep 27, 2024

Describe the bug
The Kernel class has a property retry_mechnism.
image

This is intended to be set to a Implementation of RetryMechanismBase from the semantic_kernel.reliability extension to handle the retry logic.
However this property seems to never be used, leaving us unable to handle retries in the intended way.
This was tested both with the kernel.invoke functions as well as with get_chat_message_content.

To Reproduce

  1. Create Implementation of RetryMechanismBase
  2. Initialize in Kernel
  3. Run Chat Completion or function invoke
    Code Sample to reproduce:
from semantic_kernel import Kernel
from semantic_kernel.reliability.retry_mechanism_base import RetryMechanismBase
from typing import Awaitable, Callable, TypeVar
from semantic_kernel.connectors.ai.open_ai import (
    AzureChatCompletion,
)
from semantic_kernel.contents.chat_history import ChatHistory
from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings
import pytest

T = TypeVar("T")

azure_openai_endpoint = "your-endpoint"
azure_openai_key = "your-key"
azure_openai_model = "gpt-4o"

class FailingRetryMechanism(RetryMechanismBase):
    async def execute_with_retry(self, action: Callable[[], Awaitable[T]]) -> T:
        raise NotImplementedError

kernel = Kernel(retry_mechanism=FailingRetryMechanism())
kernel.add_service(
            AzureChatCompletion(
                deployment_name=azure_openai_model,
                endpoint=azure_openai_endpoint,
                service_id=azure_openai_model,
                api_key=azure_openai_key,
            ),
        )

chat_completion_service = kernel.get_service(service_id=azure_openai_model)

chat_history = ChatHistory()
chat_history.add_user_message("Hello, how are you?")

with pytest.raises(NotImplementedError):
    response = await chat_completion_service.get_chat_message_content(
        chat_history=chat_history,
        settings = PromptExecutionSettings(),
    )

The test above fails, because FailingRetryMechanism is never used.

Expected behavior
The provided retry mechanism should be used..

Platform

  • OS: Windows, Mac
  • IDE: VS Code
  • Language: Python
  • Source:package version 1.9.0
@CBumann CBumann added the bug Something isn't working label Sep 27, 2024
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel triage labels Sep 27, 2024
@moonbox3 moonbox3 removed the triage label Sep 30, 2024
@moonbox3
Copy link
Contributor

@TaoChenOSU could you have a look at this, please?

@CBumann
Copy link
Author

CBumann commented Oct 25, 2024

Is there anything I can clarify or adjust to support you better here?

@TaoChenOSU TaoChenOSU moved this to Sprint: In Progress in Semantic Kernel Dec 10, 2024
@TaoChenOSU TaoChenOSU linked a pull request Dec 13, 2024 that will close this issue
4 tasks
github-merge-queue bot pushed a commit that referenced this issue Dec 13, 2024
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
In Python, we have the `retry_mechanism` property in the kernel but it's
never used.

Address: #9015

### Description
1. Deprecate the retry_mechanism field.
2. Add a sample showing how to perform retries with the kernel using
filter.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
@TaoChenOSU
Copy link
Contributor

Hi @CBumann, the retry_mechanism was a feature that was never implemented when we were trying to reach parity with Semantic Kernel .Net. Currently the .Net SDK no longer supports this out-of-the-box retry policy, we decided to deprecate it in Semantic Kernel Python.

The recommended way to perform retry on a kernel function is now through filters. You can refer to this new sample here: https://github.com/microsoft/semantic-kernel/blob/main/python/samples/concepts/filtering/retry_with_filters.py

Please let us know if using a filter is enough for your scenario and what additional features you'd like to see in SK!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants