Build Your First AI Agent in Microsoft Foundry: File Search, Web Search, and Python for AI-901

Ask a typical AI chatbot for your office guest Wi-Fi name or whether Microsoft 365 is down right now, and it can only guess. It doesn’t know your company, and it can’t look anything up. The eighth video in my AI-901 Microsoft Azure AI Fundamentals series fixes that by building an AI agent in Microsoft Foundry. The agent reads a company document, searches the web for current information, and decides on its own which one to use. Then it gets connected to a simple Python app with no API keys in the code. Visit MyCloud.Coach for content on the AI-901 including lessons, cheat sheets, and practice exams.

The video is part of the “Implement AI solutions by using Microsoft Foundry” domain for the AI-901. It builds on the same Foundry project, gpt-5-mini deployment, and keyless sign-in from the earlier videos, but you can follow along with any Foundry project that has a deployed chat model that supports tool calling. If you’re studying for the certification or just getting started with agents in Foundry, this video is for you.

What Makes It an Agent

Agentic AI is a model plus instructions, along with tools that take actions on your behalf. A chatbot generates a response. An agent decides what to do and uses tools to do it.

An agent has three parts. The model provides the language understanding and reasoning, and to work in an agent it has to support tool calling. The instructions, also called the system message, set the role, the behavior, and the limits, and they’re saved with the agent. The tools are what the agent uses to find knowledge or take action.

The bigger change is the mindset. With a model, you ask it a question. With an agent, you give it a goal, and it works out the steps within the limits you set. Compared with the chat app from the last video, which could only answer from what the model learned during training, the agent saves its instructions and tools together and decides when to look things up. The chat app answers. The agent figures out how to answer.

Knowledge Tools and Action Tools

Agent tools come in two groups. Knowledge tools find information so the agent can ground its answers in things like internal documentation or sales data. Action tools do something, such as sending a message, running code, or calling another service.

Agents can call on other capabilities too. A code interpreter lets the agent write and run Python to analyze a spreadsheet or draw a chart. Custom functions let it call your own code or a web API, for example to open a ticket. And a Model Context Protocol, or MCP, server is a standard way to plug an agent into outside tools and data.

Keep in mind that the agent decides when to use a tool, not you. That’s why the instructions and the tool descriptions matter so much. It also ties back to responsible AI. An agent with no action tools can’t change anything, it can only look things up. You decide what the agent is allowed to do, and for anything high-impact, you keep a person in the loop.

[Image: Blog – Knowledge and Action Tools]

Foundry Agent Service and Prompt Agents

Foundry Agent Service is the part of Microsoft Foundry that hosts agents. It stores the model choice, instructions, and tools, runs the agent when someone calls it, and handles the tool calls for you. Agents built in the portal are called prompt agents. They’re defined by a model, instructions, and tools with no code, and you build and test them in the agent playground, which works much like the model playground.

Every save creates a new, immutable version, so you can compare versions and roll back to one that worked. Just be sure to save before you leave the agent playground, or your unsaved changes are lost. Apps reach the agent by name through the project endpoint, and the agent has its own identity it uses to access tools and data. The agent name is permanent, so follow a naming standard and pick a name that works in your code.

Calling an Agent from Code

The Foundry SDK, its two clients, and the Responses API from the last video all still apply. The difference is that instead of naming a model, the app sends an agent reference, which is the agent’s name and optionally a version. The agent supplies the model, instructions, and tools. Change the instructions in the portal and save a new version, and an app that uses the latest version picks them up without a single code change.

The model still never remembers, so something has to track the conversation history. The last video showed two options: the app keeps the history, or Foundry keeps it with the previous response ID. Agents add a third option, a conversation stored in Foundry. The app creates one conversation, then passes its ID with every message.

Sign-in works the same way as before. DefaultAzureCredential authenticates the user, and the Foundry User RBAC role is required. Here’s the catch, though. Agents don’t support API keys, so keyless sign-in is the only option.

Hands-On: Build and Test the Helpdesk Agent

The demos start in the Foundry portal at ai.azure.com. The gpt-5-mini deployment is opened in the model playground, the helpdesk system message is pasted into the instructions, and Save as agent turns it into an agent named it-helpdesk-agent. You can also create one by going to Build, Agents, and select New agent. The agent playground shows the model, instructions, and tools, and the YAML tab shows the agent’s full definition in one place.

