mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
267351b760
* refactor: remove dead code * refactor: remove ignore YieldsMessageAttribute - the correct one to use is YieldsOutputAttribute - fixes a comment that mistakenly refers to `.YieldsMessage()` which does not exist. * fix: ChatForwardingExecutor does not use correct role for string messages - make ChatForwardingExecutor use its configured role for string messages rather than always use ChatRole.User - add ChatForwardingExecutor tests * fixup: remove unused attribute * test: Add tests for failure when .AsAgent used on a non-ChatProtocol workflow * test: Add FunctionExecutor tests - also fixes Send and YieldOutput type registration for synchronous output-returning delegates * test: Suppress CodeCoverage for obsolete names * fix: Re-add Obsolete attributes - avoid hard-breaking change - properly notify users that these attributes get ignored
73 lines
2.6 KiB
C#
73 lines
2.6 KiB
C#
// 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>
|
|
[Obsolete("Use YieldsOutput instead. The Code Generator and the runtime attribute-based type mapping ignore this attribute.")]
|
|
[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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This attribute indicates that a message handler streams messages during its execution.
|
|
/// </summary>
|
|
[Obsolete("This attribute does not do anything. The Code Generator and the runtime attribute-based type mapping ignore this attribute.")]
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
|
|
public sealed class StreamsMessageAttribute : Attribute
|
|
{
|
|
/// <summary>
|
|
/// The type of the message that the handler yields.
|
|
/// </summary>
|
|
public Type Type { get; }
|
|
|
|
/// <summary>
|
|
/// Indicates that the message handler yields streaming messages during the course of execution.
|
|
/// </summary>
|
|
public StreamsMessageAttribute(Type type)
|
|
{
|
|
// This attribute is used to mark executors that yield messages.
|
|
this.Type = Throw.IfNull(type);
|
|
}
|
|
}
|