ai-agents-for-beginners

🔍 Microsoft Agent Framework ကို ရှá€Ŧဖá€Ŋေတá€Ŋေ့ရှိခá€ŧငá€ēး – အခá€ŧေခá€ļ Agent (.NET)

📋 သငá€ēယူရနá€ē ရညá€ēရá€Ŋယá€ēခá€ģကá€ēမá€ģá€Ŧး

ဤá€Ĩပမá€Ŧသညá€ē Microsoft Agent Framework ၏ အခá€ŧေခá€ļ āšā¸™ā¸§ā¸„ā¸´ā¸”á€™á€ģá€Ŧးကို .NET တá€Ŋငá€ē အခá€ŧေခá€ļ agent တညá€ēဆေá€Ŧကá€ēခá€ŧငá€ēးမှတဆင့á€ē ရှá€Ŧဖá€Ŋá€ąá€žá€¯á€ļးသပá€ēပေးပá€Ģသညá€ē။ သငá€ēသညá€ē အဓိက agent နညá€ēးဗá€ģူဟá€Ŧမá€ģá€Ŧးကို လေ့လá€Ŧပá€ŧီး C# နှင့á€ē .NET ပတá€ēဝနá€ēးကá€ģငá€ēကို á€Ąá€žá€¯á€ļးပá€ŧု၍ အတá€Ŋငá€ēးနကá€ēပá€ŧတá€ēပá€ŧá€Ŧသေá€Ŧ agent မá€ģá€Ŧး အဖá€ŧေရှá€Ŧပုá€ļကို နá€Ŧးလညá€ēမိပá€Ģလိမ့á€ēမညá€ē။

သငá€ēရှá€Ŧဖá€Ŋေတá€Ŋေ့ရှိမည့á€ēအရá€Ŧမá€ģá€Ŧး

đŸŽ¯ ပá€Ģဝငá€ēသေá€Ŧ အဓိကအမá€ŧငá€ēမá€ģá€Ŧး

Agentic Framework ၏ သဘေá€Ŧတရá€Ŧးမá€ģá€Ŧး

နညá€ēးပညá€Ŧဆိုငá€ēရá€Ŧ အစိတá€ēá€Ąá€•á€­á€¯á€„á€ēးမá€ģá€Ŧး

🔧 နညá€ēးပညá€Ŧ Stack

အဓိက နညá€ēးပညá€Ŧမá€ģá€Ŧး

Agent ၏ စá€Ŋမá€ēးရညá€ēမá€ģá€Ŧး

📚 Framework နသိုငá€ēးယှဉá€ēခá€ŧငá€ēး

ဤá€Ĩပမá€Ŧသညá€ē Microsoft Agent Framework နှင့á€ē အခá€ŧá€Ŧး agentic frameworks မá€ģá€Ŧးကို နသိုငá€ēးယှဉá€ēဖေá€Ŧá€ēပá€ŧပေးပá€Ģသညá€ē။

Feature Microsoft Agent Framework အခá€ŧá€Ŧး Framework မá€ģá€Ŧး
ပေá€Ģငá€ēးစပá€ēမသု Microsoft ပတá€ēဝနá€ēးကá€ģငá€ēလိုကá€ēဖကá€ēမသု native မတူညီသည့á€ēလိုကá€ēဖကá€ēမသုမá€ģá€Ŧး
ရိုးရသငá€ēးမသု သန့á€ēရှငá€ēးပá€ŧီး လá€Ŋယá€ēကူသည့á€ē API မကá€ŧá€Ŧခဏ ပá€ŧငá€ēဆငá€ēရနá€ēရသုပá€ēထá€Ŋá€ąá€¸á€™á€žá€¯á€™á€ģá€Ŧး
ခá€ģဲ့ထá€Ŋငá€ēနိုငá€ēမသု ကိရိယá€Ŧမá€ģá€Ŧးလá€Ŋယá€ēကူစá€Ŋá€Ŧ ပေá€Ģငá€ēးစပá€ēနိုငá€ēခá€ŧငá€ēး Framework အပေá€Ģá€ēတá€Ŋငá€ē အခá€ŧေခá€ļသညá€ē
လုပá€ēငနá€ēá€¸á€Ąá€žá€¯á€ļးပá€ŧုမသု ထုတá€ēလုပá€ēá€™á€žá€¯á€Ąá€á€Ŋကá€ē တညá€ēဆေá€Ŧကá€ēထá€Ŧးသညá€ē Framework á€Ąá€œá€­á€¯á€€á€ē မတူကá€Ŋဲပá€ŧá€Ŧးမသုရသိသညá€ē

