mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 11:19:56 +00:00
### Motivation and Context This PR fixes a core issue in `OpenAIAssistantAgent` and `OpenAIResponsesAgent` where `FunctionCallContent` and `FunctionResultContent` messages were not being emitted in the correct order during `invoke()` and `invoke_stream()` execution. - `invoke_stream`: tool messages are now drained and emitted after each streamed assistant chunk, preserving causal ordering (tool call -> result -> assistant reply). - `invoke`: tool messages are emitted via callback immediately after the non-streaming response is received, ensuring they precede the final assistant message if applicable. ### Description Updated samples to better show how the callbacks are used to receive the intermediate messages in the proper order. - Added unit tests to ensure proper coverage and message ordering. - Closes #12007 ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