# 🎨 GitHub λͺ¨λΈκ³Ό ν•¨κ»˜ν•˜λŠ” μ—μ΄μ „νŠΈ 섀계 νŒ¨ν„΄ (.NET) ## πŸ“‹ ν•™μŠ΅ λͺ©ν‘œ 이 μ˜ˆμ œλŠ” Microsoft Agent Frameworkλ₯Ό μ‚¬μš©ν•˜μ—¬ .NETμ—μ„œ GitHub λͺ¨λΈμ„ ν†΅ν•©ν•œ μ§€λŠ₯ν˜• μ—μ΄μ „νŠΈλ₯Ό κ΅¬μΆ•ν•˜κΈ° μœ„ν•œ μ—”ν„°ν”„λΌμ΄μ¦ˆκΈ‰ 섀계 νŒ¨ν„΄μ„ λ³΄μ—¬μ€λ‹ˆλ‹€. μ—μ΄μ „νŠΈλ₯Ό ν”„λ‘œλ•μ…˜ μ€€λΉ„ μƒνƒœλ‘œ λ§Œλ“€κ³ , μœ μ§€ 관리 κ°€λŠ₯ν•˜λ©°, ν™•μž₯ κ°€λŠ₯ν•œ 전문적인 νŒ¨ν„΄κ³Ό μ•„ν‚€ν…μ²˜ μ ‘κ·Ό 방식을 배울 수 μžˆμŠ΅λ‹ˆλ‹€. ### μ—”ν„°ν”„λΌμ΄μ¦ˆ 섀계 νŒ¨ν„΄ - 🏭 **νŒ©ν† λ¦¬ νŒ¨ν„΄**: μ˜μ‘΄μ„± μ£Όμž…μ„ ν†΅ν•œ ν‘œμ€€ν™”λœ μ—μ΄μ „νŠΈ 생성 - πŸ”§ **λΉŒλ” νŒ¨ν„΄**: μœ μ—°ν•œ μ—μ΄μ „νŠΈ ꡬ성 및 μ„€μ • - 🧡 **μŠ€λ ˆλ“œ μ•ˆμ „ νŒ¨ν„΄**: λ™μ‹œ λŒ€ν™” 관리 - πŸ“‹ **리포지토리 νŒ¨ν„΄**: 도ꡬ 및 κΈ°λŠ₯ κ΄€λ¦¬μ˜ 체계화 ## 🎯 .NET νŠΉν™” μ•„ν‚€ν…μ²˜ 이점 ### μ—”ν„°ν”„λΌμ΄μ¦ˆ κΈ°λŠ₯ - **κ°•λ ₯ν•œ νƒ€μž… μ§€μ •**: 컴파일 μ‹œ μœ νš¨μ„± 검사 및 IntelliSense 지원 - **μ˜μ‘΄μ„± μ£Όμž…**: λ‚΄μž₯ DI μ»¨ν…Œμ΄λ„ˆ 톡합 - **ꡬ성 관리**: IConfiguration 및 Options νŒ¨ν„΄ - **Async/Await**: 일급 비동기 ν”„λ‘œκ·Έλž˜λ° 지원 ### ν”„λ‘œλ•μ…˜ μ€€λΉ„ νŒ¨ν„΄ - **λ‘œκΉ… 톡합**: ILogger 및 ꡬ쑰적 λ‘œκΉ… 지원 - **ν—¬μŠ€ 체크**: λ‚΄μž₯ λͺ¨λ‹ˆν„°λ§ 및 진단 - **ꡬ성 μœ νš¨μ„± 검사**: 데이터 주석을 ν™œμš©ν•œ κ°•λ ₯ν•œ νƒ€μž… μ§€μ • - **μ—λŸ¬ 처리**: κ΅¬μ‘°ν™”λœ μ˜ˆμ™Έ 관리 ## πŸ”§ 기술 μ•„ν‚€ν…μ²˜ ### 핡심 .NET ꡬ성 μš”μ†Œ - **Microsoft.Extensions.AI**: 톡합 AI μ„œλΉ„μŠ€ 좔상화 - **Microsoft.Agents.AI**: μ—”ν„°ν”„λΌμ΄μ¦ˆ μ—μ΄μ „νŠΈ μ˜€μΌ€μŠ€νŠΈλ ˆμ΄μ…˜ ν”„λ ˆμž„μ›Œν¬ - **GitHub λͺ¨λΈ 톡합**: κ³ μ„±λŠ₯ API ν΄λΌμ΄μ–ΈνŠΈ νŒ¨ν„΄ - **ꡬ성 μ‹œμŠ€ν…œ**: appsettings.json 및 ν™˜κ²½ 톡합 ### 섀계 νŒ¨ν„΄ κ΅¬ν˜„ ```mermaid graph LR A[IServiceCollection] --> B[Agent Builder] B --> C[Configuration] C --> D[Tool Registry] D --> E[AI Agent] ``` ## πŸ—οΈ κ΅¬ν˜„λœ μ—”ν„°ν”„λΌμ΄μ¦ˆ νŒ¨ν„΄ ### 1. **생성 νŒ¨ν„΄** - **μ—μ΄μ „νŠΈ νŒ©ν† λ¦¬**: μΌκ΄€λœ κ΅¬μ„±μœΌλ‘œ 쀑앙 μ§‘μ€‘ν™”λœ μ—μ΄μ „νŠΈ 생성 - **λΉŒλ” νŒ¨ν„΄**: λ³΅μž‘ν•œ μ—μ΄μ „νŠΈ ꡬ성을 μœ„ν•œ μœ μ—°ν•œ API - **싱글톀 νŒ¨ν„΄**: 곡유 λ¦¬μ†ŒμŠ€ 및 ꡬ성 관리 - **μ˜μ‘΄μ„± μ£Όμž…**: λŠμŠ¨ν•œ κ²°ν•© 및 ν…ŒμŠ€νŠΈ κ°€λŠ₯μ„± ### 2. **행동 νŒ¨ν„΄** - **μ „λž΅ νŒ¨ν„΄**: ꡐ체 κ°€λŠ₯ν•œ 도ꡬ μ‹€ν–‰ μ „λž΅ - **μ»€λ§¨λ“œ νŒ¨ν„΄**: μ‹€ν–‰ μ·¨μ†Œ/μž¬μ‹€ν–‰μ΄ κ°€λŠ₯ν•œ μ—μ΄μ „νŠΈ μž‘μ—… μΊ‘μŠν™” - **μ˜΅μ €λ²„ νŒ¨ν„΄**: 이벀트 기반 μ—μ΄μ „νŠΈ 생λͺ…μ£ΌκΈ° 관리 - **ν…œν”Œλ¦Ώ λ©”μ„œλ“œ**: ν‘œμ€€ν™”λœ μ—μ΄μ „νŠΈ μ‹€ν–‰ μ›Œν¬ν”Œλ‘œ ### 3. **ꡬ쑰 νŒ¨ν„΄** - **μ–΄λŒ‘ν„° νŒ¨ν„΄**: GitHub λͺ¨λΈ API 톡합 계측 - **λ°μ½”λ ˆμ΄ν„° νŒ¨ν„΄**: μ—μ΄μ „νŠΈ κΈ°λŠ₯ ν™•μž₯ - **νΌμ‚¬λ“œ νŒ¨ν„΄**: κ°„μ†Œν™”λœ μ—μ΄μ „νŠΈ μƒν˜Έμž‘μš© μΈν„°νŽ˜μ΄μŠ€ - **ν”„λ‘μ‹œ νŒ¨ν„΄**: μ„±λŠ₯을 μœ„ν•œ μ§€μ—° λ‘œλ”© 및 캐싱 ## πŸ“š .NET λ””μžμΈ 원칙 ### SOLID 원칙 - **단일 μ±…μž„ 원칙**: 각 ꡬ성 μš”μ†ŒλŠ” λͺ…ν™•ν•œ λͺ©μ μ„ 가짐 - **개방/폐쇄 원칙**: μˆ˜μ • 없이 ν™•μž₯ κ°€λŠ₯ - **λ¦¬μŠ€μ½”ν”„ μΉ˜ν™˜ 원칙**: μΈν„°νŽ˜μ΄μŠ€ 기반 도ꡬ κ΅¬ν˜„ - **μΈν„°νŽ˜μ΄μŠ€ 뢄리 원칙**: 집쀑적이고 응집λ ₯ μžˆλŠ” μΈν„°νŽ˜μ΄μŠ€ - **μ˜μ‘΄μ„± μ—­μ „ 원칙**: ꡬ체화가 μ•„λ‹Œ 좔상화에 의쑴 ### 클린 μ•„ν‚€ν…μ²˜ - **도메인 계측**: 핡심 μ—μ΄μ „νŠΈ 및 도ꡬ 좔상화 - **μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 계측**: μ—μ΄μ „νŠΈ μ˜€μΌ€μŠ€νŠΈλ ˆμ΄μ…˜ 및 μ›Œν¬ν”Œλ‘œ - **인프라 계측**: GitHub λͺ¨λΈ 톡합 및 μ™ΈλΆ€ μ„œλΉ„μŠ€ - **ν”„λ ˆμ  ν…Œμ΄μ…˜ 계측**: μ‚¬μš©μž μƒν˜Έμž‘μš© 및 응닡 ν¬λ§·νŒ… ## πŸ”’ μ—”ν„°ν”„λΌμ΄μ¦ˆ 고렀사항 ### λ³΄μ•ˆ - **자격 증λͺ… 관리**: IConfiguration을 μ‚¬μš©ν•œ μ•ˆμ „ν•œ API ν‚€ 처리 - **μž…λ ₯ μœ νš¨μ„± 검사**: κ°•λ ₯ν•œ νƒ€μž… μ§€μ • 및 데이터 주석 μœ νš¨μ„± 검사 - **좜λ ₯ μ •ν™”**: μ•ˆμ „ν•œ 응닡 처리 및 필터링 - **감사 λ‘œκΉ…**: 포괄적인 μž‘μ—… 좔적 ### μ„±λŠ₯ - **비동기 νŒ¨ν„΄**: 비차단 I/O μž‘μ—… - **μ—°κ²° 풀링**: 효율적인 HTTP ν΄λΌμ΄μ–ΈνŠΈ 관리 - **캐싱**: μ„±λŠ₯ ν–₯상을 μœ„ν•œ 응닡 캐싱 - **λ¦¬μ†ŒμŠ€ 관리**: μ μ ˆν•œ ν•΄μ œ 및 정리 νŒ¨ν„΄ ### ν™•μž₯μ„± - **μŠ€λ ˆλ“œ μ•ˆμ „μ„±**: λ™μ‹œ μ—μ΄μ „νŠΈ μ‹€ν–‰ 지원 - **λ¦¬μ†ŒμŠ€ 풀링**: 효율적인 λ¦¬μ†ŒμŠ€ ν™œμš© - **λΆ€ν•˜ 관리**: 속도 μ œν•œ 및 μ—­μ•• 처리 - **λͺ¨λ‹ˆν„°λ§**: μ„±λŠ₯ λ©”νŠΈλ¦­ 및 ν—¬μŠ€ 체크 ## πŸš€ ν”„λ‘œλ•μ…˜ 배포 - **ꡬ성 관리**: ν™˜κ²½λ³„ μ„€μ • - **λ‘œκΉ… μ „λž΅**: 상관 IDλ₯Ό ν™œμš©ν•œ ꡬ쑰적 λ‘œκΉ… - **μ—λŸ¬ 처리**: μ μ ˆν•œ 볡ꡬλ₯Ό ν¬ν•¨ν•œ μ „μ—­ μ˜ˆμ™Έ 처리 - **λͺ¨λ‹ˆν„°λ§**: μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μΈμ‚¬μ΄νŠΈ 및 μ„±λŠ₯ μΉ΄μš΄ν„° - **ν…ŒμŠ€νŠΈ**: λ‹¨μœ„ ν…ŒμŠ€νŠΈ, 톡합 ν…ŒμŠ€νŠΈ 및 λΆ€ν•˜ ν…ŒμŠ€νŠΈ νŒ¨ν„΄ .NET으둜 μ—”ν„°ν”„λΌμ΄μ¦ˆκΈ‰ μ§€λŠ₯ν˜• μ—μ΄μ „νŠΈλ₯Ό ꡬ좕할 μ€€λΉ„κ°€ λ˜μ…¨λ‚˜μš”? κ²¬κ³ ν•œ μ•„ν‚€ν…μ²˜λ₯Ό 섀계해 λ΄…μ‹œλ‹€! 🏒✨ ## πŸš€ μ‹œμž‘ν•˜κΈ° ### 사전 μš”κ΅¬ 사항 - [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) 이상 - [GitHub λͺ¨λΈ API μ•‘μ„ΈμŠ€ 토큰](https://docs.github.com/github-models/github-models-at-scale/using-your-own-api-keys-in-github-models) ### ν•„μš”ν•œ ν™˜κ²½ λ³€μˆ˜ ```bash # zsh/bash export GH_TOKEN= export GH_ENDPOINT=https://models.github.ai/inference export GH_MODEL_ID=openai/gpt-5-mini ``` ```powershell # PowerShell $env:GH_TOKEN = "" $env:GH_ENDPOINT = "https://models.github.ai/inference" $env:GH_MODEL_ID = "openai/gpt-5-mini" ``` ### μƒ˜ν”Œ μ½”λ“œ μ½”λ“œ 예제λ₯Ό μ‹€ν–‰ν•˜λ €λ©΄, ```bash # zsh/bash chmod +x ./03-dotnet-agent-framework.cs ./03-dotnet-agent-framework.cs ``` λ˜λŠ” dotnet CLIλ₯Ό μ‚¬μš©ν•˜μ—¬: ```bash dotnet run ./03-dotnet-agent-framework.cs ``` 전체 μ½”λ“œλŠ” [`03-dotnet-agent-framework.cs`](../../../../03-agentic-design-patterns/code_samples/03-dotnet-agent-framework.cs)μ—μ„œ ν™•μΈν•˜μ„Έμš”. ```csharp #!/usr/bin/dotnet run #:package Microsoft.Extensions.AI@10.* #:package Microsoft.Agents.AI.OpenAI@1.*-* using System.ClientModel; using System.ComponentModel; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; using OpenAI; // 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 { "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]; } // Extract configuration from environment variables // Retrieve the GitHub Models API endpoint, defaults to https://models.github.ai/inference if not specified // Retrieve the model ID, defaults to openai/gpt-5-mini if not specified // Retrieve the GitHub token for authentication, throws exception if not specified var github_endpoint = Environment.GetEnvironmentVariable("GH_ENDPOINT") ?? "https://models.github.ai/inference"; var github_model_id = Environment.GetEnvironmentVariable("GH_MODEL_ID") ?? "openai/gpt-5-mini"; var github_token = Environment.GetEnvironmentVariable("GH_TOKEN") ?? throw new InvalidOperationException("GH_TOKEN is not set."); // Configure OpenAI Client Options // Create configuration options to point to GitHub Models endpoint // This redirects OpenAI client calls to GitHub's model inference service var openAIOptions = new OpenAIClientOptions() { Endpoint = new Uri(github_endpoint) }; // Initialize OpenAI Client with GitHub Models Configuration // Create OpenAI client using GitHub token for authentication // Configure it to use GitHub Models endpoint instead of OpenAI directly var openAIClient = new OpenAIClient(new ApiKeyCredential(github_token), openAIOptions); // 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 // Initialize complete agent pipeline: OpenAI client β†’ Chat client β†’ AI agent // Configure agent with name, detailed instructions, and available tools // This demonstrates the .NET agent creation pattern with full configuration AIAgent agent = openAIClient .GetChatClient(github_model_id) .CreateAIAgent( name: AGENT_NAME, instructions: AGENT_INSTRUCTIONS, tools: [AIFunctionFactory.Create(GetRandomDestination)] ); // Create New Conversation Thread for Context Management // Initialize a new conversation thread to maintain context across multiple interactions // Threads enable the agent to remember previous exchanges and maintain conversational state // This is essential for multi-turn conversations and contextual understanding AgentThread thread = agent.GetNewThread(); // 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 thread parameter maintains conversation context for subsequent interactions await foreach (var update in agent.RunStreamingAsync("Plan me a day trip", thread)) { 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 threads and contextual understanding in .NET agents await foreach (var update in agent.RunStreamingAsync("I don't like that destination. Plan me another vacation.", thread)) { await Task.Delay(10); Console.Write(update); } ``` --- **λ©΄μ±… μ‘°ν•­**: 이 λ¬Έμ„œλŠ” AI λ²ˆμ—­ μ„œλΉ„μŠ€ [Co-op Translator](https://github.com/Azure/co-op-translator)λ₯Ό μ‚¬μš©ν•˜μ—¬ λ²ˆμ—­λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 정확성을 μœ„ν•΄ λ…Έλ ₯ν•˜κ³  μžˆμ§€λ§Œ, μžλ™ λ²ˆμ—­μ—λŠ” 였λ₯˜λ‚˜ 뢀정확성이 포함될 수 μžˆμŠ΅λ‹ˆλ‹€. 원본 λ¬Έμ„œλ₯Ό ν•΄λ‹Ή μ–Έμ–΄λ‘œ μž‘μ„±λœ μƒνƒœμ—μ„œ κΆŒμœ„ μžˆλŠ” 자료둜 κ°„μ£Όν•΄μ•Ό ν•©λ‹ˆλ‹€. μ€‘μš”ν•œ μ •λ³΄μ˜ 경우, 전문적인 인간 λ²ˆμ—­μ„ ꢌμž₯ν•©λ‹ˆλ‹€. 이 λ²ˆμ—­ μ‚¬μš©μœΌλ‘œ 인해 λ°œμƒν•˜λŠ” μ˜€ν•΄λ‚˜ 잘λͺ»λœ 해석에 λŒ€ν•΄ λ‹Ήμ‚¬λŠ” μ±…μž„μ„ μ§€μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.