Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows/AIAgentExtensions.cs
T
Jacob AlberandGitHub 331c750515 .NET: [BREAKING] Enable sharing of workflow instances across concurrently executing runs (#1464)
* refactor: remove unused internals

* feat: Execution Mode for sharing a workflow among concurrent runs

* feat: Update WorkflowHostAgent to support concurrent execution

* Also update AsAgent APIs to support injecting a CheckpointManager and an IWorkflowExecutionEnvironment

* fix: Make Read logic consistent in DeclarativeWorkflowContext
2025-10-15 21:34:17 +00:00

30 lines
1.0 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Text.RegularExpressions;
namespace Microsoft.Agents.AI.Workflows;
internal static partial class AIAgentExtensions
{
/// <summary>
/// Derives from an agent a unique but also hopefully descriptive name that can be used as an executor's
/// name or in a function name.
/// </summary>
public static string GetDescriptiveId(this AIAgent agent)
{
string id = string.IsNullOrEmpty(agent.Name) ? agent.Id : $"{agent.Name}_{agent.Id}";
return InvalidNameCharsRegex().Replace(id, "_");
}
/// <summary>
/// Regex that flags any character other than ASCII digits or letters or the underscore.
/// </summary>
#if NET
[GeneratedRegex("[^0-9A-Za-z]+")]
private static partial Regex InvalidNameCharsRegex();
#else
private static Regex InvalidNameCharsRegex() => s_invalidNameCharsRegex;
private static readonly Regex s_invalidNameCharsRegex = new("[^0-9A-Za-z_]+", RegexOptions.Compiled);
#endif
}