🚀 စတငá€ē á€Ąá€žá€¯á€ļးပá€ŧုခá€ŧငá€ēး

á€œá€­á€¯á€Ąá€•á€ēခá€ģကá€ēမá€ģá€Ŧး

á€œá€­á€¯á€Ąá€•á€ēသေá€Ŧ ပတá€ēဝနá€ēးကá€ģငá€ē မူဝá€Ģဒမá€ģá€Ŧး

# zsh/bash
export AZURE_OPENAI_ENDPOINT=https://<your-resource>.openai.azure.com
export AZURE_OPENAI_DEPLOYMENT=gpt-4.1-mini
# ပá€ŧီးတေá€Ŧ့ AzureCliCredential သညá€ē token တစá€ēခုပá€ŧá€¯á€œá€­á€¯á€ˇá€›á€Ąá€ąá€Ŧငá€ē လကá€ēမှတá€ēလကá€ēမှတá€ēဝငá€ēပá€Ģ
az login
# PowerShell
$env:AZURE_OPENAI_ENDPOINT = "https://<your-resource>.openai.azure.com"
$env:AZURE_OPENAI_DEPLOYMENT = "gpt-4.1-mini"
# á€‘á€­á€¯á€ˇá€”á€ąá€Ŧကá€ē AzureCliCredential သညá€ē token ကို ရနိုငá€ēရနá€ē အကေá€Ŧင့á€ēဝငá€ēပá€Ģ။
az login

နမူနá€Ŧ ကုဒá€ē

ကုဒá€ē á€Ĩပမá€Ŧကို လညá€ēပတá€ēရနá€ē

# zsh/bash
chmod +x ./02-dotnet-agent-framework.cs
./02-dotnet-agent-framework.cs

ဒá€Ģမသမဟုတá€ē dotnet CLI á€Ąá€žá€¯á€ļးပá€ŧု၍

dotnet run ./02-dotnet-agent-framework.cs

ပá€ŧည့á€ēစုá€ļသေá€Ŧကုဒá€ēကို 02-dotnet-agent-framework.cs တá€Ŋငá€ē ကá€ŧည့á€ēရသုနိုငá€ēသညá€ē။

#!/usr/bin/dotnet run

#:package Microsoft.Extensions.AI@10.*
#:package Microsoft.Agents.AI.OpenAI@1.*-*
#:package Azure.AI.OpenAI@2.1.0
#:package Azure.Identity@1.13.1

using System.ComponentModel;

using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;

using Azure.AI.OpenAI;
using Azure.Identity;

// Tool Function: Random Destination Generator
// This static method will be available to the agent as a callable tool
// The [Description] attribute helps the AI understand when to use this function
// This demonstrates how to create custom tools for AI agents
[Description("Provides a random vacation destination.")]
static string GetRandomDestination()
{
    // List of popular vacation destinations around the world
    // The agent will randomly select from these options
    var destinations = new List<string>
    {
        "Paris, France",
        "Tokyo, Japan",
        "New York City, USA",
        "Sydney, Australia",
        "Rome, Italy",
        "Barcelona, Spain",
        "Cape Town, South Africa",
        "Rio de Janeiro, Brazil",
        "Bangkok, Thailand",
        "Vancouver, Canada"
    };

    // Generate random index and return selected destination
    // Uses System.Random for simple random selection
    var random = new Random();
    int index = random.Next(destinations.Count);
    return destinations[index];
}

// Azure OpenAI with the Responses API (stable v1 endpoint). Sign in with `az login`.
var azureEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
    ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deployment = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT") ?? "gpt-4.1-mini";

var azureClient = new AzureOpenAIClient(new Uri(azureEndpoint), new AzureCliCredential());

// Define Agent Identity and Comprehensive Instructions
// Agent name for identification and logging purposes
var AGENT_NAME = "TravelAgent";

