-
Notifications
You must be signed in to change notification settings - Fork 44
Add Microsoft Agent Framework integration with code-first agents and multi-agent workflows #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sfmskywalker
merged 24 commits into
main
from
copilot/refactor-agents-to-microsoft-framework
Dec 14, 2025
Merged
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8ed8310
Update package versions in `Directory.Build.props` and `Directory.Pac…
sfmskywalker c9253c9
Initial plan
Copilot 5bbd847
Add Microsoft Agent Framework integration with code-first support
Copilot 7e699df
Add comprehensive documentation and examples for Agent Framework feat…
Copilot 163a17f
Add unit tests and fix null reference issues in ConfigurationKernelCo…
Copilot e03d1bf
Address code review feedback - improve error handling and remove unus…
Copilot 1d616cb
Add migration guide for Agent Framework features
Copilot fb4f4eb
Refactor package versioning and temporarily comment out scoped activi…
sfmskywalker 5409790
Add `Elsa.Agents.Tests` project and refactor `TestWorkflowDefinition`…
sfmskywalker b0705a7
Remove legacy KernelFactory and implement improved Agent Framework su…
sfmskywalker 814cf6d
Remove SK-based agent workflows and introduce code-first agents
sfmskywalker d86dbd7
Refactor agent activities and improve dependency injection
sfmskywalker 97a3299
Refactor agent workflow infrastructure to simplify providers.
sfmskywalker 5089bc1
Refactor agents framework and replace deprecated agent implementation
sfmskywalker 0269fae
Replace "plugins" with "skills" throughout agents framework
sfmskywalker b020eb8
Remove legacy API key and service management functionality.
sfmskywalker 89f3e1b
Remove ApiKeyDefinition and ServiceDefinition tables.
sfmskywalker add31db
Add Azure OpenAI integration to Elsa Agents
sfmskywalker b4d7a24
Refactor agent activity providers and registry to improve naming cons…
sfmskywalker fe8d3a1
Improve naming consistency in documentation for agent activity provid…
sfmskywalker b8521cf
Refactor runAsynchronously logic and remove TaskActivityAttribute
sfmskywalker 5db7bfb
Introduce `IAgentFactory` and `IAgentInvoker` interfaces to decouple …
sfmskywalker 4725ce5
Refactor agents framework to unify configuration and improve invocati…
sfmskywalker f4c7864
Remove obsolete agent test suite and update solution references.
sfmskywalker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
88 changes: 88 additions & 0 deletions
88
src/modules/agents/Elsa.Agents.Activities/Activities/AgentWorkflowActivity.cs
This file contains hidden or 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,88 @@ | ||
| using System.ComponentModel; | ||
| using System.Dynamic; | ||
| using System.Text.Encodings.Web; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using System.Text.Unicode; | ||
| using Elsa.Agents; | ||
| using Elsa.Expressions.Helpers; | ||
| using Elsa.Extensions; | ||
| using Elsa.Agents.Activities.ActivityProviders; | ||
| using Elsa.Workflows; | ||
| using Elsa.Workflows.Models; | ||
| using Elsa.Workflows.Serialization.Converters; | ||
|
|
||
| namespace Elsa.Agents.Activities; | ||
|
|
||
| /// <summary> | ||
| /// An activity that executes a multi-agent workflow. This is an internal activity used by <see cref="AgentActivityProvider"/>. | ||
| /// </summary> | ||
| [Browsable(false)] | ||
| public class AgentWorkflowActivity : CodeActivity | ||
| { | ||
| private static JsonSerializerOptions? _serializerOptions; | ||
|
|
||
| private static JsonSerializerOptions SerializerOptions => | ||
| _serializerOptions ??= new JsonSerializerOptions | ||
| { | ||
| Encoder = JavaScriptEncoder.Create(UnicodeRanges.All), | ||
| PropertyNameCaseInsensitive = true | ||
| }.WithConverters(new ExpandoObjectConverterFactory()); | ||
|
|
||
| [JsonIgnore] internal string WorkflowName { get; set; } = null!; | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) | ||
| { | ||
| var activityDescriptor = context.ActivityDescriptor; | ||
| var inputDescriptors = activityDescriptor.Inputs; | ||
| var workflowInput = new Dictionary<string, object?>(); | ||
|
|
||
| foreach (var inputDescriptor in inputDescriptors) | ||
| { | ||
| var input = (Input?)inputDescriptor.ValueGetter(this); | ||
| var inputValue = input != null ? context.Get(input.MemoryBlockReference()) : null; | ||
|
|
||
| if (inputValue is ExpandoObject expandoObject) | ||
| { | ||
| inputValue = expandoObject.ConvertTo<string>(); | ||
| } | ||
|
|
||
| workflowInput[inputDescriptor.Name] = inputValue; | ||
| } | ||
|
|
||
| var kernelConfigProvider = context.GetRequiredService<IKernelConfigProvider>(); | ||
| var workflowExecutor = context.GetRequiredService<AgentWorkflowExecutor>(); | ||
|
|
||
| var kernelConfig = await kernelConfigProvider.GetKernelConfigAsync(context.CancellationToken); | ||
|
|
||
| if (!kernelConfig.AgentWorkflows.TryGetValue(WorkflowName, out var workflowConfig)) | ||
| throw new InvalidOperationException($"Agent workflow '{WorkflowName}' not found"); | ||
|
|
||
| var result = await workflowExecutor.ExecuteWorkflowAsync(WorkflowName, workflowConfig, workflowInput, context.CancellationToken); | ||
| var json = result.Output?.Trim(); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(json)) | ||
| throw new InvalidOperationException("The workflow output is empty or null."); | ||
|
|
||
| var outputs = context.ActivityDescriptor.Outputs; | ||
| if (outputs.Count != 1) | ||
| throw new InvalidOperationException($"Expected exactly one output, but found {outputs.Count}"); | ||
|
|
||
| var outputType = outputs.First().Type; | ||
|
|
||
| // If the target type is object, we want the JSON to be deserialized into an ExpandoObject for dynamic field access. | ||
| if (outputType == typeof(object)) | ||
| outputType = typeof(ExpandoObject); | ||
|
|
||
| var converterOptions = new ObjectConverterOptions(SerializerOptions); | ||
| var outputValue = json.ConvertTo(outputType, converterOptions); | ||
| var outputDescriptor = outputs.First(); | ||
| var output = outputDescriptor.ValueGetter(this) as Output; | ||
|
|
||
| if (output == null) | ||
| throw new InvalidOperationException("Output descriptor did not return a valid Output object"); | ||
|
|
||
| context.Set(output, outputValue); | ||
| } | ||
| } |
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
src/modules/agents/Elsa.Agents.Core/Contracts/IAgentDefinition.cs
This file contains hidden or 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,22 @@ | ||
| namespace Elsa.Agents; | ||
|
|
||
| /// <summary> | ||
| /// Represents a code-first agent definition that can be registered programmatically. | ||
| /// </summary> | ||
| public interface IAgentDefinition | ||
| { | ||
| /// <summary> | ||
| /// Gets the unique name of the agent. | ||
| /// </summary> | ||
| string Name { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the description of the agent. | ||
| /// </summary> | ||
| string Description { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the agent configuration. | ||
| /// </summary> | ||
| AgentConfig GetAgentConfig(); | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/modules/agents/Elsa.Agents.Core/Contracts/IAgentDefinitionProvider.cs
This file contains hidden or 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 @@ | ||
| namespace Elsa.Agents; | ||
|
|
||
| /// <summary> | ||
| /// Provides access to registered agent definitions. | ||
| /// </summary> | ||
| public interface IAgentDefinitionProvider | ||
| { | ||
| /// <summary> | ||
| /// Gets all registered agent definitions. | ||
| /// </summary> | ||
| IEnumerable<IAgentDefinition> GetDefinitions(); | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/modules/agents/Elsa.Agents.Core/Contracts/IAgentWorkflowDefinition.cs
This file contains hidden or 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,22 @@ | ||
| namespace Elsa.Agents; | ||
|
|
||
| /// <summary> | ||
| /// Represents a code-first multi-agent workflow (agent team/sequence/graph) that can be registered programmatically. | ||
| /// </summary> | ||
| public interface IAgentWorkflowDefinition | ||
| { | ||
| /// <summary> | ||
| /// Gets the unique name of the agent workflow. | ||
| /// </summary> | ||
| string Name { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the description of the agent workflow. | ||
| /// </summary> | ||
| string Description { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the agent workflow configuration. | ||
| /// </summary> | ||
| AgentWorkflowConfig GetWorkflowConfig(); | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/modules/agents/Elsa.Agents.Core/Contracts/IAgentWorkflowDefinitionProvider.cs
This file contains hidden or 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 @@ | ||
| namespace Elsa.Agents; | ||
|
|
||
| /// <summary> | ||
| /// Provides access to registered agent workflow definitions. | ||
| /// </summary> | ||
| public interface IAgentWorkflowDefinitionProvider | ||
| { | ||
| /// <summary> | ||
| /// Gets all registered agent workflow definitions. | ||
| /// </summary> | ||
| IEnumerable<IAgentWorkflowDefinition> GetDefinitions(); | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.