Files
semantic-kernel/python/semantic_kernel/utils/async_utils.py
T
Tao Chen 75453a1219 Python: Move to a thinner wrap for Bedrock Agent in Python (#10740)
### 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.
-->
Though the current Bedrock agent implementation uses a "thin wrap"
approach, it still has some abstractions that we don't want to maintain.
Just like what we have done for the other agents, we remove those
abstractions.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
1. Update the Bedrock agent abstraction to be thinner.
2. Update samples and tests.

Note: The .Net implementation doesn't need to be updated as it was
already using a thinner wrap.
Note: This breaks the current usage pattern for Bedrock agents in
Python.

### 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
- [ ] I didn't break anyone 😄
2025-03-03 22:07:41 +00:00

12 lines
379 B
Python

# Copyright (c) Microsoft. All rights reserved.
import asyncio
from collections.abc import Callable
from functools import partial
from typing import Any
async def run_in_executor(executor: Any, func: Callable, *args, **kwargs) -> Any:
"""Run a function in an executor."""
return await asyncio.get_event_loop().run_in_executor(executor, partial(func, *args, **kwargs))