-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce agent management components, including pages for listing and handling agent workflows, dialogs for creating agents with Blazor components, and backend API endpoints for generating unique agent names. This enhances functionality for managing agent workflows within the application.
- Loading branch information
1 parent
81cbe2f
commit a7f46ae
Showing
30 changed files
with
296 additions
and
74 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
docker build -t elsa-server:latest -f ./docker/ElsaServer.Dockerfile . | ||
docker build -t elsa-server:latest -f ../../docker/ElsaServer.Dockerfile . | ||
docker run -t -i -e ASPNETCORE_ENVIRONMENT='Development' -e HTTP_PORTS=8080 -p 13000:8080 elsa-server:local |
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 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: elsa-studio-deployment | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: elsa-studio | ||
template: | ||
metadata: | ||
labels: | ||
app: elsa-studio | ||
spec: | ||
containers: | ||
- name: elsa-studio | ||
imagePullPolicy: Never | ||
image: elsa-studio:latest | ||
ports: | ||
- containerPort: 8080 | ||
env: | ||
- name: ASPNETCORE_ENVIRONMENT | ||
value: Development | ||
- name: "ELSASERVER__URL" | ||
value: "http://localhost:8001/elsa/api" |
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,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: elsa-studio-service | ||
spec: | ||
type: LoadBalancer | ||
sessionAffinity: None | ||
ports: | ||
- port: 9001 | ||
targetPort: 8080 | ||
selector: | ||
app: elsa-studio |
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
51 changes: 51 additions & 0 deletions
51
src/modules/Elsa.Agents.Api/Endpoints/Agents/GenerateUniqueName/Endpoint.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,51 @@ | ||
using Elsa.Abstractions; | ||
using Elsa.Agents.Persistence.Contracts; | ||
using Elsa.Agents.Persistence.Filters; | ||
using JetBrains.Annotations; | ||
|
||
namespace Elsa.Agents.Api.Endpoints.Agents.GenerateUniqueName; | ||
|
||
/// Lists all registered API keys. | ||
[UsedImplicitly] | ||
public class Endpoint(IAgentStore store) : ElsaEndpointWithoutRequest<GenerateUniqueNameResponse> | ||
{ | ||
/// <inheritdoc /> | ||
public override void Configure() | ||
{ | ||
Post("/ai/actions/agents/generate-unique-name"); | ||
ConfigurePermissions("ai/agents:write"); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override async Task<GenerateUniqueNameResponse> ExecuteAsync(CancellationToken ct) | ||
{ | ||
var newName = await GenerateUniqueNameAsync(ct); | ||
return new(newName); | ||
} | ||
|
||
private async Task<string> GenerateUniqueNameAsync(CancellationToken cancellationToken) | ||
{ | ||
const int maxAttempts = 100; | ||
var attempt = 0; | ||
|
||
while (attempt < maxAttempts) | ||
{ | ||
var name = $"Agent {++attempt}"; | ||
var isUnique = await IsNameUniqueAsync(name, cancellationToken); | ||
|
||
if (isUnique) | ||
return name; | ||
} | ||
|
||
throw new Exception($"Failed to generate a unique workflow name after {maxAttempts} attempts."); | ||
} | ||
|
||
private async Task<bool> IsNameUniqueAsync(string name, CancellationToken ct) | ||
{ | ||
var filter = new AgentDefinitionFilter | ||
{ | ||
Name = name | ||
}; | ||
return await store.FindAsync(filter, ct) == null; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/modules/Elsa.Agents.Api/Endpoints/Agents/IsUniqueName/Endpoint.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,35 @@ | ||
using Elsa.Abstractions; | ||
using Elsa.Agents.Persistence.Contracts; | ||
using Elsa.Agents.Persistence.Filters; | ||
using JetBrains.Annotations; | ||
|
||
namespace Elsa.Agents.Api.Endpoints.Agents.IsUniqueName; | ||
|
||
/// Checks if a name is unique. | ||
[UsedImplicitly] | ||
public class Endpoint(IAgentStore store) : ElsaEndpoint<IsUniqueNameRequest, IsUniqueNameResponse> | ||
{ | ||
/// <inheritdoc /> | ||
public override void Configure() | ||
{ | ||
Post("/ai/queries/agents/is-unique-name"); | ||
ConfigurePermissions("ai/agents:write"); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override async Task<IsUniqueNameResponse> ExecuteAsync(IsUniqueNameRequest req, CancellationToken ct) | ||
{ | ||
var isUnique = await IsNameUniqueAsync(req.Name, req.Id, ct); | ||
return new(isUnique); | ||
} | ||
|
||
private async Task<bool> IsNameUniqueAsync(string name, string? notId, CancellationToken ct) | ||
{ | ||
var filter = new AgentDefinitionFilter | ||
{ | ||
Name = name, | ||
NotId = notId, | ||
}; | ||
return await store.FindAsync(filter, ct) == null; | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/modules/Elsa.Agents.Api/Extensions/AgentDefinitionExtensions.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,26 @@ | ||
using Elsa.Agents; | ||
using Elsa.Agents.Persistence.Entities; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Elsa.Extensions; | ||
|
||
public static class AgentDefinitionExtensions | ||
{ | ||
public static AgentModel ToModel(this AgentDefinition agentDefinition) | ||
{ | ||
return new AgentModel | ||
{ | ||
Id = agentDefinition.Id, | ||
Name = agentDefinition.Name, | ||
Description = agentDefinition.Description, | ||
Agents = agentDefinition.AgentConfig.Agents, | ||
ExecutionSettings = agentDefinition.AgentConfig.ExecutionSettings, | ||
InputVariables = agentDefinition.AgentConfig.InputVariables, | ||
OutputVariable = agentDefinition.AgentConfig.OutputVariable, | ||
Services = agentDefinition.AgentConfig.Services, | ||
Plugins = agentDefinition.AgentConfig.Plugins, | ||
FunctionName = agentDefinition.AgentConfig.FunctionName, | ||
PromptTemplate = agentDefinition.AgentConfig.PromptTemplate | ||
}; | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
src/modules/Elsa.Agents.Core/Extensions/AgentConfigExtensions.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,49 @@ | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Connectors.OpenAI; | ||
|
||
#pragma warning disable SKEXP0001 | ||
#pragma warning disable SKEXP0010 | ||
|
||
namespace Elsa.Agents; | ||
|
||
public static class AgentConfigExtensions | ||
{ | ||
public static OpenAIPromptExecutionSettings ToOpenAIPromptExecutionSettings(this AgentConfig agentConfig) | ||
{ | ||
return new OpenAIPromptExecutionSettings | ||
{ | ||
Temperature = agentConfig.ExecutionSettings.Temperature, | ||
TopP = agentConfig.ExecutionSettings.TopP, | ||
MaxTokens = agentConfig.ExecutionSettings.MaxTokens, | ||
PresencePenalty = agentConfig.ExecutionSettings.PresencePenalty, | ||
FrequencyPenalty = agentConfig.ExecutionSettings.FrequencyPenalty, | ||
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions, | ||
ResponseFormat = agentConfig.ExecutionSettings.ResponseFormat, | ||
ChatSystemPrompt = agentConfig.PromptTemplate, | ||
}; | ||
} | ||
|
||
public static PromptTemplateConfig ToPromptTemplateConfig(this AgentConfig agentConfig) | ||
{ | ||
var promptExecutionSettingsDictionary = new Dictionary<string, PromptExecutionSettings> | ||
{ | ||
[PromptExecutionSettings.DefaultServiceId] = agentConfig.ToOpenAIPromptExecutionSettings(), | ||
}; | ||
|
||
return new PromptTemplateConfig | ||
{ | ||
Name = agentConfig.FunctionName, | ||
Description = agentConfig.Description, | ||
Template = agentConfig.PromptTemplate, | ||
ExecutionSettings = promptExecutionSettingsDictionary, | ||
AllowDangerouslySetContent = true, | ||
InputVariables = agentConfig.InputVariables.Select(x => new InputVariable | ||
{ | ||
Name = x.Name, | ||
Description = x.Description, | ||
IsRequired = true, | ||
AllowDangerouslySetContent = true | ||
}).ToList() | ||
}; | ||
} | ||
} |
Oops, something went wrong.