Skip to content

Python: Add missing index in Bedrock FunctionCallContent instantiation #12203

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

Merged
merged 2 commits into from
May 23, 2025

Conversation

ja-bot
Copy link
Contributor

@ja-bot ja-bot commented May 20, 2025

Motivation and Context

The current implementation of BedrockChatCompletion does not correctly initialize FunctionCallContent instances when using the Converse Stream API, as the index is not set. As a result, when adding two consecutive FunctionCallContent instances that belong to different function calls, the __add__ method does not raise a ContentAdditionException exception, and the parameters are incorrectly merged.

Description

This PR ensures proper initialization of the index in FunctionCallContent instances by using the contentBlockIndex value returned by the Converse Stream API in both delta and start content block messages. This prevents parameters from different function calls from being merged.

See:

Closes #12202

Contribution Checklist

@ja-bot ja-bot requested a review from a team as a code owner May 20, 2025 20:42
@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label May 20, 2025
@github-actions github-actions bot changed the title Add missing index in FunctionCallContent instantiation Python: Add missing index in FunctionCallContent instantiation May 20, 2025
@moonbox3
Copy link
Contributor

@ja-bot, thanks for your contribution. Please fill out the Motivation and Context / Description sections in the PR description.

@moonbox3 moonbox3 changed the title Python: Add missing index in FunctionCallContent instantiation Python: Add missing index in Bedrock FunctionCallContent instantiation May 20, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented May 20, 2025

Python Unit Test Overview

Tests Skipped Failures Errors Time
3595 18 💤 0 ❌ 0 🔥 1m 46s ⏱️

@ja-bot
Copy link
Contributor Author

ja-bot commented May 22, 2025

@ja-bot, thanks for your contribution. Please fill out the Motivation and Context / Description sections in the PR description.

Done @moonbox3. Please, let me know if something is not clear. Thanks!

@moonbox3 moonbox3 enabled auto-merge May 23, 2025 00:51
@moonbox3 moonbox3 added this pull request to the merge queue May 23, 2025
Merged via the queue into microsoft:main with commit 3e771ec May 23, 2025
28 checks passed
@ja-bot ja-bot deleted the issue-12202 branch May 23, 2025 04:38
eavanvalkenburg pushed a commit that referenced this pull request May 26, 2025
#12203)

### Motivation and Context
The current implementation of `BedrockChatCompletion` does not correctly
initialize `FunctionCallContent` instances when using the Converse
Stream API, as the index is not set. As a result, when adding two
consecutive `FunctionCallContent` instances that belong to different
function calls, the `__add__` method does not raise a
`ContentAdditionException` exception, and the parameters are incorrectly
merged.

### Description
This PR ensures proper initialization of the index in
`FunctionCallContent` instances by using the `contentBlockIndex` value
returned by the Converse Stream API in both delta and start content
block messages. This prevents parameters from different function calls
from being merged.

See:
-
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ContentBlockDeltaEvent.html
-
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ContentBlockStartEvent.html

Closes #12202

### 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 😄

Co-authored-by: Javier Cruz <me@javiercruz.com>
Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python: Bug in multi-tool parameter parsing when using BedrockChatCompletion with the Converse Stream API
4 participants