multi-agent python code

Yatipa Chaleenutthawut 0 Reputation points
2026-06-03T09:29:47.9033333+00:00

I would like to run a multi-agent setup using a named workflow via the Python SDK. The code uses openai_client.conversations.create() and openai_client.responses.create() with streaming, and relies on ResponseStreamEventType to handle streamed events. But I got Error message:

cannot import name 'ResponseStreamEventType' from 'azure.ai.projects.models'

(d:\my_env\lib\site-packages\azure\ai\projects\models_init_.py)

Azure Language in Foundry Tools
Azure Language in Foundry Tools

An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.


3 answers

Sort by: Most helpful
  1. Karnam Venkata Rajeswari 4,265 Reputation points Microsoft External Staff Moderator
    2026-06-23T13:41:56.4466667+00:00

    Hello @Yatipa Chaleenutthawut ,

    Welcome to Microsoft Q&A .Thank you for reaching out to us.

    Thank you for sharing the implementation details and error information. After reviewing the reported behavior, two separate issues have been identified. The first relates to streaming event handling when using the Azure AI Projects OpenAI-compatible client, and the second relates to authorization requirements for Agent operations. Since these issues are independent, resolving both areas should help unblock the multi-agent workflow implementation

    1. Import Error: ResponseStreamEventType Observed Error - cannot import name 'ResponseStreamEventType' from 'azure.ai.projects.models' Analysis : The implementation is using
         openai_client.conversations.create()
         openai_client.responses.create(stream=True)
      
      through an OpenAI-compatible client obtained from:
         project_client.get_openai_client()
      
      Current Azure AI Projects SDK guidance indicates that Responses and Conversations operations are handled through this OpenAI-compatible client surface. Additionally, SDK engineering guidance indicates that classes related to OpenAI client calls are not exposed through the azure-ai-projects model package. Therefore, importing:
         from azure.ai.projects.models import ResponseStreamEventType
      
      is not a supported pattern. Please check if the following helps- Verify installed package versions:
         pip show azure-ai-projects
         pip show azure-ai-agents
         pip show openai
         pip show azure-identity
      
      1. Review the implementation against the latest SDK samples and Responses API documentation, as older samples may reference components that are no longer available.
      2. Remove the unsupported import and use the streaming events returned by the Responses API directly.
      3. Avoid importing from internal modules such as:
              azure.ai.projects._models
        
        since these are not part of the supported public SDK surface and may change between releases.
      4. If package alignment is required, update to the latest supported releases:
              pip install --upgrade azure-ai-projects azure-ai-agents openai azure-identity
        
        Please note that streaming event structures can vary depending on the installed OpenAI SDK version. The event example below should be treated as illustrative and validated against the SDK version currently installed. for event in stream:     print(event.type)
    2. Permission Error: Microsoft.MachineLearningServices/workspaces/agents/action Observed Error - Identity(object id:) does not have permissions for Microsoft.MachineLearningServices/workspaces/agents/action Analysis This error is separate from the SDK import issue. The authentication process is succeeding, but the identity executing the Agent operation does not currently have the permissions required to perform that action. Azure AI Foundry permissions are divided into two areas: Control-plane permissions Used for Azure resource management activities, including roles such as:
      • Owner
      • Contributor
      Data-plane permissions Used for:
      • Agent creation
      • Agent execution
      • Agent interaction
      • Inference operations
      Current Foundry documentation states that control-plane permissions alone do not automatically grant the data-plane permissions required for Agent operations. Appropriate Foundry roles are required for Agent-related activities. An additional consideration is the identity being used during execution. When DefaultAzureCredential() is configured, authentication may occur through:
      • Azure CLI credentials
      • Managed Identity
      • Service Principal
      • Environment credentials
      For this reason, the Object ID returned in the error should be validated before making RBAC changes

    Please check if the following steps help-

    1. Confirming the runtime identity Verify that the executing identity matches with Azure Entra ID Object ID (GUID) For Azure CLI authentication:
         az account show
      
      To validate the signed-in identity:
         az ad signed-in-user show
      
    2. Reviewing role assignments Run:
         az role assignment list \
         --assignee d32d8048-dccd-4e16-8ffb-fe14bdc4f634 \
         --all
      
      Verify that the identity has the appropriate role assignment at the relevant Foundry project or resource scope.
    3. Validating Foundry permissions Review whether an appropriate Foundry role has been assigned, such as:
      • Foundry User
      • Foundry Project Manager
      • Foundry Owner
      For custom roles, verify that the permissions include the Agent actions required by the workload. Please note that current Foundry documentation specifically notes that Azure AI Developer is not intended for Foundry Agent scenarios and should not be relied upon as the primary role for Agent operations. Instead, validate that an appropriate Foundry role is assigned
    4. Refreshing authentication After any role assignment changes:
         az logout
         az login
      
      Allow time for RBAC propagation and retry the workflow execution.

    The ResponseStreamEventType error is caused by using an unsupported import while working with the OpenAI-compatible Responses API surface. Aligning the implementation with the current SDK guidance should resolve that issue.

    Separately, the Microsoft.MachineLearningServices/workspaces/agents/action error indicates that the identity executing the Agent operation does not currently have the required data-plane permissions. Validating the runtime identity and its Foundry role assignments should help resolve the remaining authorization blocker.

    The following references might be helpful , please check them out

     

    Thank you

     

    Please "Accept" the answer with an "Upvote" if the response was helpful. This will be benefitting other community members who face the same issue.

     

     

    Was this answer helpful?

    0 comments No comments

  2. Yatipa Chaleenutthawut 0 Reputation points
    2026-06-04T10:21:04.73+00:00

    While I am foundry owner but
    I still got HttpResponseError: (UserError) Identity(object id: d32d8048-dccd-4e16-8ffb-fe14bdc4f634) does not have permissions for Microsoft.MachineLearningServices/workspaces/agents/action actions. Please refer to https://aka.ms/azureml-auth-troubleshooting to fix the permissions issue. Code: UserError Message: Identity(object id: d32d8048-dccd-4e16-8ffb-fe14bdc4f634) does not have permissions for Microsoft.MachineLearningServices/workspaces/agents/action actions.

    Was this answer helpful?

    0 comments No comments

  3. AI answer

    2026-06-03T09:29:58.9366667+00:00

    ResponseStreamEventType is not part of azure.ai.projects.models, which is why the import fails. The Python SDK surface for multi-agent and workflow scenarios in the provided context uses:

    • AIProjectClient from azure.ai.projects for multi-agent setups.
    • Streaming patterns that do not rely on ResponseStreamEventType from azure.ai.projects.models.

    To build a multi-agent setup with the current SDK surface, use the Connected Agents pattern instead of trying to import ResponseStreamEventType:

    1. Initialize the project client:
         import os
         from azure.ai.projects import AIProjectClient
         from azure.ai.agents.models import ConnectedAgentTool, MessageRole
         from azure.identity import DefaultAzureCredential
         
         project_client = AIProjectClient(
             endpoint=os.environ["PROJECT_ENDPOINT"],
             credential=DefaultAzureCredential(),
         )
      
    2. Create specialized agents and connect them via ConnectedAgentTool:
         stock_price_agent = project_client.agents.create_agent(
             model=os.environ["MODEL_DEPLOYMENT_NAME"],
             name="stock_price_bot",
             instructions=(
                 "Your job is to get the stock price of a company. "
                 "If you don't know the realtime stock price, return the last known stock price."
             ),
         )
         
         connected_agent = ConnectedAgentTool(
             id=stock_price_agent.id,
             name=stock_price_agent.name,
             description="Gets the stock price of a company",
         )
         
         main_agent = project_client.agents.create_agent(
             model=os.environ["MODEL_DEPLOYMENT_NAME"],
             name="my-agent",
             instructions="You are a helpful agent, and use the available tools to get stock prices.",
             tools=connected_agent.definitions,
         )
      
    3. Create a thread, add a message, and run the main agent. The main agent orchestrates the connected agents and aggregates their responses.

    For workflow-style multi-agent orchestration with streaming, use the Microsoft Agent Framework with FoundryChatClient, FoundryAgent, and workflow builders. Streaming is handled via AgentResponseUpdate events rather than ResponseStreamEventType:

    • Create a shared FoundryChatClient.
    • Create specialized agents.
    • Connect them in a WorkflowBuilder.
    • Run the workflow with stream=True and handle AgentResponseUpdate chunks (for example, reading update.text).

    This approach avoids importing ResponseStreamEventType entirely and uses the supported streaming and multi-agent patterns in the current SDK and Agent Framework.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.