-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[BREAKING] Obsoleting ReflectingExecutor in favor of source gen #3380
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ae7dbaa
Initial working version with tests.
5e7d19c
Updates to validate class data once instead of for each handler metho…
6aa33f7
Formatting and trying to fix generation project pack.
5746cbc
Another atempt at getting the genrators project to build.
69e1fb0
More attempts to fix generator build and pack.
eef0260
Fixing file encodings.
cab2672
Initail round of cleanup.
fed96fa
Trying to fix packing.
8b0267e
Still trying to fix pipeline pack.
00e932d
Remove obsolescence markers, sample updates, and docs from generator …
cc3081d
Mark ReflectingExecutor and IMessageHandler as obsolete.
ffcac10
Obsoleteing Reflector-based workflow code generation in favor of Sour…
b430f85
Cleaning up temporary design and progress files.
11a92f1
Merge remote-tracking branch 'upstream/main' into wf-obsolete-reflector
e79a076
Merge branch 'main' into wf-obsolete-reflector
crickman 161ea2b
Merging from main.
07b7a25
Merge remote-tracking branch 'upstream/main' into wf-obsolete-reflector
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
13 changes: 13 additions & 0 deletions
13
dotnet/samples/GettingStarted/Workflows/Directory.Build.props
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,13 @@ | ||
| <Project> | ||
|
|
||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
|
||
| <!-- Include Workflows source generator for samples using [MessageHandler] attribute --> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(RepoRoot)/dotnet/src/Microsoft.Agents.AI.Workflows.Generators/Microsoft.Agents.AI.Workflows.Generators.csproj" | ||
| OutputItemType="Analyzer" | ||
| ReferenceOutputAssembly="false" | ||
| GlobalPropertiesToRemove="TargetFramework" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
121 changes: 121 additions & 0 deletions
121
dotnet/src/Microsoft.Agents.AI.Workflows.Generators/Models/EquatableArray.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,121 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
|
|
||
| namespace Microsoft.Agents.AI.Workflows.Generators.Models; | ||
|
|
||
| /// <summary> | ||
| /// A wrapper around <see cref="ImmutableArray{T}"/> that provides value-based equality. | ||
| /// This is necessary for incremental generator caching since ImmutableArray uses reference equality. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Creates a new <see cref="EquatableArray{T}"/> from an <see cref="ImmutableArray{T}"/>. | ||
| /// </remarks> | ||
| internal readonly struct EquatableArray<T>(ImmutableArray<T> array) : IEquatable<EquatableArray<T>>, IEnumerable<T> | ||
| where T : IEquatable<T> | ||
| { | ||
| private readonly ImmutableArray<T> _array = array.IsDefault ? ImmutableArray<T>.Empty : array; | ||
|
|
||
| /// <summary> | ||
| /// Gets the underlying array. | ||
| /// </summary> | ||
| public ImmutableArray<T> AsImmutableArray() => this._array; | ||
|
|
||
| /// <summary> | ||
| /// Gets the number of elements in the array. | ||
| /// </summary> | ||
| public int Length => this._array.Length; | ||
|
|
||
| /// <summary> | ||
| /// Gets the element at the specified index. | ||
| /// </summary> | ||
| public T this[int index] => this._array[index]; | ||
|
|
||
| /// <summary> | ||
| /// Gets whether the array is empty. | ||
| /// </summary> | ||
| public bool IsEmpty => this._array.IsEmpty; | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool Equals(EquatableArray<T> other) | ||
| { | ||
| if (this._array.Length != other._array.Length) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| for (int i = 0; i < this._array.Length; i++) | ||
| { | ||
| if (!this._array[i].Equals(other._array[i])) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override bool Equals(object? obj) | ||
| { | ||
| return obj is EquatableArray<T> other && this.Equals(other); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override int GetHashCode() | ||
| { | ||
| if (this._array.IsEmpty) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| var hashCode = 17; | ||
| foreach (var item in this._array) | ||
| { | ||
| hashCode = hashCode * 31 + (item?.GetHashCode() ?? 0); | ||
| } | ||
|
|
||
| return hashCode; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public IEnumerator<T> GetEnumerator() | ||
| { | ||
| return ((IEnumerable<T>)this._array).GetEnumerator(); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| IEnumerator IEnumerable.GetEnumerator() | ||
| { | ||
| return this.GetEnumerator(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Equality operator. | ||
| /// </summary> | ||
| public static bool operator ==(EquatableArray<T> left, EquatableArray<T> right) | ||
| { | ||
| return left.Equals(right); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Inequality operator. | ||
| /// </summary> | ||
| public static bool operator !=(EquatableArray<T> left, EquatableArray<T> right) | ||
| { | ||
| return !left.Equals(right); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates an empty <see cref="EquatableArray{T}"/>. | ||
| /// </summary> | ||
| public static EquatableArray<T> Empty => new(ImmutableArray<T>.Empty); | ||
|
|
||
| /// <summary> | ||
| /// Implicit conversion from <see cref="ImmutableArray{T}"/>. | ||
| /// </summary> | ||
| public static implicit operator EquatableArray<T>(ImmutableArray<T> array) => new(array); | ||
| } |
49 changes: 49 additions & 0 deletions
49
dotnet/src/Microsoft.Agents.AI.Workflows/Attributes/YieldsMessageAttribute.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,49 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace Microsoft.Agents.AI.Workflows; | ||
|
|
||
| /// <summary> | ||
| /// Declares that an executor may yield messages of the specified type as workflow outputs. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Apply this attribute to an <see cref="Executor"/> class to declare the types of messages | ||
| /// it may yield via <see cref="IWorkflowContext.YieldOutputAsync"/>. This information is used | ||
| /// for protocol validation and documentation. | ||
| /// </para> | ||
| /// <para> | ||
| /// This attribute can be applied multiple times to declare multiple output types. | ||
| /// It is inherited by derived classes, allowing base executors to declare common output types. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <example> | ||
| /// <code> | ||
| /// [YieldsMessage(typeof(FinalResult))] | ||
| /// [YieldsMessage(typeof(StreamChunk))] | ||
| /// public partial class MyExecutor : Executor | ||
| /// { | ||
| /// // ... | ||
| /// } | ||
| /// </code> | ||
| /// </example> | ||
| [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] | ||
| public sealed class YieldsMessageAttribute : Attribute | ||
| { | ||
| /// <summary> | ||
| /// Gets the type of message that the executor may yield. | ||
| /// </summary> | ||
| public Type Type { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="YieldsMessageAttribute"/> class. | ||
| /// </summary> | ||
| /// <param name="type">The type of message that the executor may yield.</param> | ||
| /// <exception cref="ArgumentNullException"><paramref name="type"/> is <see langword="null"/>.</exception> | ||
| public YieldsMessageAttribute(Type type) | ||
| { | ||
| this.Type = Throw.IfNull(type); | ||
| } | ||
| } |
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
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
2 changes: 2 additions & 0 deletions
2
dotnet/src/Microsoft.Agents.AI.Workflows/Reflection/MessageHandlerInfo.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
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
2 changes: 2 additions & 0 deletions
2
dotnet/src/Microsoft.Agents.AI.Workflows/Reflection/RouteBuilderExtensions.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
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
2 changes: 2 additions & 0 deletions
2
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/ReflectionSmokeTest.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
2 changes: 2 additions & 0 deletions
2
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/01_Simple_Workflow_Sequential.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
2 changes: 2 additions & 0 deletions
2
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/02_Simple_Workflow_Condition.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
2 changes: 2 additions & 0 deletions
2
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/Sample/03_Simple_Workflow_Loop.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
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.