multi-agent python code

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)

0 comments No comments

Sign in to comment

2 answers

  1. Yatipa Chaleenutthawut 0 Reputation points

    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.

    0 comments No comments

    Sign in to comment
  2. AI answer

    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.
Sign in to answer

Your answer