Create an Azure AI agent with Microsoft Agent Framework
Unit 3 of 6 · Module 13: Develop an AI agent with Microsoft Agent Framework
Before you start
Short explainers for ideas this lesson builds on. Watch these first if they're new to you.
Go deeper
Unlocks when you've watched the lesson.
Read this lesson
Five steps to a working line
Setting up a Foundry agent in code is like getting a telephone line put in at an old switchboard office. First, you need a Foundry project with a model deployed, and two details from it: the project endpoint and the model deployment name. Second, authentication. DefaultAzureCredential finds the right credential for wherever your code runs: your Azure CLI sign-in on your laptop, and a managed identity in production. So there are no keys or connection strings in your code. Third, create a Foundry chat client with the credential, the endpoint, and the model name. It's the operator's switchboard between your app and Foundry: it signs you in, routes each request, and looks after sessions on the service side. Fourth, create the agent from that client. Give it instructions, the system prompt that sets its role, goals, and limits, and, if you like, tools. The framework registers the tools and writes their schemas, so the model knows when and how to call them. Fifth, open a session and run the agent with the user's message. It handles any tool calls and returns the answer.
The call log
One call to run handles one exchange: one message in, one answer out. For a real conversation, the agent needs to remember earlier turns, and that's what a session is for, like the operator's call log. With the Foundry provider, the log is kept on the service side, so a conversation can carry on across many requests, even if your app restarts or runs on several servers. Providers without service-side history keep it in memory inside the session object instead. That's fine for short-lived apps, but it's gone when the process stops.
A letter or a live call
You can get answers in two ways. Without streaming, run waits until the agent has finished and hands back the whole reply at once, like a letter. It's the simplest pattern. With streaming, you loop over the reply as it arrives, piece by piece, like a live phone call. That feels better in a chat window, where people like to watch the answer appear. Either way, the response has a text property that joins up all the text, so getting the final answer is easy.
Facts from Microsoft's documentation: Microsoft Agent Framework Overview; Agent Framework: sessions (CC BY 4.0), rewritten in Loop's own words and examples. Narration, animation, and quiz by Loop. Microsoft, Azure, and Microsoft Foundry are trademarks of Microsoft. Loop is independent and not affiliated with or endorsed by Microsoft.