// Detailed instructions that define the agent's personality, capabilities, and behavior
// This system prompt shapes how the agent responds and interacts with users
var AGENT_INSTRUCTIONS = """
You are a helpful AI Agent that can help plan vacations for customers.

Important: When users specify a destination, always plan for that location. Only suggest random destinations when the user hasn't specified a preference.

When the conversation begins, introduce yourself with this message:
"Hello! I'm your TravelAgent assistant. I can help plan vacations and suggest interesting destinations for you. Here are some things you can ask me:
1. Plan a day trip to a specific location
2. Suggest a random vacation destination
3. Find destinations with specific features (beaches, mountains, historical sites, etc.)
4. Plan an alternative trip if you don't like my first suggestion

What kind of trip would you like me to help you plan today?"

Always prioritize user preferences. If they mention a specific destination like "Bali" or "Paris," focus your planning on that location rather than suggesting alternatives.
""";

// Create AI Agent with Advanced Travel Planning Capabilities
// Get the Responses client for the deployment and create the AI agent
// Configure agent with name, detailed instructions, and available tools
// This demonstrates the .NET agent creation pattern with full configuration
AIAgent agent = azureClient
    .GetChatClient(deployment)
    .AsAIAgent(
        name: AGENT_NAME,
        instructions: AGENT_INSTRUCTIONS,
        tools: [AIFunctionFactory.Create(GetRandomDestination)]
    );

// Create New Session for Context Management.
// Initialize a new conversation session to maintain context across multiple interactions
// Sessions enable the agent to remember previous exchanges and maintain conversational state
// This is essential for multi-turn conversations and contextual understanding
AgentSession session = await agent.CreateSessionAsync();

// Execute Agent: First Travel Planning Request
// Run the agent with an initial request that will likely trigger the random destination tool
// The agent will analyze the request, use the GetRandomDestination tool, and create an itinerary
// Using the session parameter maintains conversation context for subsequent interactions
await foreach (var update in agent.RunStreamingAsync("Plan me a day trip", session))
{
    await Task.Delay(10);
    Console.Write(update);
}

Console.WriteLine();

// Execute Agent: Follow-up Request with Context Awareness
// Demonstrate contextual conversation by referencing the previous response
// The agent remembers the previous destination suggestion and will provide an alternative
// This showcases the power of conversation sessions and contextual understanding in .NET agents
await foreach (var update in agent.RunStreamingAsync("I don't like that destination. Plan me another vacation.", session))
{
    await Task.Delay(10);
    Console.Write(update);
}

🎓 အဓိက သငá€ēခနá€ēးစá€Ŧမá€ģá€Ŧး

  1. Agent ပုá€ļသဏ္ဍá€Ŧနá€ē: Microsoft Agent Framework သညá€ē .NET တá€Ŋငá€ē AI agent မá€ģá€Ŧး တညá€ēဆေá€Ŧကá€ēရနá€ē ရိုးရသငá€ēးပá€ŧီး type-safe နညá€ēးလမá€ēးပေးသညá€ē
  2. ကိရိယá€Ŧ ပေá€Ģငá€ēးစပá€ēခá€ŧငá€ēး: [Description] attribute ဖá€ŧင့á€ēကပá€ēထá€Ŧးသေá€Ŧ function မá€ģá€Ŧးကို agent ၏ á€Ąá€žá€¯á€ļးပá€ŧုနိုငá€ēသေá€Ŧ ကိရိယá€Ŧမá€ģá€Ŧးအဖá€ŧစá€ē သတá€ēမှတá€ēပေးသညá€ē
  3. စကá€Ŧးပá€ŧေá€Ŧ Context: session စီမá€ļခန့á€ēခá€Ŋá€˛á€™á€žá€¯á€žá€Šá€ē multi-turn စကá€Ŧးပá€ŧေá€Ŧမá€ģá€Ŧးအတá€Ŋကá€ē context အသိပညá€Ŧနှင့á€ēအတူ ခá€Ŋင့á€ēပá€ŧုသညá€ē
  4. ဖá€Ŋဲ့စညá€ēးမသု စီမá€ļခန့á€ēခá€Ŋá€˛á€™á€žá€¯: ပတá€ēဝနá€ēးကá€ģငá€ē variable မá€ģá€Ŧးနှင့á€ē လုá€ļခá€ŧုá€ļသေá€Ŧ credential ကို .NET ၏ အကေá€Ŧငá€ēးဆုá€ļး လေ့ကá€ģင့á€ēမသုမá€ģá€Ŧးနှင့á€ēလိုကá€ēနá€Ŧသညá€ē
  5. Azure OpenAI Responses API: agent သညá€ē Azure.AI.OpenAI SDK မှတဆင့á€ē Azure OpenAI Responses API ကို á€Ąá€žá€¯á€ļးပá€ŧုသညá€ē

