Skip to content

Python: provide AzureAIAgent thread msg id during streaming#13032

Merged
eavanvalkenburg merged 7 commits intomicrosoft:mainfrom
moonbox3:azure-ai-thread-msg-id
Aug 30, 2025
Merged

Python: provide AzureAIAgent thread msg id during streaming#13032
eavanvalkenburg merged 7 commits intomicrosoft:mainfrom
moonbox3:azure-ai-thread-msg-id

Conversation

@moonbox3
Copy link
Copy Markdown
Collaborator

@moonbox3 moonbox3 commented Aug 29, 2025

Motivation and Context

As part of invoking an AzureAIAgent via streaming, we weren't providing the thread_id via the AgentStreamEvent.THREAD_MESSAGE_CREATED event.

Description

Supply the caller with the thread_msg_id by sticking it into the returned SCMC's metadata dictionary.

Sample output looks like:

Sample Output:

# User: 'Hello'
# AuthorRole.ASSISTANT: (thread message id: msg_HZ2h4Wzbj7GEcnVCjnyEuYWT) Hello! How can I assist you with 
    the menu today?
# User: 'What is the special soup?'
# AuthorRole.ASSISTANT: (thread message id: msg_TSjkJK6hHJojIkPvF6uUofHD) The special soup today is 
    Clam Chowder. Would you like to know more about it or anything else from the menu?
# User: 'How much does that cost?'
# AuthorRole.ASSISTANT: (thread message id: msg_liwTpBFrB9JpCM1oM9EXKiwq) The Clam Chowder costs $9.99. 
    Is there anything else you'd like to know?
# User: 'Thank you'
# AuthorRole.ASSISTANT: (thread message id: msg_K6lpR3gYIHethXq17T6gJcxi) You're welcome! 
    If you have any more questions or need assistance, feel free to ask. Enjoy your meal!

Contribution Checklist

@moonbox3 moonbox3 requested a review from a team as a code owner August 29, 2025 00:47
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label Aug 29, 2025
@moonbox3 moonbox3 self-assigned this Aug 29, 2025
@moonbox3 moonbox3 requested a review from Copilot August 29, 2025 00:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds thread message ID support to the AzureAIAgent streaming functionality. Previously, when invoking an AzureAIAgent via streaming, the thread_id was not provided in the AgentStreamEvent.THREAD_MESSAGE_CREATED event.

  • Captures thread message ID from THREAD_MESSAGE_CREATED events during streaming
  • Passes the thread message ID to the streaming message content generator
  • Includes the thread message ID in the returned StreamingChatMessageContent metadata

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
python/semantic_kernel/agents/azure_ai/agent_thread_actions.py Captures thread message ID from stream events and passes it to content generation
python/semantic_kernel/agents/azure_ai/agent_content_generation.py Updates streaming message generation to include thread message ID in metadata
python/samples/concepts/agents/azure_ai_agent/azure_ai_agent_streaming.py Demonstrates usage of thread message ID in streaming callback

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@moonbox3
Copy link
Copy Markdown
Collaborator Author

moonbox3 commented Aug 29, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
agents/azure_ai
   agent_content_generation.py32213458%79–80, 82, 100, 102, 231, 234, 274, 308, 326, 329–331, 340–342, 350, 358, 360, 368, 375, 381–383, 385, 387–389, 398–400, 409, 449, 488–489, 491–494, 497–500, 502, 504–505, 507–508, 510, 520–521, 523, 536–537, 539, 541–547, 557–559, 568, 585–586, 588, 590–597, 606, 615, 629–630, 632, 634–636, 638–642, 652–654, 663–664, 666, 692–699, 705–708, 713, 718–719, 726, 818, 824, 843–845, 855, 875–878, 889, 914–915, 917, 919–924, 929, 931
   agent_thread_actions.py42720352%164, 166, 203–209, 245–246, 249–253, 255–257, 261, 264–266, 275, 280–281, 343, 347, 352, 355, 358–359, 363, 366, 369–370, 374, 377, 380–381, 385–386, 390–391, 395–396, 496, 498, 538–539, 562, 564–566, 568–570, 572, 574–576, 578–579, 581–586, 588–596, 600–601, 604–607, 611, 614–615, 618–619, 622, 625, 628–629, 632–638, 640–641, 645, 648–649, 656–657, 662, 666–669, 671–672, 679, 681, 685, 688–693, 695–697, 702–703, 706–709, 712–714, 724–725, 732, 734, 738, 740–741, 745–754, 756–764, 815, 818, 852–853, 860–864, 924, 929–934, 962–965, 969, 974–975, 979, 996–998, 1002–1003, 1018–1019, 1057, 1098–1101, 1103–1104, 1108, 1112–1113, 1118
TOTAL27065468982% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3715 22 💤 0 ❌ 0 🔥 1m 37s ⏱️

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Aug 30, 2025
Merged via the queue into microsoft:main with commit 86b10b9 Aug 30, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: How can I grab the message id of AzureAIAgent assistant responses?

4 participants