mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Align environment variable names (#1053)
* alignt environment variable names * rename modelId variable names
This commit is contained in:
@@ -20,7 +20,7 @@ The agent urls are provided as a ` ` delimited list of strings
|
||||
```powershell
|
||||
cd dotnet/samples/A2AClientServer/A2AClient
|
||||
|
||||
$env:OPENAI_MODEL_ID="gpt-4o-mini"
|
||||
$env:OPENAI_MODEL="gpt-4o-mini"
|
||||
$env:OPENAI_API_KEY="<Your OPENAI api key>"
|
||||
$env:AGENT_URLS="http://localhost:5000/policy;http://localhost:5000/invoice;http://localhost:5000/logistics"
|
||||
```
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace A2AServer;
|
||||
|
||||
internal static class HostAgentFactory
|
||||
{
|
||||
internal static async Task<A2AHostAgent> CreateFoundryHostAgentAsync(string agentType, string modelId, string endpoint, string assistantId, IList<AITool>? tools = null)
|
||||
internal static async Task<A2AHostAgent> CreateFoundryHostAgentAsync(string agentType, string model, string endpoint, string assistantId, IList<AITool>? tools = null)
|
||||
{
|
||||
var persistentAgentsClient = new PersistentAgentsClient(endpoint, new AzureCliCredential());
|
||||
PersistentAgent persistentAgent = await persistentAgentsClient.Administration.GetAgentAsync(assistantId);
|
||||
@@ -31,10 +31,10 @@ internal static class HostAgentFactory
|
||||
return new A2AHostAgent(agent, agentCard);
|
||||
}
|
||||
|
||||
internal static async Task<A2AHostAgent> CreateChatCompletionHostAgentAsync(string agentType, string modelId, string apiKey, string name, string instructions, IList<AITool>? tools = null)
|
||||
internal static async Task<A2AHostAgent> CreateChatCompletionHostAgentAsync(string agentType, string model, string apiKey, string name, string instructions, IList<AITool>? tools = null)
|
||||
{
|
||||
AIAgent agent = new OpenAIClient(apiKey)
|
||||
.GetChatClient(modelId)
|
||||
.GetChatClient(model)
|
||||
.CreateAIAgent(instructions, name, tools: tools);
|
||||
|
||||
AgentCard agentCard = agentType.ToUpperInvariant() switch
|
||||
|
||||
@@ -36,8 +36,8 @@ IConfigurationRoot configuration = new ConfigurationBuilder()
|
||||
.Build();
|
||||
|
||||
string? apiKey = configuration["OPENAI_API_KEY"];
|
||||
string modelId = configuration["OPENAI_MODEL_ID"] ?? "gpt-4o-mini";
|
||||
string? endpoint = configuration["FOUNDRY_PROJECT_ENDPOINT"];
|
||||
string model = configuration["OPENAI_MODEL"] ?? "gpt-4o-mini";
|
||||
string? endpoint = configuration["AZURE_FOUNDRY_PROJECT_ENDPOINT"];
|
||||
|
||||
var invoiceQueryPlugin = new InvoiceQuery();
|
||||
IList<AITool> tools =
|
||||
@@ -52,9 +52,9 @@ if (!string.IsNullOrEmpty(endpoint) && !string.IsNullOrEmpty(agentId))
|
||||
{
|
||||
hostAgent = agentType.ToUpperInvariant() switch
|
||||
{
|
||||
"INVOICE" => await HostAgentFactory.CreateFoundryHostAgentAsync(agentType, modelId, endpoint, agentId, tools),
|
||||
"POLICY" => await HostAgentFactory.CreateFoundryHostAgentAsync(agentType, modelId, endpoint, agentId),
|
||||
"LOGISTICS" => await HostAgentFactory.CreateFoundryHostAgentAsync(agentType, modelId, endpoint, agentId),
|
||||
"INVOICE" => await HostAgentFactory.CreateFoundryHostAgentAsync(agentType, model, endpoint, agentId, tools),
|
||||
"POLICY" => await HostAgentFactory.CreateFoundryHostAgentAsync(agentType, model, endpoint, agentId),
|
||||
"LOGISTICS" => await HostAgentFactory.CreateFoundryHostAgentAsync(agentType, model, endpoint, agentId),
|
||||
_ => throw new ArgumentException($"Unsupported agent type: {agentType}"),
|
||||
};
|
||||
}
|
||||
@@ -63,12 +63,12 @@ else if (!string.IsNullOrEmpty(apiKey))
|
||||
hostAgent = agentType.ToUpperInvariant() switch
|
||||
{
|
||||
"INVOICE" => await HostAgentFactory.CreateChatCompletionHostAgentAsync(
|
||||
agentType, modelId, apiKey, "InvoiceAgent",
|
||||
agentType, model, apiKey, "InvoiceAgent",
|
||||
"""
|
||||
You specialize in handling queries related to invoices.
|
||||
""", tools),
|
||||
"POLICY" => await HostAgentFactory.CreateChatCompletionHostAgentAsync(
|
||||
agentType, modelId, apiKey, "PolicyAgent",
|
||||
agentType, model, apiKey, "PolicyAgent",
|
||||
"""
|
||||
You specialize in handling queries related to policies and customer communications.
|
||||
|
||||
@@ -84,7 +84,7 @@ else if (!string.IsNullOrEmpty(apiKey))
|
||||
template."
|
||||
"""),
|
||||
"LOGISTICS" => await HostAgentFactory.CreateChatCompletionHostAgentAsync(
|
||||
agentType, modelId, apiKey, "LogisticsAgent",
|
||||
agentType, model, apiKey, "LogisticsAgent",
|
||||
"""
|
||||
You specialize in handling queries related to logistics.
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ You must create the agents in an Azure AI Foundry project and then provide the p
|
||||
```
|
||||
|
||||
```powershell
|
||||
$env:FOUNDRY_PROJECT_ENDPOINT="https://ai-foundry-your-project.services.ai.azure.com/api/projects/ai-proj-ga-your-project" # Replace with your Foundry Project endpoint
|
||||
$env:AZURE_FOUNDRY_PROJECT_ENDPOINT="https://ai-foundry-your-project.services.ai.azure.com/api/projects/ai-proj-ga-your-project" # Replace with your Foundry Project endpoint
|
||||
```
|
||||
|
||||
Use the following commands to run each A2A server
|
||||
|
||||
@@ -12,7 +12,7 @@ using Microsoft.Agents.AI;
|
||||
using OpenAI;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_APIKEY") ?? throw new InvalidOperationException("OPENAI_APIKEY is not set.");
|
||||
var mmodel = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o-mini";
|
||||
var model = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o-mini";
|
||||
|
||||
const string JokerName = "Joker";
|
||||
const string JokerInstructions = "You are good at telling jokes.";
|
||||
@@ -21,14 +21,14 @@ const string JokerInstructions = "You are good at telling jokes.";
|
||||
var assistantClient = new OpenAIClient(apiKey).GetAssistantClient();
|
||||
|
||||
// You can create a server side assistant with the OpenAI SDK.
|
||||
var createResult = await assistantClient.CreateAssistantAsync(mmodel, new() { Name = JokerName, Instructions = JokerInstructions });
|
||||
var createResult = await assistantClient.CreateAssistantAsync(model, new() { Name = JokerName, Instructions = JokerInstructions });
|
||||
|
||||
// You can retrieve an already created server side assistant as an AIAgent.
|
||||
AIAgent agent1 = await assistantClient.GetAIAgentAsync(createResult.Value.Id);
|
||||
|
||||
// You can also create a server side assistant and return it as an AIAgent directly.
|
||||
AIAgent agent2 = await assistantClient.CreateAIAgentAsync(
|
||||
model: mmodel,
|
||||
model: model,
|
||||
name: JokerName,
|
||||
instructions: JokerInstructions);
|
||||
|
||||
|
||||
+2
-2
@@ -7,14 +7,14 @@ using Microsoft.Agents.AI;
|
||||
using OpenAI;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_APIKEY") ?? throw new InvalidOperationException("OPENAI_APIKEY is not set.");
|
||||
var modelName = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o-mini";
|
||||
var model = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o-mini";
|
||||
|
||||
const string JokerName = "Joker";
|
||||
const string JokerInstructions = "You are good at telling jokes.";
|
||||
|
||||
AIAgent agent = new OpenAIClient(
|
||||
apiKey)
|
||||
.GetChatClient(modelName)
|
||||
.GetChatClient(model)
|
||||
.CreateAIAgent(JokerInstructions, JokerName);
|
||||
|
||||
// Invoke the agent and output the text result.
|
||||
|
||||
@@ -9,14 +9,14 @@ using Microsoft.Agents.AI;
|
||||
using OpenAI;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_APIKEY") ?? throw new InvalidOperationException("OPENAI_APIKEY is not set.");
|
||||
var modelName = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o-mini";
|
||||
var model = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o-mini";
|
||||
|
||||
const string JokerName = "Joker";
|
||||
const string JokerInstructions = "You are good at telling jokes.";
|
||||
|
||||
AIAgent agent = new OpenAIClient(
|
||||
apiKey)
|
||||
.GetOpenAIResponseClient(modelName)
|
||||
.GetOpenAIResponseClient(model)
|
||||
.CreateAIAgent(JokerInstructions, JokerName);
|
||||
|
||||
// Invoke the agent and output the text result.
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Demo.DeclarativeWorkflow;
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <b>Configuration</b>
|
||||
/// Define FOUNDRY_PROJECT_ENDPOINT as a user-secret or environment variable that
|
||||
/// Define AZURE_FOUNDRY_PROJECT_ENDPOINT as a user-secret or environment variable that
|
||||
/// points to your Foundry project endpoint.
|
||||
/// <b>Usage</b>
|
||||
/// Provide the path to the workflow definition file as the first argument.
|
||||
|
||||
@@ -16,7 +16,7 @@ You can also use environment variables if you prefer.
|
||||
To set your secrets as an environment variable (PowerShell):
|
||||
|
||||
```pwsh
|
||||
$env:FOUNDRY_PROJECT_ENDPOINT="https://..."
|
||||
$env:AZURE_FOUNDRY_PROJECT_ENDPOINT="https://..."
|
||||
```
|
||||
|
||||
To set your secrets with .NET Secret Manager:
|
||||
@@ -42,7 +42,7 @@ To set your secrets with .NET Secret Manager:
|
||||
4. Define setting that identifies your Azure Foundry Project (endpoint):
|
||||
|
||||
```
|
||||
dotnet user-secrets set "FOUNDRY_PROJECT_ENDPOINT" "https://..."
|
||||
dotnet user-secrets set "AZURE_FOUNDRY_PROJECT_ENDPOINT" "https://..."
|
||||
```
|
||||
|
||||
#### Authorization
|
||||
@@ -61,7 +61,7 @@ The sample workflows rely on agents defined in your Azure Foundry Project.
|
||||
To create agents, run the [`Create.ps1`](../../../../../workflows/) script.
|
||||
This will create the agents used in the sample workflows in your Azure Foundry Project and format a script you can copy and use to configure your environment.
|
||||
|
||||
> Note: `Create.ps1` relies upon the `FOUNDRY_PROJECT_ENDPOINT` setting.
|
||||
> Note: `Create.ps1` relies upon the `AZURE_FOUNDRY_PROJECT_ENDPOINT` setting.
|
||||
|
||||
## Execution
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using Microsoft.SemanticKernel.Connectors.OpenAI;
|
||||
using OpenAI;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
@@ -19,7 +19,7 @@ async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(modelId, apiKey);
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(model, apiKey);
|
||||
|
||||
var agent = new ChatCompletionAgent()
|
||||
{
|
||||
@@ -48,7 +48,7 @@ async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
var agent = new OpenAIClient(apiKey).GetChatClient(modelId)
|
||||
var agent = new OpenAIClient(apiKey).GetChatClient(model)
|
||||
.CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes.");
|
||||
|
||||
var thread = agent.GetNewThread();
|
||||
|
||||
@@ -7,7 +7,7 @@ using Microsoft.SemanticKernel.Agents;
|
||||
using OpenAI;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "What is the weather like in Amsterdam?";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
@@ -22,7 +22,7 @@ await AFAgentAsync();
|
||||
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(modelId, apiKey);
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(model, apiKey);
|
||||
|
||||
ChatCompletionAgent agent = new()
|
||||
{
|
||||
@@ -42,7 +42,7 @@ async Task SKAgentAsync()
|
||||
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
var agent = new OpenAIClient(apiKey).GetChatClient(modelId).CreateAIAgent(
|
||||
var agent = new OpenAIClient(apiKey).GetChatClient(model).CreateAIAgent(
|
||||
instructions: "You are a helpful assistant",
|
||||
tools: [AIFunctionFactory.Create(GetWeather)]);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ using Microsoft.SemanticKernel.Agents;
|
||||
using OpenAI;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
@@ -21,7 +21,7 @@ async Task SKAgentAsync()
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddKernel().AddOpenAIChatClient(modelId, apiKey);
|
||||
serviceCollection.AddKernel().AddOpenAIChatClient(model, apiKey);
|
||||
serviceCollection.AddTransient((sp) => new ChatCompletionAgent()
|
||||
{
|
||||
Kernel = sp.GetRequiredService<Kernel>(),
|
||||
@@ -42,7 +42,7 @@ async Task AFAgentAsync()
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddTransient((sp) => new OpenAIClient(apiKey)
|
||||
.GetChatClient(modelId)
|
||||
.GetChatClient(model)
|
||||
.CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."));
|
||||
|
||||
await using ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
@@ -9,7 +9,7 @@ using OpenAI;
|
||||
using OpenAI.Assistants;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
@@ -24,7 +24,7 @@ async Task SKAgentAsync()
|
||||
var assistantsClient = new AssistantClient(apiKey);
|
||||
|
||||
// Define the assistant
|
||||
Assistant assistant = await assistantsClient.CreateAssistantAsync(modelId, name: "Joker", instructions: "You are good at telling jokes.");
|
||||
Assistant assistant = await assistantsClient.CreateAssistantAsync(model, name: "Joker", instructions: "You are good at telling jokes.");
|
||||
|
||||
// Create the agent
|
||||
OpenAIAssistantAgent agent = new(assistant, assistantsClient);
|
||||
@@ -56,7 +56,7 @@ async Task AFAgentAsync()
|
||||
|
||||
var assistantClient = new AssistantClient(apiKey);
|
||||
|
||||
var agent = await assistantClient.CreateAIAgentAsync(modelId, name: "Joker", instructions: "You are good at telling jokes.");
|
||||
var agent = await assistantClient.CreateAIAgentAsync(model, name: "Joker", instructions: "You are good at telling jokes.");
|
||||
|
||||
var thread = agent.GetNewThread();
|
||||
var agentOptions = new ChatClientAgentRunOptions(new() { MaxOutputTokens = 1000 });
|
||||
|
||||
@@ -12,7 +12,7 @@ using OpenAI;
|
||||
using OpenAI.Assistants;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "What is the weather like in Amsterdam?";
|
||||
|
||||
[KernelFunction]
|
||||
@@ -32,7 +32,7 @@ async Task SKAgentAsync()
|
||||
var builder = Kernel.CreateBuilder();
|
||||
var assistantsClient = new AssistantClient(apiKey);
|
||||
|
||||
Assistant assistant = await assistantsClient.CreateAssistantAsync(modelId,
|
||||
Assistant assistant = await assistantsClient.CreateAssistantAsync(model,
|
||||
instructions: "You are a helpful assistant");
|
||||
|
||||
OpenAIAssistantAgent agent = new(assistant, assistantsClient)
|
||||
@@ -73,7 +73,7 @@ async Task AFAgentAsync()
|
||||
|
||||
var assistantClient = new AssistantClient(apiKey);
|
||||
|
||||
var agent = await assistantClient.CreateAIAgentAsync(modelId,
|
||||
var agent = await assistantClient.CreateAIAgentAsync(model,
|
||||
instructions: "You are a helpful assistant",
|
||||
tools: [AIFunctionFactory.Create(GetWeather)]);
|
||||
|
||||
|
||||
+4
-4
@@ -11,7 +11,7 @@ using OpenAI;
|
||||
using OpenAI.Assistants;
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
@@ -25,12 +25,12 @@ async Task SKAgentAsync()
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddSingleton((sp) => new AssistantClient(apiKey));
|
||||
serviceCollection.AddKernel().AddOpenAIChatClient(modelId, apiKey);
|
||||
serviceCollection.AddKernel().AddOpenAIChatClient(model, apiKey);
|
||||
serviceCollection.AddTransient((sp) =>
|
||||
{
|
||||
var assistantsClient = sp.GetRequiredService<AssistantClient>();
|
||||
|
||||
Assistant assistant = assistantsClient.CreateAssistant(modelId, new() { Name = "Joker", Instructions = "You are good at telling jokes." });
|
||||
Assistant assistant = assistantsClient.CreateAssistant(model, new() { Name = "Joker", Instructions = "You are good at telling jokes." });
|
||||
|
||||
return new OpenAIAssistantAgent(assistant, assistantsClient);
|
||||
});
|
||||
@@ -70,7 +70,7 @@ async Task AFAgentAsync()
|
||||
{
|
||||
var assistantClient = sp.GetRequiredService<AssistantClient>();
|
||||
|
||||
return assistantClient.CreateAIAgent(modelId, name: "Joker", instructions: "You are good at telling jokes.");
|
||||
return assistantClient.CreateAIAgent(model, name: "Joker", instructions: "You are good at telling jokes.");
|
||||
});
|
||||
|
||||
await using ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@ using OpenAI.Assistants;
|
||||
#pragma warning disable CS8321 // Local function is declared but never used
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "Create a python code file using the code interpreter tool with a code ready to determine the values in the Fibonacci sequence that are less then the value of 101";
|
||||
|
||||
var assistantsClient = new AssistantClient(apiKey);
|
||||
@@ -28,7 +28,7 @@ async Task SKAgentAsync()
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
// Define the assistant
|
||||
Assistant assistant = await assistantsClient.CreateAssistantAsync(modelId, enableCodeInterpreter: true);
|
||||
Assistant assistant = await assistantsClient.CreateAssistantAsync(model, enableCodeInterpreter: true);
|
||||
|
||||
// Create the agent
|
||||
OpenAIAssistantAgent agent = new(assistant, assistantsClient);
|
||||
@@ -74,7 +74,7 @@ async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
var agent = await assistantsClient.CreateAIAgentAsync(modelId, tools: [new HostedCodeInterpreterTool()]);
|
||||
var agent = await assistantsClient.CreateAIAgentAsync(model, tools: [new HostedCodeInterpreterTool()]);
|
||||
|
||||
var thread = agent.GetNewThread();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ using OpenAI;
|
||||
#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.
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
@@ -20,7 +20,7 @@ async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
var responseClient = new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId);
|
||||
var responseClient = new OpenAIClient(apiKey).GetOpenAIResponseClient(model);
|
||||
OpenAIResponseAgent agent = new(responseClient)
|
||||
{
|
||||
Name = "Joker",
|
||||
@@ -50,7 +50,7 @@ async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
var agent = new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId)
|
||||
var agent = new OpenAIClient(apiKey).GetOpenAIResponseClient(model)
|
||||
.CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes.");
|
||||
|
||||
var thread = agent.GetNewThread();
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@ using OpenAI;
|
||||
#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.
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "o4-mini";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "o4-mini";
|
||||
var userInput =
|
||||
"""
|
||||
Instructions:
|
||||
@@ -47,7 +47,7 @@ async Task SKAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== SK Agent ===\n");
|
||||
|
||||
var responseClient = new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId);
|
||||
var responseClient = new OpenAIClient(apiKey).GetOpenAIResponseClient(model);
|
||||
OpenAIResponseAgent agent = new(responseClient)
|
||||
{
|
||||
Name = "Thinker",
|
||||
@@ -115,7 +115,7 @@ async Task AFAgentAsync()
|
||||
{
|
||||
Console.WriteLine("\n=== AF Agent ===\n");
|
||||
|
||||
var agent = new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId)
|
||||
var agent = new OpenAIClient(apiKey).GetOpenAIResponseClient(model)
|
||||
.CreateAIAgent(name: "Thinker", instructions: "You are at thinking hard before answering.");
|
||||
|
||||
var thread = agent.GetNewThread();
|
||||
|
||||
@@ -9,7 +9,7 @@ using OpenAI;
|
||||
#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.
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "What is the weather like in Amsterdam?";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
@@ -24,9 +24,9 @@ await AFAgentAsync();
|
||||
|
||||
async Task SKAgentAsync()
|
||||
{
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(modelId, apiKey);
|
||||
var builder = Kernel.CreateBuilder().AddOpenAIChatClient(model, apiKey);
|
||||
|
||||
OpenAIResponseAgent agent = new(new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId));
|
||||
OpenAIResponseAgent agent = new(new OpenAIClient(apiKey).GetOpenAIResponseClient(model));
|
||||
|
||||
// Initialize plugin and add to the agent's Kernel (same as direct Kernel usage).
|
||||
agent.Kernel.Plugins.Add(KernelPluginFactory.CreateFromFunctions("KernelPluginName", [KernelFunctionFactory.CreateFromMethod(GetWeather)]));
|
||||
@@ -44,7 +44,7 @@ async Task SKAgentAsync()
|
||||
|
||||
async Task AFAgentAsync()
|
||||
{
|
||||
var agent = new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId).CreateAIAgent(
|
||||
var agent = new OpenAIClient(apiKey).GetOpenAIResponseClient(model).CreateAIAgent(
|
||||
instructions: "You are a helpful assistant",
|
||||
tools: [AIFunctionFactory.Create(GetWeather)]);
|
||||
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ using OpenAI;
|
||||
#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.
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY") ?? throw new InvalidOperationException("OPENAI_API_KEY is not set.");
|
||||
var modelId = System.Environment.GetEnvironmentVariable("OPENAI_MODELID") ?? "gpt-4o";
|
||||
var model = System.Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
|
||||
var userInput = "Tell me a joke about a pirate.";
|
||||
|
||||
Console.WriteLine($"User Input: {userInput}");
|
||||
@@ -23,7 +23,7 @@ async Task SKAgentAsync()
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddTransient<Microsoft.SemanticKernel.Agents.Agent>((sp)
|
||||
=> new OpenAIResponseAgent(new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId))
|
||||
=> new OpenAIResponseAgent(new OpenAIClient(apiKey).GetOpenAIResponseClient(model))
|
||||
{
|
||||
Name = "Joker",
|
||||
Instructions = "You are good at telling jokes."
|
||||
@@ -42,7 +42,7 @@ async Task AFAgentAsync()
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddTransient((sp) => new OpenAIClient(apiKey)
|
||||
.GetOpenAIResponseClient(modelId)
|
||||
.GetOpenAIResponseClient(model)
|
||||
.CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."));
|
||||
|
||||
await using ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
@@ -24,4 +24,4 @@ The sample workflows rely on agents defined in your Azure Foundry Project.
|
||||
To create agents, run the [`Create.ps1`](./setup) script.
|
||||
This will create the agents used in the sample workflows in your Azure Foundry Project and format a script you can copy and use to configure your environment.
|
||||
|
||||
> Note: `Create.ps1` relies upon the `FOUNDRY_PROJECT_ENDPOINT` setting. See [README.md](../dotnet/demos/DeclarativeWorkflow/README.md) from the demo for configuration details.
|
||||
> Note: `Create.ps1` relies upon the `AZURE_FOUNDRY_PROJECT_ENDPOINT` setting. See [README.md](../dotnet/demos/DeclarativeWorkflow/README.md) from the demo for configuration details.
|
||||
|
||||
Reference in New Issue
Block a user