Exercise: Build an agent with custom tools
Unit 5 of 6 · Module 8: Integrate custom tools into your agent
Before you start
Short explainers for ideas this lesson builds on. Watch these first if they're new to you.
Read this lesson
The plan
In this lab, you'll build an astronomy assistant that uses your own functions as tools. It finds the next astronomical event visible from a place, prices telescope time, and writes observation reports. It takes about fifty minutes, with VS Code, Git, an Azure subscription, and Python 3.13. Start in the Foundry Toolkit extension: create a project, choosing a subscription, a resource group, and a name. Then deploy the gpt-5 model with a Global Standard deployment, and copy the project endpoint. Clone the lab repository, open the custom tools folder, create a virtual environment, and install the requirements. Finally, put the project endpoint and your model deployment name into the dot env file.
Tools and the call loop
In functions dot py, you add next visible event: given a location, it checks the event data and returns the next event as JSON. Two more functions are already there: one calculates observation cost, and one writes a report. In agent dot py, you import the project client, the credential, the agent definition, function tools, and the function call output type, plus your three functions. Then you connect to the project and get an OpenAI client. Each function becomes a function tool with a JSON schema. The cost tool, for example, needs a telescope tier as text, hours as a number, and a priority, and all three are required. You create the agent with a model, instructions, and all three tools, and start a conversation. Now the part to understand well. When you send a prompt, the response can contain function call items instead of a final answer. Each one has the function's name, its arguments as JSON, and a call ID. Your code matches the name, parses the arguments, runs the function, and wraps the result as a function call output with the same call ID, like a claim ticket that pairs each answer with its question. You send those outputs back in the same conversation, and the agent turns them into a final answer. Send them back with a previous response ID instead, and the next message fails with no tool output found for function call.
Run it and clean up
Sign in with az login, and run agent dot py. Ask for the next event you can see from South America and the cost of five hours of premium telescope time at normal priority. The agent calls both functions in the same turn, then answers: the Jupiter-Venus conjunction on May first, and a cost of eighteen hundred and seventy-five dollars. Ask it to put that in a report for Bellows College, and a report file appears in your folder. Type quit to finish, and then clean up: delete the model deployment, and delete the resource group, so you're not charged. Try it here in the simulation, or follow Microsoft's instructions with your own subscription.
Facts from Microsoft's documentation: Use function calling with Microsoft Foundry agents; What is Microsoft Foundry Agent Service? (CC BY 4.0), rewritten in Loop's own words and examples. Narration, animation, and quiz by Loop. The coding lab is based on Microsoft's lab files for the agent exercises (MicrosoftLearning/mslearn-ai-agents, MIT License; notice). Microsoft, Azure, and Microsoft Foundry are trademarks of Microsoft. Loop is independent and not affiliated with or endorsed by Microsoft.