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:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user