Testing shows both what the agent can do and where it falls short. It handles follow-up questions because the playground keeps the conversation, but when asked for the guest Wi-Fi network name, it can’t know, so it gives a generic answer. A new line in the instructions and a save creates version 2, and the Monitor tab shows the token usage and cost of the testing so far.

Next, the Contoso IT helpdesk guide is added with the file search tool. Foundry indexes the plain text file into a vector index, the agent is saved as version 3, and the same Wi-Fi question now gets the real answer from the guide, with a citation that shows the answer came from the file and not the model’s training.

Watching the Agent Choose Its Tools

Web search is enabled by default in the example, so the next demo verifies it and then asks three questions in a row. A question about a current Microsoft 365 service outage triggers web search, with links to the sources. A question about the VPN address in the guide uses file search, with a citation. And a simple “Thanks, that fixed it” doesn’t need any tool at all. Nobody told the agent which tool to use. It made that choice each time.

There’s a responsible AI point here too. Web search sends queries outside your Foundry project to a public search service, so keep sensitive details out of prompts that could trigger a search, and check your organization’s policy before enabling it.

From the Portal to Python

Before writing any code, Publish and Preview web app opens a ready-made chat page for the agent. It’s intended for testing, but it’s the quickest way to see the agent the way a user would, and it calls the same agent the Python app uses next.

The Python demos run in VS Code for the Web, opened straight from the agent playground. After cloning the demo repo, creating a virtual environment, and installing the requirements, the first script calls the agent by name with keyless sign-in. There’s no model and no instructions in the responses.create call because the agent handles both, and the answer to the Wi-Fi question comes from the guide, proving the app is using the agent and its tools. The second script creates a single Foundry conversation before the chat loop and passes its ID with each new message, so the agent keeps the context across turns and still uses web search when a question needs current information. When the loop ends, the conversation is deleted.

Get the scripts: https://github.com/tsrob50/AI-901-Labs

Common Errors and Cleanup

The last demo covers the two errors beginners hit most with agent clients. A wrong agent name returns a 404 error saying the agent version wasn’t found, and the fix is to copy the exact name from Build, Agents in Foundry. A 401 or 403 error means you’re signed in but missing the Foundry User role, because the Owner role lets you manage the resource but doesn’t let you call models and agents.

The video wraps up with cleanup. Deleting the agent doesn’t remove the uploaded file or its index, so those are removed separately from Build, Data. If you plan to follow along with upcoming videos, keep the project, deployment, and agent, since the series builds on the same project.

Watch the Video

If you’re studying for the AI-901 certification or ready to move from a chat app to an agent that grounds its answers and chooses its own tools, this video takes you from the Foundry portal to a working Python app.

Watch now on YouTube: https://youtu.be/2xD_YcfIQIc

And if you find it helpful, subscribe to the channel and turn on notifications so you don’t miss the next video in the AI-901 series, which adds text analysis and voice to your app.

Links:

My Cloud Coach AI-901 course:
https://MyCloud.Coach

A Beginner’s Guide to the AZ-900
https://www.udemy.com/course/beginners-guide-az-900/?referralCode=C74C266B74E837F86969

Zero to Hero with Azure Virtual Desktop
https://www.udemy.com/course/zero-to-hero-with-windows-virtual-desktop/?referralCode=B2FE49E6FCEE7A7EA8D4

Hybrid Identity with Windows AD and Azure AD
https://www.udemy.com/course/hybrid-identity-and-azure-active-directory/?referralCode=7F62C4C6FD05C73ACCC3

Windows 365 Enterprise and Intune Management
https://www.udemy.com/course/windows-365-enterprise-and-intune-management/?referralCode=4A1ED105341D0AA20D2E

AI-901 Microsoft Azure AI Fundamentals Playlist
https://www.youtube.com/playlist?list=PLRg-m2DkQG-s

Exam AI-901: Microsoft Azure AI Fundamentals
https://learn.microsoft.com/en-us/credentials/certifications/exams/ai-901/

Study guide for Exam AI-901: Microsoft Azure AI Fundamentals
https://learn.microsoft.com/en-us/credentials/certifications/resources/study-guides/ai-901

Demo scripts:
https://github.com/tsrob50/AI-901-Labs

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Click Here!
Scroll to Top