Skip to content

Python: Improve AzureAIAgent get thread msg handling. #12535

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 3 commits into from
Jun 19, 2025

Conversation

moonbox3
Copy link
Contributor

Motivation and Context

Currently, when fetching thread messages for an AzureAIAgent, it assumes that the agent exists, so we can pull it down and get its id. This may not always be the case - an agent could have been deleted, but the thread still exists. We need to account for this.

When creating user messages that we add to the thread, there's no name or id parameter allowed. We can, however, add metadata to the message. Going forward we are adding the agent_id as metadata to the message, so upon retrieval later, we can attempt to get it and return the id with the user's message. This allows one to see which agent_id has responded to the user's message:

# Messages in the thread (asc order):

# AuthorRole.USER for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: Hello
# AuthorRole.ASSISTANT for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: Hello! How can I assist you with the menu today?
# AuthorRole.USER for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: What is the special soup?
# AuthorRole.ASSISTANT for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: The special soup today is Clam Chowder. Would you like to know more about it or anything else on the menu?
# AuthorRole.USER for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: How much does that cost?
# AuthorRole.ASSISTANT for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: The Clam Chowder costs $9.99. Would you like to order it or need information on other items?
# AuthorRole.USER for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: Thank you
# AuthorRole.ASSISTANT for name=asst_mXwZOwyJLxXGtaYKHizRH6Ip: You're welcome! If you have any more questions or need assistance with the menu, feel free to ask. Enjoy your meal!

Description

Contribution Checklist

@moonbox3 moonbox3 self-assigned this Jun 19, 2025
@moonbox3 moonbox3 requested a review from a team as a code owner June 19, 2025 07:21
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel documentation labels Jun 19, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Jun 19, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
agents
   agent.py3384985%122, 129, 142–143, 146–148, 151–153, 204, 209, 214, 219, 224, 228, 232, 236, 277–279, 307–308, 310, 314, 434, 436, 501, 515, 578, 580, 605, 619, 632, 684, 691–692, 695–696, 715, 762, 819, 904–905, 907–908, 962, 1023, 1038
agents/azure_ai
   agent_thread_actions.py36214061%154, 156, 193–196, 288, 292, 296, 299, 302–303, 307, 310, 313–314, 318, 321, 324–325, 329–330, 430, 432, 472–473, 495, 497–499, 501–503, 505–506, 508–513, 515–523, 527–528, 531–534, 538, 541–542, 545–546, 549, 552, 555–559, 561–562, 566–567, 574–575, 580, 584–585, 587–588, 595, 597, 601, 603–604, 608–617, 619–621, 624, 674, 677, 711–712, 719–723, 783, 788–793, 821–824, 828, 833–834, 838, 855–857, 861–862, 877–878, 916, 957–960, 962–963, 967, 971–972, 977
TOTAL26417450482% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3638 22 💤 0 ❌ 0 🔥 1m 54s ⏱️

@moonbox3 moonbox3 added this pull request to the merge queue Jun 19, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 19, 2025
@moonbox3 moonbox3 added this pull request to the merge queue Jun 19, 2025
Merged via the queue into microsoft:main with commit 9e3cdff Jun 19, 2025
28 checks passed
@moonbox3 moonbox3 deleted the azure-ai-agent-get-msgs branch June 19, 2025 23:59
@github-project-automation github-project-automation bot moved this to Sprint: Done in Semantic Kernel Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agents documentation python Pull requests for the Python Semantic Kernel
Projects
Status: Sprint: Done
Development

Successfully merging this pull request may close these issues.

Python: Bug: AgentThreadActions get_messages
4 participants