Lab BAF1 - Build and Run Your First Agent
In this lab you'll build and run a custom engine agent using the Microsoft 365 Agents SDK with Microsoft Agent Framework. You'll explore the starter project, understand the core components, and see your agent come to life in Microsoft 365 Copilot.
The Zava Insurance Agent helps insurance adjusters streamline claims processing. In this first lab you'll start with a basic conversational agent that greets users and answers with AI-powered responses. In the labs that follow you'll ground it in real enterprise data.
What are the Microsoft 365 Agents SDK and Agent Framework?
Microsoft 365 Agents SDK provides the container and scaffolding to deploy agents across Microsoft 365 channels (Teams, Copilot, and more), handling activities, events, and communication. It's AI-agnostic, so you can use any AI services you choose.
Microsoft Agent Framework is an open-source development kit for building AI agents with LLMs, tool calling, and multi-agent workflows. It's the successor to Semantic Kernel and AutoGen, and provides the AI capabilities and agent logic.
Together, they let you build intelligent agents with Agent Framework and deliver them to Microsoft 365 using the Agents SDK.
Lab objectives
By the end of this lab you will be able to:
- Explain how an agent, its instructions, and its tools fit together in Agent Framework
- Configure an agent project with your Microsoft Foundry model credentials
- Run and debug a custom engine agent locally
- Test the agent inside Microsoft 365 Copilot
- Customize the agent's behavior and see the change live
Exercise 1: Clone and explore the project
Step 1: Clone the repository
- Open a terminal or command prompt.
-
Clone the repository and move into the starter project:
git clone https://github.com/microsoft/copilot-camp.git cd copilot-camp/src/agent-framework/begin -
Open the project in Visual Studio Code:
code .
You should see this structure:
begin/
โโโ src/
โ โโโ Agent/
โ โ โโโ ZavaInsuranceAgent.cs # Main agent implementation
โ โโโ Plugins/ # Custom plugins (tools) for the agent
โ โ โโโ StartConversationPlugin.cs # Welcome message plugin
โ โ โโโ DateTimeFunctionTool.cs # Date/time utility
โโโ appPackage/ # Teams app manifest and icons
โโโ env/ # Environment configuration files
โโโ infra/ # Scripts, data and templates for the agent's infrastructure
โโโ Program.cs # Application entry point
โโโ InsuranceAgent.csproj # Project file
โโโ m365agents.local.yml # M365 Agents provisioning config
Step 2: Understand the agent and its tools
Open src/Agent/ZavaInsuranceAgent.cs and locate these three things:
| What to find | Why it matters |
|---|---|
The AgentInstructions property |
The system prompt. It defines the agent's role and lists its tools using the {{PluginName.FunctionName}} syntax. |
| The constructor | Registers OnConversationUpdate(...) for the welcome message and OnActivity(ActivityTypes.Message, ...) for every user message. |
The GetClientAgent method |
Builds a ChatOptions with a Tools list and registers each plugin with AIFunctionFactory.Create(...). This is how the AI learns what it can call. |
Now open src/Plugins/StartConversationPlugin.cs:
public class StartConversationPlugin
{
[Description("Starts a new conversation suggesting a conversation flow.")]
public async Task<string> StartConversation()
{
var welcomeMessage = "๐ Welcome to Zava Insurance Claims Assistant!...";
return welcomeMessage;
}
}
The [Description] attribute is the critical part โ it tells the model when to use the tool. Open src/Plugins/DateTimeFunctionTool.cs and notice it follows the same pattern with a static getDate() method.
Step 3: Review the host and the manifest
Open Program.cs and find these registrations:
AddSingleton<IStorage, MemoryStorage>()โ conversation state storageAddAgentApplicationOptions()โ agent configurationAddAgent<ZavaInsuranceAgent>()โ the agent itself- The
IChatClientsingleton โ creates anAzureOpenAIClientfrom your endpoint, key, and deployment name, which is what powers the agent's reasoning
Then open appPackage/manifest.json and review the conversationStarters array โ these are the suggested prompts users see on first use โ and the copilotAgents section that declares this app as a custom engine agent.
Exercise 2: Configure the agent
Step 1: Create your environment files
The agent reads configuration from environment files. Copy both samples:
Windows PowerShell:
Copy-Item env/.env.local.sample env/.env.local
Copy-Item env/.env.local.user.sample env/.env.local.user
macOS/Linux:
cp env/.env.local.sample env/.env.local
cp env/.env.local.user.sample env/.env.local.user
Step 2: Add your Microsoft Foundry credentials
-
Open
env/.env.localand setMODELS_ENDPOINTto the endpoint from Lab BAF0:MODELS_ENDPOINT=https://your-resource.services.ai.azure.com/ -
Open
env/.env.local.userand set your API key:SECRET_MODELS_API_KEY=your-api-key-here
Finding your endpoint
Go to Microsoft Foundry, select your project, then Settings โ Properties, and copy the Endpoint URL.
Keep your API key secret
.env.local.user contains sensitive information and is already listed in .gitignore. Never commit it.
Step 3: Sign in to Microsoft 365 and Azure
- In Visual Studio Code, select the Microsoft 365 Agents Toolkit icon in the Activity Bar.
- In the ACCOUNTS section, select Sign in to Microsoft 365 and complete the flow.
- Select Sign in to Azure and complete the flow.
Expected result: both accounts show as signed in in the ACCOUNTS section.
First time sign-in
You may be asked to grant permissions to the Microsoft 365 Agents Toolkit extension.
Exercise 3: Run, test, and customize
Step 1: Start the agent
- Set the debug configuration to (Preview) Debug in Copilot (Edge), then press F5.
- On first run, the Agents Toolkit provisions Azure resources โ it will ask you to pick an Azure subscription, a resource group, and a region (choose one close to your Microsoft Foundry project). This takes 2-3 minutes and creates an Azure Bot Service, an App Registration, and a Dev Tunnel.
- Watch the Terminal output.
Expected result: the terminal shows:
๐ Environment: local
๐ข Starting Zava Insurance Agent...
๐ค Main agent using model: gpt-4.1
โ
Agent initialized successfully!
A browser opens with Microsoft 365 Copilot and an install dialog. Select Add, then Open in Copilot.
Step 2: Test the agent
Your agent appears with its conversation starters.
Try each of these and observe which tool the agent chooses:
| Prompt | Expected behavior |
|---|---|
| What can you do? | Calls StartConversationPlugin and returns the welcome message |
| What's today's date? | Calls DateTimeFunctionTool and returns the current date and time |
| Tell me about insurance claims | Answers from the model's own knowledge โ no tool call |
| What's the weather today? | Politely declines as out of scope |
Check the Debug Console in Visual Studio Code to see the plugin calls and message processing in real time.
Issue processing the user's prompt
If the agent replies with raw text such as {{StartConversationPlugin.StartConversation}}, slightly reword the agent instructions in src/Agent/ZavaInsuranceAgent.cs, stop all running processes, and press F5 again. If it persists you can safely continue โ later exercises address it.
Step 3: Customize the welcome message
- Stop the debugger with Shift+F5.
- Open
src/Plugins/StartConversationPlugin.csand find thewelcomeMessagevariable. - Change the first line to
"๐ Welcome! I'm [Your Name]'s Agent!\n\n". - Save, press F5, and type "start over" in Microsoft 365 Copilot.
Expected result: your customized greeting appears, confirming that changing a plugin changes what the agent says.
CONGRATULATIONS!
You have completed Lab BAF1 - Build and Run Your First Agent!
You've learned how to:
- โ Explore an Agent Framework project and its plugin model
- โ Configure the agent with Microsoft Foundry credentials
- โ Run and debug the agent locally
- โ Test the agent in Microsoft 365 Copilot
- โ Customize the agent's behavior
Your agent can hold a conversation โ but it doesn't know anything about Zava's actual claims yet. In the next lab you'll ground it with a Foundry IQ knowledge base.