ai-agents-for-beginners

🌍 Microsoft Agent Framework (.NET)తో AI ప్రయాణ ఏజెంట్

📋 దృశ్యం అవలోకనం

ఈ ఉదాహరణ Microsoft Agent Framework ఉపయోగించి .NET కోసం బుద్ధిమంతమైన ప్రయాణ ప్రణాళిక ఏజెంట్‌ను ఎలా నిర్మించాలో చూపిస్తుంది. ఏజెంట్ ప్రపంథం అంతటా యాదృచ్ఛిక గమ్యస్థానాల కోసం వ్యక్తిగతీకరించిన దిన-యాత్ర మార్గనిర్దేశకాలను ఆటోమేటిక్‌గా తయారుచేయగలదు.

ప్రధాన సామర్థ్యాలు:

🔧 సాంకేతిక నిర్మాణం

ప్రాథమిక సాంకేతికతలు

కీలక భాగాలు

  1. AIAgent: సంభాషణ ప్రవాహాన్ని నిర్వహించే ప్రధాన ఏజెంట్ ఆర్కెస్ట్రేటర్
  2. అనుకూల సాధనాలు: ఏజెంట్‌కు అందుబాటులో ఉన్న GetRandomDestination() ఫంక్షన్
  3. ప్రత్యుత్తర క్లయింట్: Azure OpenAI Responses ఆధారిత సంభాషణ ఇంటర్‌ఫేస్
  4. స్ట్రీమింగ్ మద్దతు: రియల్-టైం ప్రత్యుత్తరాల సృష్టి సామర్థ్యాలు

ఇంటిగ్రేషన్ ప్యాటర్న్

graph LR
    A[వాడుకరి అభ్యర్థన] --> B[AI ఏజెంట్]
    B --> C[Azure OpenAI (ప్రత్యుత్తరాలు API)]
    B --> D[GetRandomDestination టూల్]
    C --> E[ప్రయాణ క్రమవివరణ]
    D --> E

🚀 ప్రారంభించండి

ముందస్తు అవసరాలు

అవసరమైన పరిసర వేరియబుల్స్

# zsh/bash
export AZURE_OPENAI_ENDPOINT=https://<your-resource>.openai.azure.com
export AZURE_OPENAI_DEPLOYMENT=gpt-4.1-mini
# అప్పుడు సైన్ ఇన్ అవ్వండి כדי AzureCliCredential టోకెన్ పొందడానికి
az login
# పవర్‌షెల్
$env:AZURE_OPENAI_ENDPOINT = "https://<your-resource>.openai.azure.com"
$env:AZURE_OPENAI_DEPLOYMENT = "gpt-4.1-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-4.1-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 ఉపయోగించి అనువదించబడింది. మేము ఖచ్చితత్వానికి ప్రయత్నిస్తున్నప్పటికీ, ఆటోమేటెడ్ అనువాదాలు తప్పులు లేదా అసమగ్రతలను కలిగి ఉండవచ్చు. దాని స్వదేశ భాషలో ఉన్న అసలు పత్రాన్ని అధికారం కలిగిన మూలంగా పరిగణించాలి. కీలకమైన సమాచారం కోసం, ప్రొఫెషనల్ మానవ అనువాదాన్ని సిఫారసు చేస్తాము. ఈ అనువాదం ఉపయోగం వల్ల కలిగే ఏవైనా అపార్థాలు లేదా తప్పుదారులు కోసం మేము బాధ్యత వహించము.