ai-agents-for-beginners

🌍 Microsoft Agent Framework (.NET)을 ν™œμš©ν•œ AI μ—¬ν–‰ μ—μ΄μ „νŠΈ

πŸ“‹ μ‹œλ‚˜λ¦¬μ˜€ κ°œμš”

이 μ˜ˆμ œλŠ” .NET용 Microsoft Agent Frameworkλ₯Ό μ‚¬μš©ν•˜μ—¬ μ§€λŠ₯ν˜• μ—¬ν–‰ κ³„νš μ—μ΄μ „νŠΈλ₯Ό κ΅¬μΆ•ν•˜λŠ” 방법을 λ³΄μ—¬μ€λ‹ˆλ‹€. 이 μ—μ΄μ „νŠΈλŠ” μ „ μ„Έκ³„μ˜ 랜덀 λͺ©μ μ§€μ— λŒ€ν•΄ κ°œμΈν™”λœ 당일 μ—¬ν–‰ 일정을 μžλ™μœΌλ‘œ 생성할 수 μžˆμŠ΅λ‹ˆλ‹€.

μ£Όμš” κΈ°λŠ₯:

πŸ”§ 기술 μ•„ν‚€ν…μ²˜

핡심 기술

μ£Όμš” ꡬ성 μš”μ†Œ

  1. AIAgent: λŒ€ν™” 흐름을 κ΄€λ¦¬ν•˜λŠ” μ£Όμš” μ—μ΄μ „νŠΈ κ΄€λ¦¬μž
  2. μ»€μŠ€ν…€ 도ꡬ: μ—μ΄μ „νŠΈκ°€ μ‚¬μš©ν•  수 μžˆλŠ” GetRandomDestination() ν•¨μˆ˜
  3. Responses ν΄λΌμ΄μ–ΈνŠΈ: Azure OpenAI Responses 기반 λŒ€ν™” μΈν„°νŽ˜μ΄μŠ€
  4. 슀트리밍 지원: μ‹€μ‹œκ°„ 응닡 생성 κΈ°λŠ₯

톡합 νŒ¨ν„΄

graph LR
    A[μ‚¬μš©μž μš”μ²­] --> B[AI μ—μ΄μ „νŠΈ]
    B --> C[Azure OpenAI (응닡 API)]
    B --> D[λ¬΄μž‘μœ„ λͺ©μ μ§€ μ–»κΈ° 도ꡬ]
    C --> E[μ—¬ν–‰ μΌμ •ν‘œ]
    D --> E

πŸš€ μ‹œμž‘ν•˜κΈ°

ν•„μš” 쑰건

ν•„μˆ˜ ν™˜κ²½ λ³€μˆ˜

# zsh/bash
export AZURE_OPENAI_ENDPOINT=https://<your-resource>.openai.azure.com
export AZURE_OPENAI_DEPLOYMENT=gpt-5-mini
# 그런 λ‹€μŒ AzureCliCredential이 토큰을 얻을 수 μžˆλ„λ‘ λ‘œκ·ΈμΈν•˜μ„Έμš”
az login
# PowerShell
$env:AZURE_OPENAI_ENDPOINT = "https://<your-resource>.openai.azure.com"
$env:AZURE_OPENAI_DEPLOYMENT = "gpt-5-mini"
# 그런 λ‹€μŒ AzureCliCredentialκ°€ 토큰을 κ°€μ Έμ˜¬ 수 μžˆλ„λ‘ λ‘œκ·ΈμΈν•©λ‹ˆλ‹€
az login

μƒ˜ν”Œ μ½”λ“œ

μ½”λ“œλ₯Ό μ‹€ν–‰ν•˜λ €λ©΄,

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

λ˜λŠ” dotnet CLIλ₯Ό μ‚¬μš©ν•˜μ—¬:

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

전체 μ½”λ“œλŠ” 01-dotnet-agent-framework.csλ₯Ό μ°Έμ‘°ν•˜μ„Έμš”.

