Repository navigation
Python: New Feature: Cannot Retrieve MCP Call Results via Streaming in Azure OpenAI Responses API #13085
Copy link
Copy link
Closed
Closed
Python: New Feature: Cannot Retrieve MCP Call Results via Streaming in Azure OpenAI Responses API#13085
Feature
Copy link
Labels
mcppythonPull requests for the Python Semantic KernelPull requests for the Python Semantic KernelstaleIssue is stale because it has been open for a while and has no activityIssue is stale because it has been open for a while and has no activity
Description
Description
When running the following code, I tried to capture MCP arguments and results from the streaming chunks. However, I noticed that the corresponding events are not detected.
import asyncio
import os
from dotenv import load_dotenv
from openai import AsyncAzureOpenAI
from semantic_kernel.agents import AzureResponsesAgent
from semantic_kernel.contents import ChatMessageContent
load_dotenv()
AZURE_OPENAI_RESPONSES_MODEL_ID: str = os.getenv("AZURE_OPENAI_RESPONSES_MODEL_ID", "")
client: AsyncAzureOpenAI = AzureResponsesAgent.create_client(deployment_name=AZURE_OPENAI_RESPONSES_MODEL_ID)
async def handle_intermediate_message(message: ChatMessageContent):
for item in message.items:
print(">> item", item)
async def main():
agent = AzureResponsesAgent(
ai_model_id=AZURE_OPENAI_RESPONSES_MODEL_ID,
client=client,
name="Agent",
tools=[
{
"type": "mcp",
"server_label": "microsoft-document",
"server_url": "https://learn.microsoft.com/api/mcp",
"require_approval": "never",
}
],
)
thread = None
for _ in range(10):
user_prompt = input("Enter your prompt: ")
if not user_prompt:
user_prompt = "microsoft-document: what is azure ai agent"
print("reasoning start: ", user_prompt)
async for r in agent.invoke_stream(
messages=user_prompt,
thread=thread,
on_intermediate_message=handle_intermediate_message,
):
print(r, end="", flush=True)
thread = r.thread
print("")
if __name__ == "__main__":
asyncio.run(main())Investigation
Looking into the source, I noticed that the following events are not defined in the current implementation:
semantic-kernel/python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py
Lines 405 to 539 in 0ec81c8
| match event: | |
| case ResponseCreatedEvent(): | |
| if store_enabled: | |
| thread.response_id = event.response.id | |
| # Ensure subsequent requests link to this response context | |
| previous_response_id = event.response.id | |
| case ResponseOutputItemAddedEvent(): | |
| function_calls = cls._get_tool_calls_from_output([event.item]) # type: ignore | |
| if function_calls: | |
| function_call_returned = True | |
| msg = cls._build_streaming_msg( | |
| agent=agent, | |
| metadata=metadata, | |
| event=event, | |
| items=function_calls, | |
| choice_index=request_index, | |
| ) | |
| all_messages.append(msg) | |
| case ResponseFunctionCallArgumentsDeltaEvent(): | |
| function_call = FunctionCallContent( | |
| id=event.item_id, | |
| index=getattr(event, "index", None), | |
| arguments=event.delta, | |
| ) | |
| msg = cls._build_streaming_msg( | |
| agent=agent, | |
| metadata=metadata, | |
| event=event, | |
| items=[function_call], | |
| choice_index=request_index, | |
| ) | |
| all_messages.append(msg) | |
| case ResponseTextDeltaEvent(): | |
| text_content = StreamingTextContent( | |
| text=event.delta, | |
| choice_index=request_index, | |
| ) | |
| msg = cls._build_streaming_msg( | |
| agent=agent, | |
| metadata=metadata, | |
| event=event, | |
| items=[text_content], | |
| choice_index=request_index, | |
| ) | |
| yield msg | |
| case ResponseReasoningTextDeltaEvent(): | |
| if on_intermediate_message: | |
| reasoning_content = StreamingReasoningContent( | |
| text=event.delta, | |
| choice_index=request_index, | |
| metadata={ | |
| "item_id": event.item_id, | |
| "output_index": event.output_index, | |
| "sequence_number": event.sequence_number, | |
| "content_index": event.content_index, | |
| }, | |
| ) | |
| reasoning_msg = cls._build_streaming_msg( | |
| agent=agent, | |
| metadata=metadata, | |
| event=event, | |
| items=[reasoning_content], | |
| choice_index=request_index, | |
| ) | |
| await on_intermediate_message(reasoning_msg) | |
| case ResponseReasoningTextDoneEvent(): | |
| if on_intermediate_message: | |
| final_reasoning_content = ReasoningContent( | |
| text=event.text, | |
| metadata={ | |
| "item_id": event.item_id, | |
| "output_index": event.output_index, | |
| "sequence_number": event.sequence_number, | |
| "content_index": event.content_index, | |
| }, | |
| ) | |
| reasoning_msg = cls._build_streaming_msg( | |
| agent=agent, | |
| metadata=metadata, | |
| event=event, | |
| items=[final_reasoning_content], | |
| choice_index=request_index, | |
| ) | |
| await on_intermediate_message(reasoning_msg) | |
| case ResponseReasoningSummaryTextDeltaEvent(): | |
| if on_intermediate_message: | |
| reasoning_content = StreamingReasoningContent( | |
| text=event.delta, | |
| choice_index=request_index, | |
| metadata={ | |
| "item_id": event.item_id, | |
| "output_index": event.output_index, | |
| "sequence_number": event.sequence_number, | |
| "summary_index": event.summary_index, | |
| "is_summary": True, | |
| }, | |
| ) | |
| reasoning_msg = cls._build_streaming_msg( | |
| agent=agent, | |
| metadata=metadata, | |
| event=event, | |
| items=[reasoning_content], | |
| choice_index=request_index, | |
| ) | |
| await on_intermediate_message(reasoning_msg) | |
| case ResponseReasoningSummaryTextDoneEvent(): | |
| if on_intermediate_message: | |
| final_reasoning_summary_content = ReasoningContent( | |
| text=event.text, | |
| metadata={ | |
| "item_id": event.item_id, | |
| "output_index": event.output_index, | |
| "sequence_number": event.sequence_number, | |
| "summary_index": event.summary_index, | |
| "is_summary": True, | |
| }, | |
| ) | |
| reasoning_msg = cls._build_streaming_msg( | |
| agent=agent, | |
| metadata=metadata, | |
| event=event, | |
| items=[final_reasoning_summary_content], | |
| choice_index=request_index, | |
| ) | |
| await on_intermediate_message(reasoning_msg) | |
| case ResponseOutputItemDoneEvent(): | |
| msg = cls._create_output_item_done(agent, event.item) # type: ignore | |
| if output_messages is not None: | |
| output_messages.append(msg) | |
| case ResponseErrorEvent(): | |
| logger.error( | |
| f"Error in agent invoke_stream: {event.message} " | |
| f"(code: {event.code if event.code else 'unknown'})" | |
| ) | |
| break |
- ResponseInProgressEvent
- ResponseMcpListToolsInProgressEvent
- ResponseMcpListToolsCompletedEvent
- ResponseMcpCallInProgressEvent
- ResponseMcpCallArgumentsDeltaEvent
- ResponseMcpCallArgumentsDoneEvent
- ResponseMcpCallCompletedEvent
- ResponseContentPartAddedEvent
- ResponseTextDoneEvent
- ResponseContentPartDoneEvent
- ResponseCompletedEvent
Question
Would it be possible to add detection support for these events as well?
Info
- python
- azure openai responses api
Metadata
Metadata
Labels
mcppythonPull requests for the Python Semantic KernelPull requests for the Python Semantic KernelstaleIssue is stale because it has been open for a while and has no activityIssue is stale because it has been open for a while and has no activity
Type
Projects
- StatusShow more project fieldsNo status
Activity
[-]New Feature: Cannot Retrieve MCP Call Results via Streaming in Azure OpenAI Responses API[/-][+]Python: New Feature: Cannot Retrieve MCP Call Results via Streaming in Azure OpenAI Responses API[/+]yuichiromukaiyama commentedon Sep 8, 2025
semantic-kernel/python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py
Line 402 in 0ec81c8
Log of the "event" variable when no events are filtered
moonbox3 commentedon Sep 9, 2025
Hi ふぁー (@ymuichiro), this is simply a gap in implementation. We don't have MCP tool support with the responses agent. Do you want to open a PR to fix this?
ymuichiro commentedon Sep 9, 2025
Evan Mattson (@moonbox3)
I've created a draft of the changes now. After some testing, I'll create a pull request.
ymuichiro@1a23568
ymuichiro commentedon Sep 12, 2025
Evan Mattson (@moonbox3) I have created a pr for this issue.
#13112
github-actions commentedon Dec 12, 2025
This issue is stale because it has been open for 90 days with no activity.
github-actions commentedon Dec 26, 2025
This issue was closed because it has been inactive for 14 days since being marked as stale.