QuestionQ13

VerifiedImplement generative AI and agentic solutions

You have a Microsoft Foundry project that contains an agent, and the agent has a Model Context Protocol (MCP) tool that queries a knowledge base stored in Azure AI Search.

Some agent runs return answers straight from the base model without invoking the knowledge base, so those responses lack grounded citations.

You are given the following code snippet, which runs the agent:

Question Image

You need to add the correct tool_choice parameter to the code so that the agent is deterministically forced to invoke the MCP tool on every run.

What should you add?

Explanation

The Azure AI Agents SDK's tool_choice parameter accepts either a mode string (auto, required, none) or a named tool choice object that pins the run to one specific tool by its type — for example a value equivalent to {"type": "mcp"} — which forces the agent to invoke that particular tool rather than whichever tool the model happens to pick. Setting tool_choice to "required" only guarantees that some tool is called; if the agent had more than one tool available it would not guarantee the MCP tool specifically is the one invoked. Because the goal is to deterministically force invocation of the MCP tool specifically (not merely any tool), the typed/named tool_choice value targeting the mcp tool type is required.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!