-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2088 from solliancenet/cj-code-execution-091alpha2
(0.9.1-alpha2) Code execution session identifiers using ACA Dynamic Sessions
- Loading branch information
Showing
19 changed files
with
333 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/dotnet/Common/Constants/Agents/AgentToolPropertyNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace FoundationaLLM.Common.Constants.Agents | ||
{ | ||
/// <summary> | ||
/// Provides well-known parameter names for agent tools. | ||
/// </summary> | ||
public static class AgentToolPropertyNames | ||
{ | ||
/// <summary> | ||
/// Indicates whether code execution is enabled or not. | ||
/// </summary> | ||
public const string FoundationaLLM_AzureContainerApps_CodeExecution_Enabled = "foundationallm_aca_code_execution_enabled"; | ||
|
||
/// <summary> | ||
/// The session identifier required to execute code in Azure Container Apps Dynamic Sessions. | ||
/// </summary> | ||
public const string FoundationaLLM_AzureContainerApps_CodeExecution_SessionId = "foundationallm_aca_code_execution_session_id"; | ||
|
||
/// <summary> | ||
/// The endpoint required to execute code in Azure Container Apps Dynamic Sessions. | ||
/// </summary> | ||
public const string FoundationaLLM_AzureContainerApps_CodeExecution_Endpoint = "foundationallm_aca_code_execution_endpoint"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using FoundationaLLM.Common.Models.Authentication; | ||
using FoundationaLLM.Common.Models.CodeExecution; | ||
|
||
namespace FoundationaLLM.Common.Interfaces | ||
{ | ||
/// <summary> | ||
/// Defines the capabilities for code execution services. | ||
/// </summary> | ||
public interface ICodeExecutionService | ||
{ | ||
/// <summary> | ||
/// Creates a new code execution session. | ||
/// </summary> | ||
/// <param name="instanceId">The unique identifier of the FoundationaLLM instance.</param> | ||
/// <param name="context">The context in which the code execution session is created. This is usually the name of the agent tool, but it is not limited to that.</param> | ||
/// <param name="conversationId">The unique identifier of the conversation.</param> | ||
/// <param name="userIdentity">The <see cref="UnifiedUserIdentity"/> providing the user identity information.</param> | ||
/// <returns>A <see cref="CodeExecutionSession"/> object with the properties of the code execution session.</returns> | ||
Task<CodeExecutionSession> CreateCodeExecutionSession( | ||
string instanceId, | ||
string context, | ||
string conversationId, | ||
UnifiedUserIdentity userIdentity); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/dotnet/Common/Models/CodeExecution/CodeExecutionSession.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace FoundationaLLM.Common.Models.CodeExecution | ||
{ | ||
/// <summary> | ||
/// Provides details about a code execution session. | ||
/// </summary> | ||
public class CodeExecutionSession | ||
{ | ||
/// <summary> | ||
/// The unique identifier for the code execution session. | ||
/// </summary> | ||
public required string SessionId { get; set; } | ||
|
||
/// <summary> | ||
/// The endpoint used to execute the code. | ||
/// </summary> | ||
public required string Endpoint { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...mmon/Models/Configuration/CodeExecution/AzureContainerAppsCodeExecutionServiceSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace FoundationaLLM.Common.Models.Configuration.CodeExecution | ||
{ | ||
/// <summary> | ||
/// Provides settings for the Azure Container Apps code execution service. | ||
/// </summary> | ||
public class AzureContainerAppsCodeExecutionServiceSettings | ||
{ | ||
/// <summary> | ||
/// Get or sets the list of Azure Container Apps Dynamic Sessions endpoints. | ||
/// </summary> | ||
public List<string> DynamicSessionsEndpoints { get; set; } = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/dotnet/Common/Services/CodeExecution/AzureContainerAppsCodeExecutionService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using FoundationaLLM.Common.Interfaces; | ||
using FoundationaLLM.Common.Models.Authentication; | ||
using FoundationaLLM.Common.Models.CodeExecution; | ||
using FoundationaLLM.Common.Models.Configuration.CodeExecution; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace FoundationaLLM.Common.Services.CodeExecution | ||
{ | ||
/// <summary> | ||
/// Provides a code execution service that uses Azure Container Apps Dynamic Sessions to execute code. | ||
/// </summary> | ||
/// <param name="options">The options for the Azure Container Apps code execution service.</param> | ||
/// <param name="logger">The logger used for logging.</param> | ||
public class AzureContainerAppsCodeExecutionService( | ||
IOptions<AzureContainerAppsCodeExecutionServiceSettings> options, | ||
ILogger<AzureContainerAppsCodeExecutionService> logger) : ICodeExecutionService | ||
{ | ||
private readonly AzureContainerAppsCodeExecutionServiceSettings _settings = options.Value; | ||
private readonly ILogger<AzureContainerAppsCodeExecutionService> _logger = logger; | ||
|
||
/// <inheritdoc /> | ||
public Task<CodeExecutionSession> CreateCodeExecutionSession( | ||
string instanceId, | ||
string context, | ||
string conversationId, | ||
UnifiedUserIdentity userIdentity) | ||
{ | ||
string newSessionId; | ||
|
||
if (string.IsNullOrWhiteSpace(context)) | ||
{ | ||
// Since the context is invalid, the session identifier will be a random GUID. | ||
|
||
_logger.LogWarning("An empty context was provided for creating a code execution session identifier."); | ||
newSessionId = Guid.NewGuid().ToString().ToLower(); | ||
} | ||
else if (string.IsNullOrWhiteSpace(conversationId)) | ||
{ | ||
// Since the conversation identifier is invalid, the session identifier will use a random GUID instead. | ||
_logger.LogWarning("An empty conversation identifier was provided for creating a code execution session identifier."); | ||
newSessionId = $"{context}-{Guid.NewGuid().ToString().ToLower()}"; | ||
} | ||
else | ||
{ | ||
// The session identifier will be a combination of the context and conversation identifier. | ||
newSessionId = $"{context}-{conversationId}"; | ||
} | ||
|
||
// Ensure the session identifier is no longer than 128 characters. | ||
if (newSessionId.Length > 128) | ||
{ | ||
_logger.LogWarning("The generated code execution session identifier is longer than 128 characters. It will be truncated."); | ||
newSessionId = newSessionId[..128]; | ||
} | ||
|
||
return Task.FromResult(new CodeExecutionSession | ||
{ | ||
SessionId = newSessionId, | ||
Endpoint = _settings.DynamicSessionsEndpoints.First() | ||
}); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/dotnet/Common/Services/CodeExecution/DependencyInjection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using FoundationaLLM.Common.Constants.Configuration; | ||
using FoundationaLLM.Common.Interfaces; | ||
using FoundationaLLM.Common.Models.Configuration.CodeExecution; | ||
using FoundationaLLM.Common.Services.CodeExecution; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace FoundationaLLM | ||
{ | ||
/// <summary> | ||
/// General purpose dependency injection extensions. | ||
/// </summary> | ||
public static partial class DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Registers the <see cref="ICodeExecutionService"/> implementation with the dependency injection container. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IHostApplicationBuilder"/> application builder managing the dependency injection container.</param> | ||
public static void AddAzureContainerAppsCodeExecutionService(this IHostApplicationBuilder builder) => | ||
builder.Services.AddAzureContainerAppsCodeExecutionService(builder.Configuration); | ||
|
||
/// <summary> | ||
/// Registers the <see cref="ICodeExecutionService"/> implementation with the dependency injection container. | ||
/// </summary> | ||
/// <param name="services">The <see cref="IServiceCollection"/> dependency injection container service collection.</param> | ||
/// <param name="configuration">The <see cref="IConfigurationManager"/> application configuration manager.</param> | ||
public static void AddAzureContainerAppsCodeExecutionService(this IServiceCollection services, IConfigurationManager configuration) | ||
{ | ||
services.AddOptions<AzureContainerAppsCodeExecutionServiceSettings>() | ||
.Bind(configuration.GetSection(AppConfigurationKeys.FoundationaLLM_Code_CodeExecution_AzureContainerAppsDynamicSessions)); | ||
|
||
services.AddSingleton<ICodeExecutionService, AzureContainerAppsCodeExecutionService>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/dotnet/Common/Services/Templates/DependencyInjection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using FoundationaLLM.Common.Interfaces; | ||
using FoundationaLLM.Common.Services.Templates; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace FoundationaLLM | ||
{ | ||
/// <summary> | ||
/// General purpose dependency injection extensions. | ||
/// </summary> | ||
public static partial class DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Registers the <see cref="ITemplatingService"/> implementation with the dependency injection container. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IHostApplicationBuilder"/> application builder managing the dependency injection container.</param> | ||
public static void AddRegexTemplatingService(this IHostApplicationBuilder builder) => | ||
builder.Services.AddSingleton<ITemplatingService, RegexTemplatingService>(); | ||
|
||
/// <summary> | ||
/// Registers the <see cref="ITemplatingService"/> implementation with the dependency injection container. | ||
/// </summary> | ||
/// <param name="services">The <see cref="IServiceCollection"/> dependency injection container service collection.</param> | ||
public static void AddRegexTemplatingService(this IServiceCollection services) => | ||
services.AddSingleton<ITemplatingService, RegexTemplatingService>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.