Azure / Azure/azure-sdk-for-python
azure-ai-agents connected agent with MCP will raise for approval and eventually crash
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
- **Package Name**: azure-ai-agents
- **Package Version**: 1.2.0b2
- **Operating System**: Windows/Linux
- **Python Version**: 3.11.13
**Describe the bug**
Configuration requires the following:
1. one "coordinator" agent that includes MCP tool and a connected agent
2. one connected agent that includes a different MCP tool
models tested: gpt-4o, gpt-4.1 and o3-mini
When this is invoked, MCP tools one the main agent will run, as soon as the connected agent is invoked the stream gets stuck at ThreadRun status: RunStatus.IN_PROGRESS eventually an error is returned "Error processing messages: Response ended prematurely"
**To Reproduce**
Steps to reproduce the behavior:
1. Create the two agents required above and run them, streaming or via the run_and_process call
```python
mcp_tool_1 = McpTool(
server_label=mcp_server_label,
server_url=mcp_server_url,
allowed_tools=[ "someTool"]
)
mcp_tool_2 = McpTool(
server_label=mcp_server_label_2,
server_url=mcp_server_url_2,
allowed_tools=[ "someTool2"]
)
mcp_tool_1.set_approval_mode("never")
# my understanding is this will not have any effect as it cant be called on a specific run
mcp_tool_2.set_approval_mode("never")
toolset1 = ToolSet()
tooolset1.add(mcp_tool_1)
toolset2 = ToolSet()
toolset2.add(mcp_tool_2)
with project_client:
agent_2 = project_client.agents.create_agent(
description="description about when to use this as a connected agent",
name="agent2",
toolset=toolset2,
instructions=accounts_agent_instructions,
temperature=0.5)
connected_agent = ConnectedAgentTool(
id = agent_2.id,
name =agent_2.name,
description = agent_2.description,
)
toolset1.add(connected_agent)
agent_1 = project_client.agents.create_agent(
name="agent1",
description="this is the main orchestrator agent",
toolset=toolset1,
instructions="...",
temperature=0.5)
thread = project_client.agents.threads.create()
with project_client.agents.runs.stream(
agent_id=agent1.id,
thread_id=thread.id,
event_handler=MyEventHandler(project_client.agents),
tool_resources=toolset1.resources) as stream:
stream.until_done()
```
**Expected behavior**
As its not possible to specify a connected agents tool_resources directly for a run I would expected the connected_agent to still have a way to pass the tool approval, for example via capturing the run.status at "requires_action".
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Additional context**
azure-ai-projects: 1.1.0b2
When prompting the agent with a question that does NOT require the connected_agent from calling its MCP tool a proper response is surfaced. Additionally if the main agent needs to call a combination of its MCP tool + connected_agent, no issue is seen either. Only in the case of the connected_agent calling its MCP tool will a crash happen.
Contributor guide
Assessment
This issue has not been assessed yet.