|
| 1 | +--- |
| 2 | +title: "Running Your First Agent using Microsoft Agent Framework" |
| 3 | +date: "2025-10-26" |
| 4 | +share: true |
| 5 | +header: |
| 6 | + image: media/2025-10-26-first-agent-agent-framework/01.png |
| 7 | + teaser: media/2025-10-26-first-agent-agent-framework/01.png |
| 8 | +categories: |
| 9 | + - AI |
| 10 | + - Copilot |
| 11 | +tags: |
| 12 | + - "2025" |
| 13 | + - October 2025 |
| 14 | +last_modified_at: 2025-10-26T00:00:00-00:00 |
| 15 | +--- |
| 16 | +## Introduction |
| 17 | + |
| 18 | +The **Microsoft Agent Framework** is a developer toolkit that allows you to build, orchestrate, and run intelligent agents that can think, reason, and take actions. These agents can perform specific tasks, call APIs, or integrate with real-world systems. |
| 19 | + |
| 20 | +In this article, we’ll learn how to **run your first agent** using Microsoft's Agent Framework - both in Python and C#. Instead of simply greeting users, our sample agents will help users **track daily tasks** in a simple and interactive way. |
| 21 | + |
| 22 | +## Understanding the Microsoft Agent Framework |
| 23 | + |
| 24 | +At its core, the Agent Framework enables developers to: |
| 25 | + |
| 26 | +- Create **autonomous agents** that use AI reasoning. |
| 27 | +- Integrate with **custom tools** (functions, APIs, data sources). |
| 28 | +- Run locally or in the cloud using simple commands. |
| 29 | +- Extend agents with **plugins** or external connectors. |
| 30 | + |
| 31 | +The agent runtime handles the conversation loop — interpreting user input, reasoning about it, and taking the right actions (like calling a function or returning a message). |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +## Example 1: Running an Agent in Python |
| 36 | + |
| 37 | +### Step 1: Prerequisites |
| 38 | + |
| 39 | +Ensure you have: |
| 40 | + |
| 41 | +- [Python 3.10+](https://www.python.org/downloads/release/python-3100/) |
| 42 | +- agentframework library installed via pip: |
| 43 | + |
| 44 | + ```bash |
| 45 | + pip install agentframework |
| 46 | + ``` |
| 47 | + |
| 48 | +### Step 2: Create the Agent File |
| 49 | + |
| 50 | +Let's create a Python agent called `task_agent.py`: |
| 51 | +
|
| 52 | +```python |
| 53 | +from agentframework import Agent |
| 54 | +
|
| 55 | +# Define the agent |
| 56 | +agent = Agent( |
| 57 | + name="task-agent", |
| 58 | + instructions="You are a helpful assistant that helps users manage their daily tasks." |
| 59 | +) |
| 60 | +
|
| 61 | +# Define a custom tool |
| 62 | +@agent.tool |
| 63 | +def add_task(task_name: str, priority: str = "normal"): |
| 64 | + """Add a new task with an optional priority.""" |
| 65 | + return f"✅ Task '{task_name}' added successfully with {priority} priority." |
| 66 | +
|
| 67 | +# Run the agent |
| 68 | +if __name__ == "__main__": |
| 69 | + agent.run() |
| 70 | +``` |
| 71 | +
|
| 72 | +### Step 3: Run the Agent |
| 73 | +
|
| 74 | +In the terminal, execute: |
| 75 | +
|
| 76 | +```bash |
| 77 | +python -m agentframework run task_agent.py |
| 78 | +``` |
| 79 | +
|
| 80 | +You will enter an interactive shell where you can talk to the agent. |
| 81 | +
|
| 82 | +**Example conversation:** |
| 83 | +
|
| 84 | +```bash |
| 85 | +> Add a task to review the AI presentation with high priority |
| 86 | +✅ Task 'review the AI presentation' added successfully with high priority. |
| 87 | +``` |
| 88 | +
|
| 89 | +## Example 2: Running an Agent in C# |
| 90 | +
|
| 91 | +### Step 1: Setup Project |
| 92 | +
|
| 93 | +Create a new .NET console project: |
| 94 | +
|
| 95 | +```bash |
| 96 | +dotnet new console -n TaskAgentApp |
| 97 | +cd TaskAgentApp |
| 98 | +dotnet add package Microsoft.AgentFramework |
| 99 | +``` |
| 100 | +
|
| 101 | +### Step 2: Create the Agent Class |
| 102 | +
|
| 103 | +In `Program.cs`, define and run your agent: |
| 104 | +
|
| 105 | +```csharp |
| 106 | +using Microsoft.AgentFramework; |
| 107 | +
|
| 108 | +class Program |
| 109 | +{ |
| 110 | + static void Main() |
| 111 | + { |
| 112 | + var agent = new Agent( |
| 113 | + name: "task-agent", |
| 114 | + instructions: "You are an intelligent assistant that helps users plan their daily schedule." |
| 115 | + ); |
| 116 | +
|
| 117 | + // Define a simple tool |
| 118 | + agent.AddTool("create_task", (parameters) => |
| 119 | + { |
| 120 | + string title = parameters["title"].ToString(); |
| 121 | + string time = parameters.ContainsKey("time") ? parameters["time"].ToString() : "unspecified time"; |
| 122 | + return $"🗓️ Task '{title}' scheduled for {time}."; |
| 123 | + }); |
| 124 | +
|
| 125 | + // Run the agent |
| 126 | + agent.Run(); |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
| 130 | +
|
| 131 | +### Step 3: Run the Application |
| 132 | +
|
| 133 | +Run the following command: |
| 134 | +
|
| 135 | +```bash |
| 136 | +dotnet run |
| 137 | +``` |
| 138 | +
|
| 139 | +Sample interaction: |
| 140 | +
|
| 141 | +```bash |
| 142 | +> Create a task to call the client at 3 PM |
| 143 | +🗓️ Task 'call the client' scheduled for 3 PM. |
| 144 | +``` |
| 145 | +
|
| 146 | +## Use Cases |
| 147 | +
|
| 148 | +The Microsoft Agent Framework can be extended to fit various business and productivity needs: |
| 149 | +
|
| 150 | +| **Use Case ** | **Description** | |
| 151 | +|---------------------------|-------------------------------------------------------------------------------| |
| 152 | +| **Personal Productivity** | Build agents to manage schedules, tasks, or reminders. | |
| 153 | +| **Customer Support** | Create agents that handle FAQs or escalate complex queries. | |
| 154 | +| **Business Workflows** | Automate tasks like report generation, ticket updates, or approvals. | |
| 155 | +| **Data Insights** | Connect to enterprise data sources for intelligent analysis and suggestions. | |
| 156 | +| **Copilot Integrations** | Extend Copilot scenarios by embedding agents with custom logic or memory. | |
| 157 | +
|
| 158 | +## Summary |
| 159 | +
|
| 160 | +In this article, we explored how to **run your first Microsoft Agent Framework agent** using both **Python** and **C#**. |
| 161 | +
|
| 162 | +We created simple task management agents that respond to user commands using natural language. The framework abstracts the complexity of reasoning and orchestration, allowing developers to focus on defining tools and business logic. |
| 163 | +
|
| 164 | +## References |
| 165 | +
|
| 166 | +- [Microsoft Agent Framework Documentation](https://learn.microsoft.com/en-us/agent-framework/overview/agent-framework-overview?WT.mc_id=M365-MVP-5003693) |
| 167 | +- [Tutorial: Run Your First Agent](https://learn.microsoft.com/en-us/agent-framework/tutorials/agents/run-agent?WT.mc_id=M365-MVP-5003693) |
| 168 | +- [Microsoft Agent Framework Agent Types](https://learn.microsoft.com/en-us/agent-framework/user-guide/agents/agent-types/?WT.mc_id=M365-MVP-5003693) |
| 169 | +- [Microsoft Agent Framework - GitHub Repository](https://github.com/microsoft/agent-framework) |
0 commit comments