<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ahamed Hilmy</title>
    <description>The latest articles on DEV Community by Ahamed Hilmy (@ahamed_hilmy).</description>
    <link>https://dev.to/ahamed_hilmy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3598006%2F6e027f1d-db1a-4442-a2ab-4f0e5354a8d9.jpg</url>
      <title>DEV Community: Ahamed Hilmy</title>
      <link>https://dev.to/ahamed_hilmy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahamed_hilmy"/>
    <language>en</language>
    <item>
      <title>Building Microsoft Foundry Agents: Part 1 - Creating Your First Simple SDK Agent</title>
      <dc:creator>Ahamed Hilmy</dc:creator>
      <pubDate>Fri, 30 Jan 2026 05:16:50 +0000</pubDate>
      <link>https://dev.to/ahamed_hilmy/building-microsoft-foundry-agents-part-1-creating-your-first-simple-sdk-agent-51je</link>
      <guid>https://dev.to/ahamed_hilmy/building-microsoft-foundry-agents-part-1-creating-your-first-simple-sdk-agent-51je</guid>
      <description>&lt;p&gt;In the rapidly evolving world of artificial intelligence, the industry is moving beyond simple Large Language Model (LLM) calls toward &lt;strong&gt;agentic behavior&lt;/strong&gt;. While a traditional LLM interaction is a single exchange, an agent represents an &lt;strong&gt;interaction loop&lt;/strong&gt; capable of taking action and making decisions.&lt;/p&gt;

&lt;p&gt;This series uses Microsoft Agent Framework to run agents backed by Azure AI Foundry Agent Service (via &lt;code&gt;AzureAIAgentClient&lt;/code&gt;). The framework is a unified, open-source library that simplifies building these systems by providing a high-level abstraction for orchestration.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an Agent?
&lt;/h2&gt;

&lt;p&gt;At its core, an agent can be broken down into three simple categories: &lt;strong&gt;inputs&lt;/strong&gt;, &lt;strong&gt;outputs&lt;/strong&gt;, and &lt;strong&gt;tool calls&lt;/strong&gt;. Unlike traditional Retrieval-Augmented Generation (RAG) where all context is provided up-front, an agent may start with only a system prompt and discover the necessary context and tools through its own journey.&lt;/p&gt;

&lt;p&gt;The Microsoft Agent Framework allows you to build these agents as code, offering &lt;strong&gt;local debuggability&lt;/strong&gt; and the ability to step through tool calls to trace tool calls / execution steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow this guide, you will need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Python 3.10&lt;/strong&gt; or later (or .NET 8.0 if you prefer C#).&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;Azure AI Foundry&lt;/strong&gt; project endpoint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Azure CLI&lt;/strong&gt; installed and authenticated (&lt;code&gt;az login&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;The Agent Framework library: &lt;code&gt;pip install agent-framework --pre&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Set your two required environment variables: &lt;code&gt;AZURE_AI_PROJECT_ENDPOINT&lt;/code&gt;
&lt;code&gt;AZURE_AI_MODEL_DEPLOYMENT_NAME&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Secure Authentication
&lt;/h2&gt;

&lt;p&gt;A standout feature of the Microsoft Agent Framework is its security-first mindset. Instead of leaking API keys in environment files, it uses Identity to authenticate. By using &lt;code&gt;AzureCliCredential&lt;/code&gt;, the agent runs using your identity on your machine and can transition to a production system's identity without code changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;azure.identity.aio&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AzureCliCredential&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;agent_framework.azure&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AzureAIAgentClient&lt;/span&gt;

&lt;span class="c1"&gt;# Authenticate securely without API keys
&lt;/span&gt;&lt;span class="n"&gt;credential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AzureCliCredential&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Define Your Agent
&lt;/h2&gt;

&lt;p&gt;Creating an agent involves defining its &lt;strong&gt;instructions&lt;/strong&gt; (the system prompt) and giving it a &lt;strong&gt;name&lt;/strong&gt;. The name is crucial for observability and when you eventually compose multiple agents into a multi-agent swarm.&lt;/p&gt;

&lt;p&gt;It is important to note that &lt;strong&gt;creating an agent and running an agent are separate steps&lt;/strong&gt;. This allows your application to instantiate the agent resources once and reuse them for multiple requests within the same process/context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Create the client and the agent
&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;AzureAIAgentClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;credential&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;credential&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;as_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TravelGuide&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;instructions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are a luxury travel concierge. Recommend hidden gems.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Running the Agent
&lt;/h2&gt;

&lt;p&gt;Once the agent is defined, you can invoke it using the &lt;code&gt;run&lt;/code&gt; method. The framework handles the low-level API communication, allowing you to focus on the input and the resulting output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Run and wait for result
&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Suggest top 3 places to go to in Galle, Sri Lanka.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Print messages
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Optional: Real-time Streaming
&lt;/h3&gt;

&lt;p&gt;For a better user experience, you can use &lt;code&gt;run_stream&lt;/code&gt; to receive updates as they are generated rather than waiting for the full response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Suggest top 3 places to go to in Galle, Sri Lanka.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Putting it all together
&lt;/h2&gt;

&lt;p&gt;Now that we’ve explored the components individually, let’s see how they fit into a complete, executable Python script.&lt;/p&gt;

&lt;p&gt;To run this, we wrap our logic in an &lt;code&gt;async&lt;/code&gt; function. This is necessary because the &lt;strong&gt;Azure AI Agent Service&lt;/strong&gt; operates asynchronously to handle real-time streaming and long-running tool calls without blocking your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;azure.identity.aio&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AzureCliCredential&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;agent_framework.azure&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AzureAIAgentClient&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# Authenticate securely without API keys
&lt;/span&gt;    &lt;span class="n"&gt;credential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AzureCliCredential&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Create the client and the agent
&lt;/span&gt;    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;AzureAIAgentClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;credential&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;credential&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;as_agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TravelGuide&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;instructions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are a luxury travel concierge. Recommend hidden gems.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

        &lt;span class="c1"&gt;# Run and wait for result
&lt;/span&gt;        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Suggest top 3 places to go to in Galle, Sri Lanka.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Print messages
&lt;/span&gt;        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Cleanup
&lt;/span&gt;    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;credential&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# This is the crucial part that executes the async loop
&lt;/span&gt;    &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why Build Agents as Code?
&lt;/h2&gt;

&lt;p&gt;You might wonder why you would choose a code-first approach over low-code platforms like Copilot Studio. The primary reasons are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Customization and Control:&lt;/strong&gt; Code gives you the power to manipulate low-level tool calls and agent discovery.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portability:&lt;/strong&gt; You can run the framework in restricted or on-premise environments while calling cloud-based LLMs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local Experimentation:&lt;/strong&gt; You can run agents locally on your laptop to understand formatting, response behavior, and state management.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Looking Ahead
&lt;/h2&gt;

&lt;p&gt;We have now successfully built a basic agent that follows instructions using the Microsoft Agent Framework. However, this agent is currently &lt;strong&gt;isolated from the outside world&lt;/strong&gt;; it only knows what the LLM knows.&lt;/p&gt;

&lt;p&gt;Part 2: add a &lt;strong&gt;tool + MCP server&lt;/strong&gt; so the agent can call real functions / local data.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note on the Framework:&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;Agent Framework is in public preview; APIs may evolve.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>microsoft</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
