Files
semantic-kernel/python/tests
Evan Mattson b07454aff8 Python: Fix OpenAIAssistantAgent/OpenAIResponsesAgent intermediate message ordering for invoke and invoke_stream (#12008)
### 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 😄
2025-05-12 22:45:43 +00:00
..
2023-04-13 16:12:36 -07:00