Skip to content

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

@moonbox3

Description

@moonbox3

Discussed in #12909

Originally posted by mollaosmanoglu August 11, 2025
I’m using Semantic Kernel (Python) with Azure AI Agents and running into a frustrating limitation.

In my app, I stream responses from the agent and extract citations from StreamingAnnotationContent chunks. The idea is to pair those citations with the exact assistant message they came from so my frontend can contain the citations in the user/assistant pair, which means I need the assistant message’s service id.

The problem is: SK doesn’t expose the Azure message id on the streamed message objects, only the thread_id. For the user message it’s fine, I create it manually via client.agents.messages.create(...) and get its id right away. But for the assistant message, SK starts streaming without giving me its id.

The only workaround I’ve found is to, right after the first streamed delta, poll client.agents.messages.list(thread_id, order="desc", limit=1) to grab the latest assistant message’s id and then attach citations to it.

So the question is: is there any way in SK to get the assistant message id immediately when streaming starts? Or do I have to either keep polling or ditch SK and consume the Azure AI Agents stream directly since it provides a thread.message.created event which includes the message id?

Metadata

Metadata

Assignees

Labels

agentslanguage:pythonpythonPull requests for the Python Semantic KernelquestionFurther information is requested

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions