Minor cleanup

This commit is contained in:
Shyju Krishnankutty
2026-01-27 19:38:08 -08:00
Unverified
parent e64fb4a435
commit 45050a2b08
10 changed files with 235 additions and 205 deletions
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Agents.AI.Workflows;
namespace Microsoft.Agents.AI.DurableTask;
/// <summary>
/// Event raised when an executor requests the workflow to halt via <see cref="IWorkflowContext.RequestHaltAsync"/>.
/// </summary>
/// <remarks>
/// This is the durable equivalent of the internal RequestHaltEvent since that class is not accessible
/// from outside the Workflows assembly.
/// </remarks>
public sealed class DurableHaltRequestedEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DurableHaltRequestedEvent"/> class.
/// </summary>
/// <param name="executorId">The ID of the executor that requested the halt.</param>
public DurableHaltRequestedEvent(string executorId) : base($"Halt requested by {executorId}")
{
this.ExecutorId = executorId;
}
/// <summary>
/// Gets the ID of the executor that requested the halt.
/// </summary>
public string ExecutorId { get; }
}
@@ -20,7 +20,7 @@ public sealed class DurableOptions
/// <summary>
/// Initializes a new instance of the <see cref="DurableOptions"/> class.
/// </summary>
public DurableOptions()
internal DurableOptions()
{
this.Workflows = new DurableWorkflowOptions(this);
}
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using Microsoft.Agents.AI.Workflows;
namespace Microsoft.Agents.AI.DurableTask;
/// <summary>
/// Event raised when the durable workflow is waiting for external input at a <see cref="RequestPort"/>.
/// </summary>
/// <param name="RequestPortId">The ID of the request port waiting for input.</param>
/// <param name="Input">The serialized input data that was passed to the RequestPort.</param>
/// <param name="RequestType">The full type name of the request type.</param>
/// <param name="ResponseType">The full type name of the expected response type.</param>
/// <param name="RequestPort">The request port definition, if available.</param>
public sealed class DurableRequestInfoEvent(
string RequestPortId,
string Input,
string RequestType,
string ResponseType,
RequestPort? RequestPort) : WorkflowEvent(Input)
{
/// <summary>
/// Gets the ID of the request port waiting for input.
/// </summary>
public string RequestPortId { get; } = RequestPortId;
/// <summary>
/// Gets the serialized input data that was passed to the RequestPort.
/// </summary>
public string Input { get; } = Input;
/// <summary>
/// Gets the full type name of the request type.
/// </summary>
public string RequestType { get; } = RequestType;
/// <summary>
/// Gets the full type name of the expected response type.
/// </summary>
public string ResponseType { get; } = ResponseType;
/// <summary>
/// Gets the request port definition, if available.
/// </summary>
public RequestPort? RequestPort { get; } = RequestPort;
/// <summary>
/// Attempts to deserialize the input data to the specified type.
/// </summary>
/// <typeparam name="T">The type to deserialize to.</typeparam>
/// <returns>The deserialized input, or default if deserialization fails.</returns>
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Deserializing workflow types provided by the caller.")]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Deserializing workflow types provided by the caller.")]
public T? GetInputAs<T>()
{
try
{
return JsonSerializer.Deserialize<T>(this.Input);
}
catch (JsonException)
{
return default;
}
}
}
@@ -116,7 +116,7 @@ public sealed class DurableRun : IRun
/// <param name="eventData">The data to send with the event.</param>
/// <param name="cancellationToken">A cancellation token to observe.</param>
#pragma warning disable CA1030 // Use events where appropriate - This is intentionally a method that sends events to an orchestration
public async ValueTask SendExternalEventAsync(string eventName, object? eventData = null, CancellationToken cancellationToken = default)
internal async ValueTask SendExternalEventAsync(string eventName, object? eventData = null, CancellationToken cancellationToken = default)
#pragma warning restore CA1030
{
await this._client.RaiseEventAsync(
@@ -131,7 +131,7 @@ public sealed class DurableRun : IRun
/// </summary>
/// <param name="workflowEvent">The workflow event to send.</param>
/// <param name="cancellationToken">A cancellation token to observe.</param>
public ValueTask SendEventAsync(WorkflowEvent workflowEvent, CancellationToken cancellationToken = default)
internal ValueTask SendEventAsync(WorkflowEvent workflowEvent, CancellationToken cancellationToken = default)
=> this.SendExternalEventAsync("WorkflowEvent", workflowEvent, cancellationToken);
/// <summary>
@@ -238,49 +238,3 @@ public sealed class DurableRun : IRun
return default;
}
}
/// <summary>
/// Represents the execution status of a durable workflow run.
/// </summary>
public enum DurableRunStatus
{
/// <summary>
/// The orchestration instance was not found.
/// </summary>
NotFound,
/// <summary>
/// The orchestration is pending and has not started.
/// </summary>
Pending,
/// <summary>
/// The orchestration is currently running.
/// </summary>
Running,
/// <summary>
/// The orchestration completed successfully.
/// </summary>
Completed,
/// <summary>
/// The orchestration failed with an error.
/// </summary>
Failed,
/// <summary>
/// The orchestration was terminated.
/// </summary>
Terminated,
/// <summary>
/// The orchestration is suspended.
/// </summary>
Suspended,
/// <summary>
/// The orchestration status is unknown.
/// </summary>
Unknown
}
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.Agents.AI.DurableTask;
/// <summary>
/// Represents the execution status of a durable workflow run.
/// </summary>
public enum DurableRunStatus
{
/// <summary>
/// The orchestration instance was not found.
/// </summary>
NotFound,
/// <summary>
/// The orchestration is pending and has not started.
/// </summary>
Pending,
/// <summary>
/// The orchestration is currently running.
/// </summary>
Running,
/// <summary>
/// The orchestration completed successfully.
/// </summary>
Completed,
/// <summary>
/// The orchestration failed with an error.
/// </summary>
Failed,
/// <summary>
/// The orchestration was terminated.
/// </summary>
Terminated,
/// <summary>
/// The orchestration is suspended.
/// </summary>
Suspended,
/// <summary>
/// The orchestration status is unknown.
/// </summary>
Unknown
}
@@ -473,158 +473,3 @@ public sealed class DurableStreamingRun : IStreamingRun
return requestPorts;
}
}
/// <summary>
/// Event raised when the durable workflow is waiting for external input at a <see cref="RequestPort"/>.
/// </summary>
/// <param name="RequestPortId">The ID of the request port waiting for input.</param>
/// <param name="Input">The serialized input data that was passed to the RequestPort.</param>
/// <param name="RequestType">The full type name of the request type.</param>
/// <param name="ResponseType">The full type name of the expected response type.</param>
/// <param name="RequestPort">The request port definition, if available.</param>
public sealed class DurableRequestInfoEvent(
string RequestPortId,
string Input,
string RequestType,
string ResponseType,
RequestPort? RequestPort) : WorkflowEvent(Input)
{
/// <summary>
/// Gets the ID of the request port waiting for input.
/// </summary>
public string RequestPortId { get; } = RequestPortId;
/// <summary>
/// Gets the serialized input data that was passed to the RequestPort.
/// </summary>
public string Input { get; } = Input;
/// <summary>
/// Gets the full type name of the request type.
/// </summary>
public string RequestType { get; } = RequestType;
/// <summary>
/// Gets the full type name of the expected response type.
/// </summary>
public string ResponseType { get; } = ResponseType;
/// <summary>
/// Gets the request port definition, if available.
/// </summary>
public RequestPort? RequestPort { get; } = RequestPort;
/// <summary>
/// Attempts to deserialize the input data to the specified type.
/// </summary>
/// <typeparam name="T">The type to deserialize to.</typeparam>
/// <returns>The deserialized input, or default if deserialization fails.</returns>
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Deserializing workflow types provided by the caller.")]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Deserializing workflow types provided by the caller.")]
public T? GetInputAs<T>()
{
try
{
return JsonSerializer.Deserialize<T>(this.Input);
}
catch (JsonException)
{
return default;
}
}
}
/// <summary>
/// Event raised when a durable workflow completes successfully.
/// </summary>
public sealed class DurableWorkflowCompletedEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DurableWorkflowCompletedEvent"/> class.
/// </summary>
/// <param name="result">The serialized result of the workflow.</param>
public DurableWorkflowCompletedEvent(string? result) : base(result)
{
this.Result = result;
}
/// <summary>
/// Gets the serialized result of the workflow.
/// </summary>
public string? Result { get; }
}
/// <summary>
/// Event raised when a durable workflow fails.
/// </summary>
public sealed class DurableWorkflowFailedEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DurableWorkflowFailedEvent"/> class.
/// </summary>
/// <param name="errorMessage">The error message describing the failure.</param>
public DurableWorkflowFailedEvent(string errorMessage) : base(errorMessage)
{
this.ErrorMessage = errorMessage;
}
/// <summary>
/// Gets the error message describing the failure.
/// </summary>
public string ErrorMessage { get; }
}
/// <summary>
/// Event raised when an executor yields intermediate output via <see cref="IWorkflowContext.YieldOutputAsync"/>.
/// </summary>
/// <remarks>
/// This is the durable equivalent of <see cref="WorkflowOutputEvent"/> since that class has an internal
/// constructor not accessible from outside the Workflows assembly.
/// </remarks>
public sealed class DurableYieldedOutputEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DurableYieldedOutputEvent"/> class.
/// </summary>
/// <param name="executorId">The ID of the executor that yielded the output.</param>
/// <param name="output">The yielded output value.</param>
public DurableYieldedOutputEvent(string executorId, object output) : base(output)
{
this.ExecutorId = executorId;
this.Output = output;
}
/// <summary>
/// Gets the ID of the executor that yielded the output.
/// </summary>
public string ExecutorId { get; }
/// <summary>
/// Gets the yielded output value.
/// </summary>
public object Output { get; }
}
/// <summary>
/// Event raised when an executor requests the workflow to halt via <see cref="IWorkflowContext.RequestHaltAsync"/>.
/// </summary>
/// <remarks>
/// This is the durable equivalent of the internal RequestHaltEvent since that class is not accessible
/// from outside the Workflows assembly.
/// </remarks>
public sealed class DurableHaltRequestedEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DurableHaltRequestedEvent"/> class.
/// </summary>
/// <param name="executorId">The ID of the executor that requested the halt.</param>
public DurableHaltRequestedEvent(string executorId) : base($"Halt requested by {executorId}")
{
this.ExecutorId = executorId;
}
/// <summary>
/// Gets the ID of the executor that requested the halt.
/// </summary>
public string ExecutorId { get; }
}
@@ -8,7 +8,7 @@ namespace Microsoft.Agents.AI.DurableTask;
/// <summary>
/// Provides methods to run workflows as durable orchestrations.
/// </summary>
public static class DurableWorkflow
internal static class DurableWorkflow
{
/// <summary>
/// Runs a workflow as a durable orchestration and returns a handle to monitor its execution.
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Agents.AI.Workflows;
namespace Microsoft.Agents.AI.DurableTask;
/// <summary>
/// Event raised when a durable workflow completes successfully.
/// </summary>
public sealed class DurableWorkflowCompletedEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DurableWorkflowCompletedEvent"/> class.
/// </summary>
/// <param name="result">The serialized result of the workflow.</param>
public DurableWorkflowCompletedEvent(string? result) : base(result)
{
this.Result = result;
}
/// <summary>
/// Gets the serialized result of the workflow.
/// </summary>
public string? Result { get; }
}
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Agents.AI.Workflows;
namespace Microsoft.Agents.AI.DurableTask;
/// <summary>
/// Event raised when a durable workflow fails.
/// </summary>
public sealed class DurableWorkflowFailedEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DurableWorkflowFailedEvent"/> class.
/// </summary>
/// <param name="errorMessage">The error message describing the failure.</param>
public DurableWorkflowFailedEvent(string errorMessage) : base(errorMessage)
{
this.ErrorMessage = errorMessage;
}
/// <summary>
/// Gets the error message describing the failure.
/// </summary>
public string ErrorMessage { get; }
}
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Agents.AI.Workflows;
namespace Microsoft.Agents.AI.DurableTask;
/// <summary>
/// Event raised when an executor yields intermediate output via <see cref="IWorkflowContext.YieldOutputAsync"/>.
/// </summary>
/// <remarks>
/// This is the durable equivalent of <see cref="WorkflowOutputEvent"/> since that class has an internal
/// constructor not accessible from outside the Workflows assembly.
/// </remarks>
public sealed class DurableYieldedOutputEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="DurableYieldedOutputEvent"/> class.
/// </summary>
/// <param name="executorId">The ID of the executor that yielded the output.</param>
/// <param name="output">The yielded output value.</param>
public DurableYieldedOutputEvent(string executorId, object output) : base(output)
{
this.ExecutorId = executorId;
this.Output = output;
}
/// <summary>
/// Gets the ID of the executor that yielded the output.
/// </summary>
public string ExecutorId { get; }
/// <summary>
/// Gets the yielded output value.
/// </summary>
public object Output { get; }
}