mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Enable more analyzers and various code tweaks/cleanup (#738)
This commit is contained in:
committed by
GitHub
Unverified
parent
f3264966ff
commit
5e5761b288
@@ -14,10 +14,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -47,7 +47,7 @@ async Task SKAgent()
|
||||
await azureAgentClient.Administration.DeleteAgentAsync(agent.Id);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ Console.WriteLine($"User Input: {userInput}");
|
||||
static string GetWeather([Description("The location to get the weather for.")] string location)
|
||||
=> $"The weather in {location} is cloudy with a high of 15°C.";
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -59,7 +59,7 @@ async Task SKAgent()
|
||||
await azureAgentClient.Administration.DeleteAgentAsync(agent.Id);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
+5
-7
@@ -16,10 +16,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -61,7 +61,7 @@ async Task SKAgent()
|
||||
await agent.Client.Administration.DeleteAgentAsync(agent.Id);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
@@ -71,12 +71,10 @@ async Task AFAgent()
|
||||
{
|
||||
var azureAgentClient = sp.GetRequiredService<PersistentAgentsClient>();
|
||||
|
||||
var aiAgent = azureAgentClient.CreateAIAgent(
|
||||
return azureAgentClient.CreateAIAgent(
|
||||
deploymentName,
|
||||
name: "GenerateStory",
|
||||
instructions: "You are good at telling jokes.");
|
||||
|
||||
return aiAgent;
|
||||
});
|
||||
|
||||
await using ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
+4
-4
@@ -17,10 +17,10 @@ var userInput = "Create a python code file using the code interpreter tool with
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -65,7 +65,7 @@ async Task SKAgent()
|
||||
await azureAgentClient.Administration.DeleteAgentAsync(agent.Id);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
+4
-4
@@ -15,10 +15,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -46,7 +46,7 @@ async Task SKAgent()
|
||||
}
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
+4
-4
@@ -42,10 +42,10 @@ var userInput =
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -111,7 +111,7 @@ async Task SKAgent()
|
||||
}
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
+4
-4
@@ -21,10 +21,10 @@ Console.WriteLine($"User Input: {userInput}");
|
||||
static string GetWeather([Description("The location to get the weather for.")] string location)
|
||||
=> $"The weather in {location} is cloudy with a high of 15°C.";
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
OpenAIResponseAgent agent = new(new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
|
||||
.GetOpenAIResponseClient(deploymentName));
|
||||
@@ -43,7 +43,7 @@ async Task SKAgent()
|
||||
}
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
|
||||
.GetOpenAIResponseClient(deploymentName)
|
||||
|
||||
+4
-4
@@ -16,10 +16,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -39,7 +39,7 @@ async Task SKAgent()
|
||||
Console.WriteLine(result.Message);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -44,7 +44,7 @@ async Task SKAgent()
|
||||
}
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ Console.WriteLine($"User Input: {userInput}");
|
||||
static string GetWeather([Description("The location to get the weather for.")] string location)
|
||||
=> $"The weather in {location} is cloudy with a high of 15°C.";
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(modelId, apiKey);
|
||||
|
||||
@@ -40,7 +40,7 @@ async Task SKAgent()
|
||||
Console.WriteLine(result.Message);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
var agent = new OpenAIClient(apiKey).GetChatClient(modelId).CreateAIAgent(
|
||||
instructions: "You are a helpful assistant",
|
||||
|
||||
@@ -13,10 +13,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -36,7 +36,7 @@ async Task SKAgent()
|
||||
Console.WriteLine(result.Message);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#pragma warning disable OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
|
||||
|
||||
using Microsoft.Extensions.AI.Agents;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Microsoft.SemanticKernel.Agents.OpenAI;
|
||||
using Microsoft.SemanticKernel.Connectors.OpenAI;
|
||||
using OpenAI;
|
||||
@@ -15,15 +14,13 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(modelId, apiKey);
|
||||
|
||||
var assistantsClient = new AssistantClient(apiKey);
|
||||
|
||||
// Define the assistant
|
||||
@@ -53,7 +50,7 @@ async Task SKAgent()
|
||||
await assistantsClient.DeleteAssistantAsync(agent.Id);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ static string GetWeather([Description("The location to get the weather for.")] s
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -67,7 +67,7 @@ async Task SKAgent()
|
||||
await assistantsClient.DeleteAssistantAsync(agent.Id);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
+5
-7
@@ -16,10 +16,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -60,7 +60,7 @@ async Task SKAgent()
|
||||
await assistantsClient.DeleteAssistantAsync(agent.Id);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
@@ -70,9 +70,7 @@ async Task AFAgent()
|
||||
{
|
||||
var assistantClient = sp.GetRequiredService<AssistantClient>();
|
||||
|
||||
var agent = assistantClient.CreateAIAgent(modelId, name: "Joker", instructions: "You are good at telling jokes.");
|
||||
|
||||
return agent;
|
||||
return assistantClient.CreateAIAgent(modelId, name: "Joker", instructions: "You are good at telling jokes.");
|
||||
});
|
||||
|
||||
await using ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
+4
-6
@@ -19,15 +19,13 @@ var assistantsClient = new AssistantClient(apiKey);
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(modelId, apiKey);
|
||||
|
||||
// Define the assistant
|
||||
Assistant assistant = await assistantsClient.CreateAssistantAsync(modelId, enableCodeInterpreter: true);
|
||||
|
||||
@@ -71,7 +69,7 @@ async Task SKAgent()
|
||||
await assistantsClient.DeleteAssistantAsync(agent.Id);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -43,7 +43,7 @@ async Task SKAgent()
|
||||
}
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
+4
-4
@@ -40,10 +40,10 @@ var userInput =
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -108,7 +108,7 @@ async Task SKAgent()
|
||||
}
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ Console.WriteLine($"User Input: {userInput}");
|
||||
static string GetWeather([Description("The location to get the weather for.")] string location)
|
||||
=> $"The weather in {location} is cloudy with a high of 15°C.";
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(modelId, apiKey);
|
||||
|
||||
@@ -42,7 +42,7 @@ async Task SKAgent()
|
||||
}
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
var agent = new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId).CreateAIAgent(
|
||||
instructions: "You are a helpful assistant",
|
||||
|
||||
+4
-4
@@ -14,10 +14,10 @@ var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
|
||||
await SKAgent();
|
||||
await AFAgent();
|
||||
await SKAgentAsync();
|
||||
await AFAgentAsync();
|
||||
|
||||
async Task SKAgent()
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
@@ -36,7 +36,7 @@ async Task SKAgent()
|
||||
Console.WriteLine(result.Message);
|
||||
}
|
||||
|
||||
async Task AFAgent()
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user