🔗 ထပá€ēမá€ļ á€Ąá€žá€¯á€ļးဝငá€ē မူရငá€ēးမá€ģá€Ŧး


ပá€ŧေá€Ŧကá€ŧá€Ŧးခá€ģကá€ē ဤစá€Ŧတမá€ēးကို AI ဘá€Ŧသá€Ŧပá€ŧနá€ēဝနá€ēဆေá€Ŧငá€ēမသု Co-op Translator á€Ąá€žá€¯á€ļးပá€ŧု၍ ဘá€Ŧသá€Ŧပá€ŧနá€ēထá€Ŧးပá€Ģသညá€ē။ ကá€ģá€Ŋနá€ēုပá€ēá€á€­á€¯á€ˇá€žá€Šá€ē တိကá€ģမှနá€ēကနá€ēá€™á€žá€¯á€Ąá€á€Ŋကá€ē ကá€ŧိုးပမá€ēးနေသေá€Ŧá€ēလညá€ēး၊ စကá€ēကိရိယá€Ŧဘá€Ŧသá€Ŧပá€ŧနá€ēခá€ŧငá€ēးမá€ģá€Ŧးတá€Ŋငá€ē အမှá€Ŧးမá€ģá€Ŧး á€žá€­á€¯á€ˇá€™á€Ÿá€¯á€á€ē မှá€Ŧးယá€Ŋငá€ēးခá€ģကá€ēမá€ģá€Ŧး ပá€Ģဝငá€ēနိုငá€ēကá€ŧေá€Ŧငá€ēး သတိပá€ŧုပá€Ģရနá€ē á€œá€­á€¯á€Ąá€•á€ēပá€Ģသညá€ē။ မူလစá€Ŧတမá€ēးကို မူရငá€ēးဘá€Ŧသá€Ŧဖá€ŧင့á€ēသá€Ŧ ယုá€ļကá€ŧညá€ēစိတá€ēခá€ģရသေá€Ŧ အခá€ģကá€ēအလကá€ēအဖá€ŧစá€ē သတá€ēမှတá€ēသင့á€ēသညá€ē။ အရေးကá€ŧီးသည့á€ē သတငá€ēးအခá€ģကá€ēအလကá€ēမá€ģá€Ŧးအတá€Ŋကá€ē ပရေá€Ŧá€ēဖကá€ēရှငá€ēနယá€ē လူသá€Ŧးဘá€Ŧသá€Ŧပá€ŧနá€ēသူဝနá€ēဆေá€Ŧငá€ēမသုကို အကá€ŧá€ļပá€ŧုပá€Ģသညá€ē။ ဤဘá€Ŧသá€Ŧပá€ŧနá€ēခá€ģကá€ēကို á€Ąá€žá€¯á€ļးပá€ŧုခá€ŧငá€ēးမှ ဖá€ŧစá€ēပေá€Ģá€ēလá€Ŧသေá€Ŧ နá€Ŧးလညá€ēမသုကá€Ŋá€Ŧခá€ŧá€Ŧးမသုမá€ģá€Ŧး á€žá€­á€¯á€ˇá€™á€Ÿá€¯á€á€ē မမှနá€ēကနá€ēသေá€Ŧ á€Ąá€žá€¯á€ļးပá€ŧုမသုမá€ģá€Ŧးအတá€Ŋကá€ē ကá€ģá€Ŋနá€ēုပá€ēá€á€­á€¯á€ˇ တá€Ŧဝနá€ēမခá€ļပá€Ģ။