Files
semantic-kernel/python/samples
Evan Mattson 9e3cdffc6b Python: Improve AzureAIAgent get thread msg handling. (#12535)
### 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!
```

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

- Closes #12435

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### 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 😄
2025-06-19 23:52:07 +00:00
..

Semantic Kernel Samples

Type Description
getting_started Take this step by step tutorial to get started with Semantic Kernel and get introduced to the key concepts.
getting_started_with_agents Take this step by step tutorial to get started with Semantic Kernel Agents and get introduced to the key concepts.
getting_started_with_processes Take this step by step tutorial to get started with Semantic Kernel Processes and get introduced to the key concepts.
concepts This section contains focused samples which illustrate all of the concepts included in Semantic Kernel.
demos Look here to find a sample which demonstrate how to use many of Semantic Kernel features.
learn_resources Code snippets that are related to online documentation sources like Microsoft Learn, DevBlogs and others