#!/usr/bin/dotnet run

#:package Microsoft.Extensions.AI@10.4.1
#:package Microsoft.Agents.AI.OpenAI@1.1.0
#: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-5-mini";

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

// Create AI Agent with Travel Planning Capabilities
// Get the Responses client for the specified deployment and create the AI agent
// Configure agent with travel planning instructions and random destination tool
// The agent can now plan trips using the GetRandomDestination function
AIAgent agent = azureClient
    .GetChatClient(deployment)
    .AsAIAgent(
        instructions: "You are a helpful AI Agent that can help plan vacations for customers at random destinations",
        tools: [AIFunctionFactory.Create(GetRandomDestination)]
    );

// Execute Agent: Plan a Day Trip
// Run the agent with streaming enabled for real-time response display
// Shows the agent's thinking and response as it generates the content
// Provides better user experience with immediate feedback
await foreach (var update in agent.RunStreamingAsync("Plan me a day trip"))
{
    await Task.Delay(10);
    Console.Write(update);
}

πŸŽ“ μ£Όμš” μ‹œμ‚¬μ 

  1. μ—μ΄μ „νŠΈ μ•„ν‚€ν…μ²˜: Microsoft Agent FrameworkλŠ” .NETμ—μ„œ AI μ—μ΄μ „νŠΈλ₯Ό ꡬ좕할 수 μžˆλŠ” κΉ”λ”ν•˜κ³  νƒ€μž… μ•ˆμ „ν•œ 접근법을 μ œκ³΅ν•©λ‹ˆλ‹€.
  2. 도ꡬ 톡합: [Description] νŠΉμ„±μ΄ μ§€μ •λœ ν•¨μˆ˜λŠ” μ—μ΄μ „νŠΈκ°€ μ‚¬μš©ν•  수 μžˆλŠ” 도ꡬ가 λ©λ‹ˆλ‹€.
  3. ꡬ성 관리: ν™˜κ²½ λ³€μˆ˜μ™€ μ•ˆμ „ν•œ 자격 증λͺ… μ²˜λ¦¬λŠ” .NET μ΅œμ„  사둀λ₯Ό λ”°λ¦…λ‹ˆλ‹€.
  4. Azure OpenAI Responses API: μ—μ΄μ „νŠΈλŠ” Azure.AI.OpenAI SDKλ₯Ό 톡해 Azure OpenAI Responses APIλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

πŸ”— μΆ”κ°€ 자료


λ©΄μ±… μ‘°ν•­: 이 λ¬Έμ„œλŠ” AI λ²ˆμ—­ μ„œλΉ„μŠ€ Co-op Translatorλ₯Ό μ‚¬μš©ν•˜μ—¬ λ²ˆμ—­λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 정확성을 κΈ°ν•˜κΈ° μœ„ν•΄ λ…Έλ ₯ν•˜κ³  μžˆμœΌλ‚˜, μžλ™ λ²ˆμ—­μ€ 였λ₯˜λ‚˜ λΆ€μ •ν™•ν•œ 뢀뢄이 μžˆμ„ 수 μžˆμŒμ„ μœ μ˜ν•˜μ‹œκΈ° λ°”λžλ‹ˆλ‹€. 원본 λ¬Έμ„œμ˜ 원어본이 κΆŒμœ„ μžˆλŠ” 자료둜 κ°„μ£Όλ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€. μ€‘μš”ν•œ μ •λ³΄μ˜ 경우, μ „λ¬Έκ°€μ˜ 인간 λ²ˆμ—­μ„ ꢌμž₯ν•©λ‹ˆλ‹€. 이 λ²ˆμ—­ μ‚¬μš©μœΌλ‘œ 인해 λ°œμƒν•˜λŠ” μ˜€ν•΄λ‚˜ 잘λͺ»λœ 해석에 λŒ€ν•΄ λ‹Ήμ‚¬λŠ” μ±…μž„μ„ μ§€μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.