Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
Python - Merge - Tests / paths-filter (push) Has been cancelled
Python - Merge - Tests / Python Tests - Core (integration, ubuntu-latest, 3.10) (push) Has been cancelled
Python - Merge - Tests / Python Tests - Azure AI (integration, ubuntu-latest, 3.10) (push) Has been cancelled
Python - Merge - Tests / python-integration-tests-check (push) Has been cancelled
Python - Lab Tests / paths-filter (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.10) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.11) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.12) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.13) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.14) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.10) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.11) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.12) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.13) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.14) (push) Has been cancelled
Check .md links / markdown-link-check (push) Has been cancelled
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// This sample shows how to create an agent from a YAML based declarative representation.
|
|
|
|
using Azure.AI.OpenAI;
|
|
using Azure.Identity;
|
|
using Microsoft.Agents.AI;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
|
|
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
|
|
|
|
// Create the chat client
|
|
IChatClient chatClient = new AzureOpenAIClient(
|
|
new Uri(endpoint),
|
|
new AzureCliCredential())
|
|
.GetChatClient(deploymentName)
|
|
.AsIChatClient();
|
|
|
|
// Define the agent using a YAML definition.
|
|
var text =
|
|
"""
|
|
kind: Prompt
|
|
name: Assistant
|
|
description: Helpful assistant
|
|
instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format.
|
|
model:
|
|
options:
|
|
temperature: 0.9
|
|
topP: 0.95
|
|
outputSchema:
|
|
properties:
|
|
language:
|
|
type: string
|
|
required: true
|
|
description: The language of the answer.
|
|
answer:
|
|
type: string
|
|
required: true
|
|
description: The answer text.
|
|
""";
|
|
|
|
// Create the agent from the YAML definition.
|
|
var agentFactory = new ChatClientPromptAgentFactory(chatClient);
|
|
var agent = await agentFactory.CreateFromYamlAsync(text);
|
|
|
|
// Invoke the agent and output the text result.
|
|
Console.WriteLine(await agent!.RunAsync("Tell me a joke about a pirate in English."));
|
|
|
|
// Invoke the agent with streaming support.
|
|
await foreach (var update in agent!.RunStreamingAsync("Tell me a joke about a pirate in French."))
|
|
{
|
|
Console.WriteLine(update);
|
|
}
|