From 523127fbf47aceb19ca41d31ac2f0cc6703efb35 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Wed, 8 Oct 2025 11:56:34 +0100 Subject: [PATCH] Update readme.md sample to show sample parameter values and switch to openai sdk (#1265) * Update readme.md sample to show sample parameter values and make azure sdk pre-release * Add clarifying comment about params. * Switch sample to use the OpenAI SDK --- README.md | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dfdf896922..30d9ab2bdd 100644 --- a/README.md +++ b/README.md @@ -119,22 +119,35 @@ if __name__ == "__main__": ### Basic Agent - .NET +Create a simple Agent, using OpenAI Responses, that writes a haiku about the Microsoft Agent Framework + +```c# +// dotnet add package Microsoft.Agents.AI.OpenAI --prerelease +using System; +using OpenAI; + +// Replace the with your OpenAI API key. +var agent = new OpenAIClient("") + .GetOpenAIResponseClient("gpt-4o-mini") + .CreateAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully."); + +Console.WriteLine(await agent.RunAsync("Write a haiku about Microsoft Agent Framework.")); +``` + +Create a simple Agent, using Azure OpenAI Responses with token based auth, that writes a haiku about the Microsoft Agent Framework + ```c# // dotnet add package Microsoft.Agents.AI.OpenAI --prerelease -// dotnet add package Azure.AI.OpenAI // dotnet add package Azure.Identity // Use `az login` to authenticate with Azure CLI using System; -using Azure.AI.OpenAI; -using Azure.Identity; -using Microsoft.Agents.AI; using OpenAI; -var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!; -var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME")!; - -var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) - .GetOpenAIResponseClient(deploymentName) +// Replace and gpt-4o-mini with your Azure OpenAI resource name and deployment name. +var agent = new OpenAIClient( + new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), + new OpenAIClientOptions() { Endpoint = new Uri("https://.openai.azure.com/openai/v1") }) + .GetOpenAIResponseClient("gpt-4o-mini") .CreateAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully."); Console.WriteLine(await agent.RunAsync("Write a haiku about Microsoft Agent Framework."));