diff --git a/agent-samples/azure/AzureOpenAIAssistants.yaml b/agent-samples/azure/AzureOpenAIAssistants.yaml index f973d05acc..cf934ded5f 100644 --- a/agent-samples/azure/AzureOpenAIAssistants.yaml +++ b/agent-samples/azure/AzureOpenAIAssistants.yaml @@ -3,7 +3,7 @@ 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. You must include Assistants as the type in your response. model: - id: gpt-4o-mini + id: =Env.AZURE_OPENAI_DEPLOYMENT_NAME provider: AzureOpenAI apiType: Assistants options: diff --git a/agent-samples/azure/AzureOpenAIChat.yaml b/agent-samples/azure/AzureOpenAIChat.yaml index d02e0c6039..8272b908ad 100644 --- a/agent-samples/azure/AzureOpenAIChat.yaml +++ b/agent-samples/azure/AzureOpenAIChat.yaml @@ -3,7 +3,7 @@ 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. You must include Chat as the type in your response. model: - id: gpt-4o-mini + id: =Env.AZURE_OPENAI_DEPLOYMENT_NAME provider: AzureOpenAI apiType: Chat options: diff --git a/agent-samples/azure/AzureOpenAIResponses.yaml b/agent-samples/azure/AzureOpenAIResponses.yaml index 006c1476f4..f29a7b7bbb 100644 --- a/agent-samples/azure/AzureOpenAIResponses.yaml +++ b/agent-samples/azure/AzureOpenAIResponses.yaml @@ -3,7 +3,7 @@ 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. You must include Responses as the type in your response. model: - id: gpt-4o-mini + id: =Env.AZURE_OPENAI_DEPLOYMENT_NAME provider: AzureOpenAI apiType: Responses options: diff --git a/agent-samples/foundry/PersistentAgent.yaml b/agent-samples/foundry/PersistentAgent.yaml index 2de2ea069e..5ff4514dd8 100644 --- a/agent-samples/foundry/PersistentAgent.yaml +++ b/agent-samples/foundry/PersistentAgent.yaml @@ -3,7 +3,7 @@ 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: - id: gpt-4.1-mini + id: =Env.AZURE_FOUNDRY_PROJECT_MODEL_ID options: temperature: 0.9 topP: 0.95 diff --git a/agent-samples/openai/OpenAIAssistants.yaml b/agent-samples/openai/OpenAIAssistants.yaml index c1f20beb38..867639aa22 100644 --- a/agent-samples/openai/OpenAIAssistants.yaml +++ b/agent-samples/openai/OpenAIAssistants.yaml @@ -3,7 +3,7 @@ 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. You must include Assistants as the type in your response. model: - id: gpt-4.1-mini + id: =Env.OPENAI_MODEL provider: OpenAI apiType: Assistants options: diff --git a/agent-samples/openai/OpenAIChat.yaml b/agent-samples/openai/OpenAIChat.yaml index 832ef4eb15..135bf8602b 100644 --- a/agent-samples/openai/OpenAIChat.yaml +++ b/agent-samples/openai/OpenAIChat.yaml @@ -3,7 +3,7 @@ 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. You must include Chat as the type in your response. model: - id: gpt-4.1-mini + id: =Env.OPENAI_MODEL provider: OpenAI apiType: Chat options: diff --git a/agent-samples/openai/OpenAIResponses.yaml b/agent-samples/openai/OpenAIResponses.yaml index efe822233e..78f331eea2 100644 --- a/agent-samples/openai/OpenAIResponses.yaml +++ b/agent-samples/openai/OpenAIResponses.yaml @@ -3,7 +3,7 @@ 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. You must include Responses as the type in your response. model: - id: gpt-4.1-mini + id: =Env.OPENAI_MODEL provider: OpenAI apiType: Responses options: diff --git a/dotnet/samples/GettingStarted/DeclarativeAgents/Azure/Program.cs b/dotnet/samples/GettingStarted/DeclarativeAgents/Azure/Program.cs index 1231484c77..213cbf7815 100644 --- a/dotnet/samples/GettingStarted/DeclarativeAgents/Azure/Program.cs +++ b/dotnet/samples/GettingStarted/DeclarativeAgents/Azure/Program.cs @@ -8,6 +8,7 @@ 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"; // Read command-line arguments if (args.Length < 2) @@ -31,6 +32,9 @@ if (!File.Exists(yamlFilePath)) // Read the YAML content from the file var text = await File.ReadAllTextAsync(yamlFilePath); +// TODO: Remove this workaround when the agent framework supports environment variable substitution in YAML files. +text = text.Replace("=Env.AZURE_OPENAI_DEPLOYMENT_NAME", deploymentName, StringComparison.OrdinalIgnoreCase); + var endpointUri = new Uri(endpoint); var tokenCredential = new AzureCliCredential(); diff --git a/dotnet/samples/GettingStarted/DeclarativeAgents/Azure/Properties/launchSettings.json b/dotnet/samples/GettingStarted/DeclarativeAgents/Azure/Properties/launchSettings.json deleted file mode 100644 index 3c1b8c8325..0000000000 --- a/dotnet/samples/GettingStarted/DeclarativeAgents/Azure/Properties/launchSettings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "profiles": { - "Chat": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\azure\\AzureOpenAIChat.yaml \"What is the weather in Cambridge, MA in °C?\"" - }, - "Responses": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\azure\\AzureOpenAIResponses.yaml \"What is the weather in Cambridge, MA in °C?\"" - }, - "Assistants": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\azure\\AzureOpenAIAssistants.yaml \"What is the weather in Cambridge, MA in °C?\"" - } - } -} \ No newline at end of file diff --git a/dotnet/samples/GettingStarted/DeclarativeAgents/ChatClient/Properties/launchSettings.json b/dotnet/samples/GettingStarted/DeclarativeAgents/ChatClient/Properties/launchSettings.json deleted file mode 100644 index 5ec486626c..0000000000 --- a/dotnet/samples/GettingStarted/DeclarativeAgents/ChatClient/Properties/launchSettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "profiles": { - "GetWeather": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\chatclient\\GetWeather.yaml \"What is the weather in Cambridge, MA in °C?\"" - }, - "Assistant": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\chatclient\\Assistant.yaml \"Tell me a joke about a pirate in Italian.\"" - } - } -} \ No newline at end of file diff --git a/dotnet/samples/GettingStarted/DeclarativeAgents/Foundry/Program.cs b/dotnet/samples/GettingStarted/DeclarativeAgents/Foundry/Program.cs index e04070da16..68a78fe01e 100644 --- a/dotnet/samples/GettingStarted/DeclarativeAgents/Foundry/Program.cs +++ b/dotnet/samples/GettingStarted/DeclarativeAgents/Foundry/Program.cs @@ -6,9 +6,9 @@ using System.ComponentModel; using Azure.Identity; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; -using Microsoft.Extensions.Configuration; var endpoint = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_FOUNDRY_PROJECT_ENDPOINT is not set."); +var model = Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_MODEL_ID") ?? "gpt-4.1-mini"; // Read command-line arguments if (args.Length < 2) @@ -32,13 +32,9 @@ if (!File.Exists(yamlFilePath)) // Read the YAML content from the file var text = await File.ReadAllTextAsync(yamlFilePath); -// Set up configuration with the Azure Foundry project endpoint -IConfiguration configuration = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - ["AZURE_FOUNDRY_PROJECT_ENDPOINT"] = endpoint, - }) - .Build(); +// TODO: Remove this workaround when the agent framework supports environment variable substitution in YAML files. +text = text.Replace("=Env.AZURE_FOUNDRY_PROJECT_ENDPOINT", endpoint, StringComparison.OrdinalIgnoreCase); +text = text.Replace("=Env.AZURE_FOUNDRY_PROJECT_MODEL_ID", model, StringComparison.OrdinalIgnoreCase); // Example function tool that can be used by the agent. [Description("Get the weather for a given location.")] @@ -48,7 +44,7 @@ static string GetWeather( => $"The weather in {location} is cloudy with a high of {(unit.Equals("celsius", StringComparison.Ordinal) ? "15°C" : "59°F")}."; // Create the agent from the YAML definition. -var agentFactory = new FoundryPersistentAgentFactory(new AzureCliCredential(), configuration); +var agentFactory = new FoundryPersistentAgentFactory(new AzureCliCredential()); var agent = await agentFactory.CreateFromYamlAsync(text); // Create agent run options diff --git a/dotnet/samples/GettingStarted/DeclarativeAgents/Foundry/Properties/launchSettings.json b/dotnet/samples/GettingStarted/DeclarativeAgents/Foundry/Properties/launchSettings.json deleted file mode 100644 index ee5dc4fb3d..0000000000 --- a/dotnet/samples/GettingStarted/DeclarativeAgents/Foundry/Properties/launchSettings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "profiles": { - "PersistentAgent": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\foundry\\PersistentAgent.yaml \"What is the weather in Cambridge, MA in °C?\"" - }, - "MicrosoftLearnAgent": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\foundry\\MicrosoftLearnAgent.yaml \"Tell me a joke about a pirate in Italian.\"" - } - } -} \ No newline at end of file diff --git a/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/DeclarativeOpenAIAgents.csproj b/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/DeclarativeOpenAIAgents.csproj index 6d5f1a5025..e607b92fb7 100644 --- a/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/DeclarativeOpenAIAgents.csproj +++ b/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/DeclarativeOpenAIAgents.csproj @@ -11,7 +11,6 @@ - diff --git a/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/Program.cs b/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/Program.cs index 0f6cf328b7..5aca8ef7cf 100644 --- a/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/Program.cs +++ b/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/Program.cs @@ -5,9 +5,9 @@ using System.ComponentModel; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; -using Microsoft.Extensions.Configuration; var apiKey = Environment.GetEnvironmentVariable("OPENAI_APIKEY") ?? throw new InvalidOperationException("OPENAI_APIKEY is not set."); +var model = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o-mini"; // Read command-line arguments if (args.Length < 2) @@ -31,20 +31,16 @@ if (!File.Exists(yamlFilePath)) // Read the YAML content from the file var text = await File.ReadAllTextAsync(yamlFilePath); -// Set up configuration with the OpenAI API key -IConfiguration configuration = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - ["OPENAI_APIKEY"] = apiKey - }) - .Build(); +// TODO: Remove this workaround when the agent framework supports environment variable substitution in YAML files. +text = text.Replace("=Env.OPENAI_APIKEY", apiKey, StringComparison.OrdinalIgnoreCase); +text = text.Replace("=Env.OPENAI_MODEL", model, StringComparison.OrdinalIgnoreCase); // Create the agent from the YAML definition. var agentFactory = new AggregatorAgentFactory( [ - new OpenAIChatAgentFactory(configuration: configuration), - new OpenAIResponseAgentFactory(configuration: configuration), - new OpenAIAssistantAgentFactory(configuration: configuration) + new OpenAIChatAgentFactory(), + new OpenAIResponseAgentFactory(), + new OpenAIAssistantAgentFactory() ]); var agent = await agentFactory.CreateFromYamlAsync(text); diff --git a/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/Properties/launchSettings.json b/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/Properties/launchSettings.json deleted file mode 100644 index 85b9d08303..0000000000 --- a/dotnet/samples/GettingStarted/DeclarativeAgents/OpenAI/Properties/launchSettings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "profiles": { - "Chat": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\openai\\OpenAIChat.yaml \"What is the weather in Cambridge, MA in °C?\"" - }, - "Responses": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\openai\\OpenAIResponses.yaml \"What is the weather in Cambridge, MA in °C?\"" - }, - "Assistants": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\..\\agent-samples\\openai\\OpenAIAssistants.yaml \"What is the weather in Cambridge, MA in °C?\"" - } - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/FoundryPersistentAgentFactory.cs b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/FoundryPersistentAgentFactory.cs index 505c627263..90e7953926 100644 --- a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/FoundryPersistentAgentFactory.cs +++ b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/FoundryPersistentAgentFactory.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Azure.AI.Agents.Persistent; using Azure.Core; using Microsoft.Bot.ObjectModel; -using Microsoft.Extensions.Configuration; using Microsoft.Shared.Diagnostics; namespace Microsoft.Agents.AI; @@ -21,7 +20,7 @@ public sealed class FoundryPersistentAgentFactory : AgentFactory /// /// Creates a new instance of the class. /// - public FoundryPersistentAgentFactory(PersistentAgentsClient agentClient, IConfiguration? configuration = null) : base(configuration) + public FoundryPersistentAgentFactory(PersistentAgentsClient agentClient) { Throw.IfNull(agentClient); @@ -31,7 +30,7 @@ public sealed class FoundryPersistentAgentFactory : AgentFactory /// /// Creates a new instance of the class. /// - public FoundryPersistentAgentFactory(TokenCredential tokenCredential, IConfiguration? configuration = null) : base(configuration) + public FoundryPersistentAgentFactory(TokenCredential tokenCredential) { Throw.IfNull(tokenCredential); @@ -73,7 +72,7 @@ public sealed class FoundryPersistentAgentFactory : AgentFactory var connection = externalModel?.Connection as RemoteConnection; if (connection is not null) { - var endpoint = connection.Endpoint?.Eval(this.Engine); + var endpoint = connection.Endpoint?.LiteralValue; if (string.IsNullOrEmpty(endpoint)) { throw new InvalidOperationException("The endpoint must be specified in the agent definition model connection to create an PersistentAgentsClient."); diff --git a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIAgentFactory.cs b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIAgentFactory.cs index dd2116d96c..a729d1c025 100644 --- a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIAgentFactory.cs +++ b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIAgentFactory.cs @@ -4,7 +4,6 @@ using System.ClientModel; using Azure.AI.OpenAI; using Azure.Core; using Microsoft.Bot.ObjectModel; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Shared.Diagnostics; using OpenAI; @@ -22,7 +21,7 @@ public abstract class OpenAIAgentFactory : AgentFactory /// /// Creates a new instance of the class. /// - protected OpenAIAgentFactory(IConfiguration? configuration, ILoggerFactory? loggerFactory) : base(configuration) + protected OpenAIAgentFactory(ILoggerFactory? loggerFactory) { this.LoggerFactory = loggerFactory; } @@ -30,7 +29,7 @@ public abstract class OpenAIAgentFactory : AgentFactory /// /// Creates a new instance of the class. /// - protected OpenAIAgentFactory(Uri endpoint, TokenCredential tokenCredential, IConfiguration? configuration, ILoggerFactory? loggerFactory) : base(configuration) + protected OpenAIAgentFactory(Uri endpoint, TokenCredential tokenCredential, ILoggerFactory? loggerFactory) { Throw.IfNull(endpoint); Throw.IfNull(tokenCredential); @@ -54,7 +53,7 @@ public abstract class OpenAIAgentFactory : AgentFactory var provider = model?.Provider?.Value ?? ModelProvider.OpenAI; if (provider == ModelProvider.OpenAI) { - return this.CreateOpenAIChatClient(promptAgent); + return CreateOpenAIChatClient(promptAgent); } else if (provider == ModelProvider.AzureOpenAI) { @@ -75,7 +74,7 @@ public abstract class OpenAIAgentFactory : AgentFactory var provider = model?.Provider?.Value ?? ModelProvider.OpenAI; if (provider == ModelProvider.OpenAI) { - return this.CreateOpenAIAssistantClient(promptAgent); + return CreateOpenAIAssistantClient(promptAgent); } else if (provider == ModelProvider.AzureOpenAI) { @@ -96,7 +95,7 @@ public abstract class OpenAIAgentFactory : AgentFactory var provider = model?.Provider?.Value ?? ModelProvider.OpenAI; if (provider == ModelProvider.OpenAI) { - return this.CreateOpenAIResponseClient(promptAgent); + return CreateOpenAIResponseClient(promptAgent); } else if (provider == ModelProvider.AzureOpenAI) { @@ -112,12 +111,12 @@ public abstract class OpenAIAgentFactory : AgentFactory private readonly Uri? _endpoint; private readonly TokenCredential? _tokenCredential; - private ChatClient CreateOpenAIChatClient(GptComponentMetadata promptAgent) + private static ChatClient CreateOpenAIChatClient(GptComponentMetadata promptAgent) { var modelId = promptAgent.Model?.ModelNameHint; Throw.IfNullOrEmpty(modelId, "The model id must be specified in the agent definition to create an OpenAI agent."); - return this.CreateOpenAIClient(promptAgent).GetChatClient(modelId); + return CreateOpenAIClient(promptAgent).GetChatClient(modelId); } private static ChatClient CreateAzureOpenAIChatClient(GptComponentMetadata promptAgent, Uri endpoint, TokenCredential tokenCredential) @@ -128,12 +127,12 @@ public abstract class OpenAIAgentFactory : AgentFactory return new AzureOpenAIClient(endpoint, tokenCredential).GetChatClient(deploymentName); } - private AssistantClient CreateOpenAIAssistantClient(GptComponentMetadata promptAgent) + private static AssistantClient CreateOpenAIAssistantClient(GptComponentMetadata promptAgent) { var modelId = promptAgent.Model?.ModelNameHint; Throw.IfNullOrEmpty(modelId, "The model id must be specified in the agent definition to create an OpenAI agent."); - return this.CreateOpenAIClient(promptAgent).GetAssistantClient(); + return CreateOpenAIClient(promptAgent).GetAssistantClient(); } private static AssistantClient CreateAzureOpenAIAssistantClient(GptComponentMetadata promptAgent, Uri endpoint, TokenCredential tokenCredential) @@ -144,12 +143,12 @@ public abstract class OpenAIAgentFactory : AgentFactory return new AzureOpenAIClient(endpoint, tokenCredential).GetAssistantClient(); } - private OpenAIResponseClient CreateOpenAIResponseClient(GptComponentMetadata promptAgent) + private static OpenAIResponseClient CreateOpenAIResponseClient(GptComponentMetadata promptAgent) { var modelId = promptAgent.Model?.ModelNameHint; Throw.IfNullOrEmpty(modelId, "The model id must be specified in the agent definition to create an OpenAI agent."); - return this.CreateOpenAIClient(promptAgent).GetOpenAIResponseClient(modelId); + return CreateOpenAIClient(promptAgent).GetOpenAIResponseClient(modelId); } private static OpenAIResponseClient CreateAzureOpenAIResponseClient(GptComponentMetadata promptAgent, Uri endpoint, TokenCredential tokenCredential) @@ -160,14 +159,14 @@ public abstract class OpenAIAgentFactory : AgentFactory return new AzureOpenAIClient(endpoint, tokenCredential).GetOpenAIResponseClient(deploymentName); } - private OpenAIClient CreateOpenAIClient(GptComponentMetadata promptAgent) + private static OpenAIClient CreateOpenAIClient(GptComponentMetadata promptAgent) { var model = promptAgent.Model as CurrentModels; var keyConnection = model?.Connection as ApiKeyConnection; Throw.IfNull(keyConnection, "A key connection must be specified when create an OpenAI client"); - var apiKey = keyConnection.Key?.Eval(this.Engine); + var apiKey = keyConnection.Key?.LiteralValue; Throw.IfNullOrEmpty(apiKey, "The connection key must be specified in the agent definition to create an OpenAI client."); var clientOptions = new OpenAIClientOptions(); diff --git a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIAssistantAgentFactory.cs b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIAssistantAgentFactory.cs index 621736e6dd..081a008881 100644 --- a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIAssistantAgentFactory.cs +++ b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIAssistantAgentFactory.cs @@ -7,7 +7,6 @@ using Azure.AI.Agents.Persistent; using Azure.Core; using Microsoft.Bot.ObjectModel; using Microsoft.Extensions.AI; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Shared.Diagnostics; using OpenAI; @@ -23,7 +22,7 @@ public sealed class OpenAIAssistantAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIAssistantAgentFactory(IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory) + public OpenAIAssistantAgentFactory(IList? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory) { this._functions = functions; } @@ -31,7 +30,7 @@ public sealed class OpenAIAssistantAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIAssistantAgentFactory(AssistantClient assistantClient, IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory) + public OpenAIAssistantAgentFactory(AssistantClient assistantClient, IList? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory) { Throw.IfNull(assistantClient); @@ -42,7 +41,7 @@ public sealed class OpenAIAssistantAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIAssistantAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, configuration, loggerFactory) + public OpenAIAssistantAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList? functions = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, loggerFactory) { this._functions = functions; } diff --git a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIChatAgentFactory.cs b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIChatAgentFactory.cs index f27c8ca6a5..587d39aae2 100644 --- a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIChatAgentFactory.cs +++ b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIChatAgentFactory.cs @@ -7,7 +7,6 @@ using Azure.AI.Agents.Persistent; using Azure.Core; using Microsoft.Bot.ObjectModel; using Microsoft.Extensions.AI; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Shared.Diagnostics; using OpenAI.Chat; @@ -22,7 +21,7 @@ public sealed class OpenAIChatAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIChatAgentFactory(IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory) + public OpenAIChatAgentFactory(IList? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory) { this._functions = functions; } @@ -30,7 +29,7 @@ public sealed class OpenAIChatAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIChatAgentFactory(ChatClient chatClient, IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory) + public OpenAIChatAgentFactory(ChatClient chatClient, IList? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory) { Throw.IfNull(chatClient); @@ -41,7 +40,7 @@ public sealed class OpenAIChatAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIChatAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, configuration, loggerFactory) + public OpenAIChatAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList? functions = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, loggerFactory) { this._functions = functions; } diff --git a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIResponseAgentFactory.cs b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIResponseAgentFactory.cs index fd86ad78dc..1e5ddfc98b 100644 --- a/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIResponseAgentFactory.cs +++ b/dotnet/src/Microsoft.Agents.AI.Declarative.AzureAI/OpenAIResponseAgentFactory.cs @@ -7,7 +7,6 @@ using Azure.AI.Agents.Persistent; using Azure.Core; using Microsoft.Bot.ObjectModel; using Microsoft.Extensions.AI; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Shared.Diagnostics; using OpenAI.Responses; @@ -22,7 +21,7 @@ public sealed class OpenAIResponseAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIResponseAgentFactory(IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory) + public OpenAIResponseAgentFactory(IList? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory) { this._functions = functions; } @@ -30,7 +29,7 @@ public sealed class OpenAIResponseAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIResponseAgentFactory(OpenAIResponseClient responseClient, IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory) + public OpenAIResponseAgentFactory(OpenAIResponseClient responseClient, IList? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory) { Throw.IfNull(responseClient); @@ -41,7 +40,7 @@ public sealed class OpenAIResponseAgentFactory : OpenAIAgentFactory /// /// Creates a new instance of the class. /// - public OpenAIResponseAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, configuration, loggerFactory) + public OpenAIResponseAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList? functions = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, loggerFactory) { this._functions = functions; } diff --git a/dotnet/src/Microsoft.Agents.AI.Declarative/AgentFactory.cs b/dotnet/src/Microsoft.Agents.AI.Declarative/AgentFactory.cs index d50b82066c..653c14bdf8 100644 --- a/dotnet/src/Microsoft.Agents.AI.Declarative/AgentFactory.cs +++ b/dotnet/src/Microsoft.Agents.AI.Declarative/AgentFactory.cs @@ -4,8 +4,6 @@ using System; using System.Threading; using System.Threading.Tasks; using Microsoft.Bot.ObjectModel; -using Microsoft.Extensions.Configuration; -using Microsoft.PowerFx; using Microsoft.Shared.Diagnostics; namespace Microsoft.Agents.AI; @@ -15,28 +13,6 @@ namespace Microsoft.Agents.AI; /// public abstract class AgentFactory { - /// - /// Initializes a new instance of the class. - /// - /// The configuration. - protected AgentFactory(IConfiguration? configuration = null) - { - this.Engine = new RecalcEngine(); - - if (configuration is not null) - { - foreach (var kvp in configuration.AsEnumerable()) - { - this.Engine.UpdateVariable(kvp.Key, kvp.Value ?? string.Empty); - } - } - } - - /// - /// Gets the Power Fx recalculation engine. - /// - protected RecalcEngine Engine { get; } - /// /// Create a from the specified . /// diff --git a/dotnet/src/Microsoft.Agents.AI.Declarative/ChatClient/ChatClientAgentFactory.cs b/dotnet/src/Microsoft.Agents.AI.Declarative/ChatClient/ChatClientAgentFactory.cs index 1a9a3b7a4b..aa32da4112 100644 --- a/dotnet/src/Microsoft.Agents.AI.Declarative/ChatClient/ChatClientAgentFactory.cs +++ b/dotnet/src/Microsoft.Agents.AI.Declarative/ChatClient/ChatClientAgentFactory.cs @@ -5,7 +5,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Bot.ObjectModel; using Microsoft.Extensions.AI; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Microsoft.Shared.Diagnostics; @@ -19,7 +18,7 @@ public sealed class ChatClientAgentFactory : AgentFactory /// /// Creates a new instance of the class. /// - public ChatClientAgentFactory(IChatClient chatClient, IList? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration) + public ChatClientAgentFactory(IChatClient chatClient, IList? functions = null, ILoggerFactory? loggerFactory = null) { Throw.IfNull(chatClient); diff --git a/dotnet/src/Microsoft.Agents.AI.Declarative/Extensions/StringExpressionExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Declarative/Extensions/StringExpressionExtensions.cs deleted file mode 100644 index 478a0ba2a9..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Declarative/Extensions/StringExpressionExtensions.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.PowerFx; -using Microsoft.PowerFx.Types; - -namespace Microsoft.Bot.ObjectModel; - -/// -/// Extension methods for . -/// -public static class StringExpressionExtensions -{ - /// - /// Evaluates the given using the provided . - /// - /// Expression to evaluate. - /// Recalc engine to use for evaluation. - public static string? Eval(this StringExpression? expression, RecalcEngine engine) - { - if (expression is null) - { - return null; - } - - if (expression.IsLiteral) - { - return expression.LiteralValue?.ToString(); - } - else if (expression.IsExpression) - { - return engine.Eval(expression.ExpressionText!).ToString(); - } - else if (expression.IsVariableReference) - { - var stringValue = engine.Eval(expression.VariableReference!.VariableName) as StringValue; - return stringValue?.Value; - } - - return null; - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AgentBotElementYamlTests.cs b/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AgentBotElementYamlTests.cs index 165ad7948a..86ec4bc571 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AgentBotElementYamlTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/AgentBotElementYamlTests.cs @@ -6,8 +6,6 @@ using System.Text.Json.Serialization; using Microsoft.Bot.ObjectModel; using Microsoft.Extensions.AI; using Microsoft.Extensions.Configuration; -using Microsoft.PowerFx; -using Microsoft.PowerFx.Types; namespace Microsoft.Agents.AI.Declarative.UnitTests; @@ -220,6 +218,7 @@ public sealed class AgentBotElementYamlTests .AddInMemoryCollection(new Dictionary { ["OpenAIEndpoint"] = "endpoint", + ["OpenAIModelId"] = "modelId", ["OpenAIApiKey"] = "apiKey" }) .Build(); @@ -234,10 +233,9 @@ public sealed class AgentBotElementYamlTests Assert.NotNull(model); Assert.NotNull(model.Connection); Assert.IsType(model.Connection); - ApiKeyConnection connection = (model.Connection as ApiKeyConnection)!; - Assert.NotNull(connection); - Assert.Equal("endpoint", this.Eval(connection.Endpoint!, configuration)); - Assert.Equal("apiKey", this.Eval(connection.Key!, configuration)); + //Assert.Equal("https://my-azure-openai-endpoint.openai.azure.com/", agent.Model.Connection.Endpoint?.LiteralValue); + //Assert.Equal("apiKey", connection.Key?.LiteralValue); + //Assert.Equal("modelId", model.Id); } /// @@ -255,28 +253,4 @@ public sealed class AgentBotElementYamlTests [JsonPropertyName("occupation")] public string? Occupation { get; set; } } - - private string? Eval(StringExpression expression, IConfiguration configuration) - { - RecalcEngine engine = new(); - foreach (var kvp in configuration.AsEnumerable()) - { - engine.UpdateVariable(kvp.Key, kvp.Value ?? string.Empty); - } - - if (expression.IsLiteral) - { - return expression.LiteralValue?.ToString(); - } - else if (expression.IsExpression) - { - return engine.Eval(expression.ExpressionText!).ToString(); - } - else if (expression.IsVariableReference) - { - var stringValue = engine.Eval(expression.VariableReference!.VariableName) as StringValue; - return stringValue?.Value; - } - return null; - } } diff --git a/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/PromptAgents.cs b/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/PromptAgents.cs index 513026aa41..075b134981 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/PromptAgents.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Declarative.UnitTests/PromptAgents.cs @@ -146,7 +146,7 @@ internal static class PromptAgents description: Agent description instructions: You are a helpful assistant. model: - id: gpt-4o + id: =Env.OpenAIModelId connection: kind: apiKey endpoint: =Env.OpenAIEndpoint