mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Revert "Integrate RecalcEngine to compute Env variables"
This reverts commit caf61440f6.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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?\""
|
||||
}
|
||||
}
|
||||
}
|
||||
-12
@@ -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.\""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<string, string?>
|
||||
{
|
||||
["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
|
||||
|
||||
-12
@@ -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.\""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.Identity" />
|
||||
<PackageReference Include="Azure.AI.Agents.Persistent" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||
<PackageReference Include="Microsoft.Bot.ObjectModel" />
|
||||
<PackageReference Include="Microsoft.Bot.ObjectModel.Json" />
|
||||
|
||||
@@ -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<string, string?>
|
||||
{
|
||||
["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);
|
||||
|
||||
|
||||
@@ -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?\""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="FoundryPersistentAgentFactory"/> class.
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="FoundryPersistentAgentFactory"/> class.
|
||||
/// </summary>
|
||||
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.");
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIAgentFactory"/> class.
|
||||
/// </summary>
|
||||
protected OpenAIAgentFactory(IConfiguration? configuration, ILoggerFactory? loggerFactory) : base(configuration)
|
||||
protected OpenAIAgentFactory(ILoggerFactory? loggerFactory)
|
||||
{
|
||||
this.LoggerFactory = loggerFactory;
|
||||
}
|
||||
@@ -30,7 +29,7 @@ public abstract class OpenAIAgentFactory : AgentFactory
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIAgentFactory"/> class.
|
||||
/// </summary>
|
||||
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();
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIAssistantAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIAssistantAgentFactory(IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory)
|
||||
public OpenAIAssistantAgentFactory(IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory)
|
||||
{
|
||||
this._functions = functions;
|
||||
}
|
||||
@@ -31,7 +30,7 @@ public sealed class OpenAIAssistantAgentFactory : OpenAIAgentFactory
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIAssistantAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIAssistantAgentFactory(AssistantClient assistantClient, IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory)
|
||||
public OpenAIAssistantAgentFactory(AssistantClient assistantClient, IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory)
|
||||
{
|
||||
Throw.IfNull(assistantClient);
|
||||
|
||||
@@ -42,7 +41,7 @@ public sealed class OpenAIAssistantAgentFactory : OpenAIAgentFactory
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIAssistantAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIAssistantAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, configuration, loggerFactory)
|
||||
public OpenAIAssistantAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, loggerFactory)
|
||||
{
|
||||
this._functions = functions;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIChatAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIChatAgentFactory(IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory)
|
||||
public OpenAIChatAgentFactory(IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory)
|
||||
{
|
||||
this._functions = functions;
|
||||
}
|
||||
@@ -30,7 +29,7 @@ public sealed class OpenAIChatAgentFactory : OpenAIAgentFactory
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIChatAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIChatAgentFactory(ChatClient chatClient, IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory)
|
||||
public OpenAIChatAgentFactory(ChatClient chatClient, IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory)
|
||||
{
|
||||
Throw.IfNull(chatClient);
|
||||
|
||||
@@ -41,7 +40,7 @@ public sealed class OpenAIChatAgentFactory : OpenAIAgentFactory
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIChatAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIChatAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, configuration, loggerFactory)
|
||||
public OpenAIChatAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, loggerFactory)
|
||||
{
|
||||
this._functions = functions;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIResponseAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIResponseAgentFactory(IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory)
|
||||
public OpenAIResponseAgentFactory(IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory)
|
||||
{
|
||||
this._functions = functions;
|
||||
}
|
||||
@@ -30,7 +29,7 @@ public sealed class OpenAIResponseAgentFactory : OpenAIAgentFactory
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIResponseAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIResponseAgentFactory(OpenAIResponseClient responseClient, IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration, loggerFactory)
|
||||
public OpenAIResponseAgentFactory(OpenAIResponseClient responseClient, IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(loggerFactory)
|
||||
{
|
||||
Throw.IfNull(responseClient);
|
||||
|
||||
@@ -41,7 +40,7 @@ public sealed class OpenAIResponseAgentFactory : OpenAIAgentFactory
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenAIChatAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public OpenAIResponseAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, configuration, loggerFactory)
|
||||
public OpenAIResponseAgentFactory(Uri endpoint, TokenCredential tokenCredential, IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null) : base(endpoint, tokenCredential, loggerFactory)
|
||||
{
|
||||
this._functions = functions;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
/// </summary>
|
||||
public abstract class AgentFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AgentFactory"/> class.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration.</param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Power Fx recalculation engine.
|
||||
/// </summary>
|
||||
protected RecalcEngine Engine { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="AIAgent"/> from the specified <see cref="GptComponentMetadata"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ChatClientAgentFactory"/> class.
|
||||
/// </summary>
|
||||
public ChatClientAgentFactory(IChatClient chatClient, IList<AIFunction>? functions = null, IConfiguration? configuration = null, ILoggerFactory? loggerFactory = null) : base(configuration)
|
||||
public ChatClientAgentFactory(IChatClient chatClient, IList<AIFunction>? functions = null, ILoggerFactory? loggerFactory = null)
|
||||
{
|
||||
Throw.IfNull(chatClient);
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using Microsoft.PowerFx;
|
||||
using Microsoft.PowerFx.Types;
|
||||
|
||||
namespace Microsoft.Bot.ObjectModel;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="StringExpression"/>.
|
||||
/// </summary>
|
||||
public static class StringExpressionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Evaluates the given <see cref="StringExpression"/> using the provided <see cref="RecalcEngine"/>.
|
||||
/// </summary>
|
||||
/// <param name="expression">Expression to evaluate.</param>
|
||||
/// <param name="engine">Recalc engine to use for evaluation.</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<string, string?>
|
||||
{
|
||||
["OpenAIEndpoint"] = "endpoint",
|
||||
["OpenAIModelId"] = "modelId",
|
||||
["OpenAIApiKey"] = "apiKey"
|
||||
})
|
||||
.Build();
|
||||
@@ -234,10 +233,9 @@ public sealed class AgentBotElementYamlTests
|
||||
Assert.NotNull(model);
|
||||
Assert.NotNull(model.Connection);
|
||||
Assert.IsType<ApiKeyConnection>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user