// Copyright (c) Microsoft. All rights reserved. using System.Threading; using System.Threading.Tasks; using Microsoft.Agents.AI.Workflows.InProc; namespace Microsoft.Agents.AI.Workflows; /// /// Provides methods to initiate and manage in-process workflow executions, supporting both streaming and /// non-streaming modes with asynchronous operations. /// public static class InProcessExecution { /// /// The default InProcess execution environment. /// public static InProcessExecutionEnvironment Default => OffThread; /// /// An InProcessExecution environment which will run SuperSteps in a background thread, streaming /// events out as they are raised. /// public static InProcessExecutionEnvironment OffThread { get; } = new(ExecutionMode.OffThread); /// /// Gets an execution environment that enables concurrent, off-thread in-process execution. /// public static InProcessExecutionEnvironment Concurrent { get; } = new(ExecutionMode.OffThread, enableConcurrentRuns: true); /// /// An InProcesExecution environment which will run SuperSteps in the event watching thread, /// accumulating events during each SuperStep and streaming them out after each SuperStep is /// completed. /// public static InProcessExecutionEnvironment Lockstep { get; } = new(ExecutionMode.Lockstep); /// /// An InProcessExecution environment which will not run SuperSteps directly, relying instead /// on the hosting workflow to run them directly, while streaming events out as they are raised. /// internal static InProcessExecutionEnvironment Subworkflow { get; } = new(ExecutionMode.Subworkflow); /// public static ValueTask OpenStreamAsync(Workflow workflow, string? runId = null, CancellationToken cancellationToken = default) => Default.OpenStreamAsync(workflow, runId, cancellationToken); /// public static ValueTask StreamAsync(Workflow workflow, TInput input, string? runId = null, CancellationToken cancellationToken = default) where TInput : notnull => Default.StreamAsync(workflow, input, runId, cancellationToken); /// public static ValueTask> StreamAsync(Workflow workflow, CheckpointManager checkpointManager, string? runId = null, CancellationToken cancellationToken = default) => Default.StreamAsync(workflow, checkpointManager, runId, cancellationToken); /// public static ValueTask> StreamAsync(Workflow workflow, TInput input, CheckpointManager checkpointManager, string? runId = null, CancellationToken cancellationToken = default) where TInput : notnull => Default.StreamAsync(workflow, input, checkpointManager, runId, cancellationToken); /// public static ValueTask> ResumeStreamAsync(Workflow workflow, CheckpointInfo fromCheckpoint, CheckpointManager checkpointManager, CancellationToken cancellationToken = default) => Default.ResumeStreamAsync(workflow, fromCheckpoint, checkpointManager, cancellationToken); /// public static ValueTask RunAsync(Workflow workflow, TInput input, string? runId = null, CancellationToken cancellationToken = default) where TInput : notnull => Default.RunAsync(workflow, input, runId, cancellationToken); /// public static ValueTask> RunAsync(Workflow workflow, TInput input, CheckpointManager checkpointManager, string? runId = null, CancellationToken cancellationToken = default) where TInput : notnull => Default.RunAsync(workflow, input, checkpointManager, runId, cancellationToken); /// public static ValueTask> ResumeAsync(Workflow workflow, CheckpointInfo fromCheckpoint, CheckpointManager checkpointManager, CancellationToken cancellationToken = default) => Default.ResumeAsync(workflow, fromCheckpoint, checkpointManager, cancellationToken); }