mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
24ad03af6f
* test: Add Reflection/Invocation tests * fix: Terminate on Completion event * refactor: Update public API surface * feat: Add support for external requests * feat: Support hosting AIAgent instances in Workflows * fix: Fix routing to go through Executor.ExecuteAsync * test: Update samples for "must SendMessage" semantics * Add invoking samples to unit tests to avoid future breaks * fix: ExternalRequest should block Workflow completion * feat: Normalize API surface against Python * Also adds xmldoc to all public APIs * refactor: Normalize UnitTest and Sample namespaces * fix: Formatting * refactor: Normalize project/folder names * feat: Remove DynamicCodeExecution from ValueTaskTypeErasure * fix: Fix ILTrim warnings * docs: Add missing docs and fix typos * feat: Hosted Agents should report Run events * fix: Fix type propagation for ILTrim changes * refactor: Simplify DynamicallyAccessedMembers annotations * sample: Use static-Type construction of InputPort * feat: Support non-Streaming Run Mode * test: Add test for non-streaming execution * Conversion checkpoint * Fix namespace error * Restructure * Completion * Executor checkpoint * Conditional checkpoint * Cleanup * Exception cleanup * Sample cleanup * Updates * feat: Define Workflow and Executor APIs * feat: Define IExecutionContext and Events * feat: Simple Workflow Demos * refactor: Move Workflows classes to separate assembly * feat: Move FanOut/In to LowLevel API with new semantics * feat: Implement Local Execution * refactor: Assembly name .Workflow => .Workflows * feat: Enable Default Message Handling * also lifts Bind in MessageHandlerInfo to better be able to direclty invoke handlers (for AOT, later) * feat: Implement StreamingHandle APIs This allows the user to respond to WorkflowEvents with external messages, enabling HIL. * feat: Add checks for duplicate edges and chain cycles * feat: Add built-in WorkflowEvents * refactor: Pull classes into own files * refactor: Simplify Disposal pattern in Executor * refactor: Break EdgeRunner file into per-type files * refactor: Use Throw.IfNull() * refactor: Remove AddLoop() Per https://github.com/microsoft/agent-framework/pull/272#discussion_r2241739079 we decided this was not very useful. * refactor: Normalize use of ValueTask * fix: Build Break from removing .AddLoop * refactor: Explicit routing and RouteBuilder Split out reflection from MessageRouter implemention into build phase, enabling AOT compilation to drive RouteBuilding without reflection. * test: Add Reflection/Invocation tests * fix: Terminate on Completion event * refactor: Update public API surface * feat: Add support for external requests * feat: Support hosting AIAgent instances in Workflows * fix: Fix routing to go through Executor.ExecuteAsync * test: Update samples for "must SendMessage" semantics * Add invoking samples to unit tests to avoid future breaks * fix: ExternalRequest should block Workflow completion * feat: Normalize API surface against Python * Also adds xmldoc to all public APIs * refactor: Normalize UnitTest and Sample namespaces * fix: Formatting * refactor: Normalize project/folder names * feat: Remove DynamicCodeExecution from ValueTaskTypeErasure * fix: Fix ILTrim warnings * docs: Add missing docs and fix typos * feat: Hosted Agents should report Run events * fix: Fix type propagation for ILTrim changes * refactor: Simplify DynamicallyAccessedMembers annotations * sample: Use static-Type construction of InputPort * feat: Support non-Streaming Run Mode * test: Add test for non-streaming execution * refactor: Remove unused types * refactor: Simplify Event and EdgeData type hierarchies * feat: Add Switch (=Conditional Edge Group) control flow * Fix unit-tests * Add sample * Comment cleanup * Fix debug output * Formating helpers * feat: Define Workflow and Executor APIs * feat: Define IExecutionContext and Events * feat: Simple Workflow Demos * refactor: Move Workflows classes to separate assembly * feat: Move FanOut/In to LowLevel API with new semantics * feat: Implement Local Execution * refactor: Assembly name .Workflow => .Workflows * feat: Enable Default Message Handling * also lifts Bind in MessageHandlerInfo to better be able to direclty invoke handlers (for AOT, later) * feat: Implement StreamingHandle APIs This allows the user to respond to WorkflowEvents with external messages, enabling HIL. * feat: Add checks for duplicate edges and chain cycles * feat: Add built-in WorkflowEvents * refactor: Pull classes into own files * refactor: Simplify Disposal pattern in Executor * refactor: Break EdgeRunner file into per-type files * refactor: Use Throw.IfNull() * refactor: Remove AddLoop() Per https://github.com/microsoft/agent-framework/pull/272#discussion_r2241739079 we decided this was not very useful. * refactor: Normalize use of ValueTask * fix: Build Break from removing .AddLoop * refactor: Explicit routing and RouteBuilder Split out reflection from MessageRouter implemention into build phase, enabling AOT compilation to drive RouteBuilding without reflection. * test: Add Reflection/Invocation tests * fix: Terminate on Completion event * refactor: Update public API surface * feat: Add support for external requests * feat: Support hosting AIAgent instances in Workflows * fix: Fix routing to go through Executor.ExecuteAsync * test: Update samples for "must SendMessage" semantics * Add invoking samples to unit tests to avoid future breaks * fix: ExternalRequest should block Workflow completion * feat: Normalize API surface against Python * Also adds xmldoc to all public APIs * refactor: Normalize UnitTest and Sample namespaces * fix: Formatting * refactor: Normalize project/folder names * feat: Remove DynamicCodeExecution from ValueTaskTypeErasure * fix: Fix ILTrim warnings * docs: Add missing docs and fix typos * feat: Hosted Agents should report Run events * fix: Fix type propagation for ILTrim changes * refactor: Simplify DynamicallyAccessedMembers annotations * sample: Use static-Type construction of InputPort * feat: Support non-Streaming Run Mode * test: Add test for non-streaming execution * refactor: Remove unused types * refactor: Simplify Event and EdgeData type hierarchies * feat: Add Switch (=Conditional Edge Group) control flow * feat: Make .NET AutoSend the MessageHandler result * feat: Implement State APIs * Add tests * Fix merge from main * Test coverage * Message event * Comments and clean-up * Format * Cleanup * Test checkpoint * Clean-up - comments / test * Test baseline - 100% * More clean-up * Comments * Streaming...sort've... * Fix build / test * Stable * Checkpoint * Checkpoint * Stable * Update sample after merge * Add "Question" workflow * State clean-up checkpoint * State clean-up * Sample updated * Expression bug fix * Sample formatting * Add unit test * Comments * Scope cleanup * Refine cleanup * Fill gaps * fcs * Finalize data-types * Add unit-test * Debug cleanup * Bug fixes * Demo progress * Sample clean-up * Update samples * Sample updates * Sync demo workflows * Sample formatting * Sample formatting * Demo complete * Workflow formatting * Demo formatting #2 * Readme + Sample clean-up * Scope update * Update diagnostics * Variable initiaization * Rollback * Tune research summary * State management * Fix merge * Fix merge - demo * Add readme * Overload for workflow builder * Fault tolerance - scope equivalency * Fix feed * Update sample * Add default for "Bot" * Nuget.config patchwork * Scope assignment check * Rollback nuget.config haxx * Sample format * Namespace * Namespace * Agent-Provider * Clean-up extra files * Renaming * Update sample * Prune junk files * Clean-up * Use transform * agent provider fix * Typo * Null check fix * Fix merge * Checkpoint * Cleanup * Exception cleanup * Exception message * Clean-up * Sample config update * Update handling of "Env" scope * Sample agent templates * Add readme * Event cleanup * Rename event * Update workflows/README.md Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com> --------- Co-authored-by: Jacob Alber <jaalber@microsoft.com> Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
186 lines
5.2 KiB
C#
186 lines
5.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Linq;
|
|
using Microsoft.Agents.Workflows.Declarative.PowerFx;
|
|
using Microsoft.Bot.ObjectModel;
|
|
using Microsoft.PowerFx.Types;
|
|
|
|
namespace Microsoft.Agents.Workflows.Declarative.UnitTests.PowerFx;
|
|
|
|
public class WorkflowScopesTests
|
|
{
|
|
[Fact]
|
|
public void ConstructorInitializesAllScopes()
|
|
{
|
|
// Arrange & Act
|
|
WorkflowScopes scopes = new();
|
|
|
|
// Assert
|
|
RecordValue envRecord = scopes.BuildRecord(VariableScopeNames.Environment);
|
|
RecordValue topicRecord = scopes.BuildRecord(VariableScopeNames.Topic);
|
|
RecordValue globalRecord = scopes.BuildRecord(VariableScopeNames.Global);
|
|
RecordValue systemRecord = scopes.BuildRecord(VariableScopeNames.System);
|
|
|
|
Assert.NotNull(envRecord);
|
|
Assert.NotNull(topicRecord);
|
|
Assert.NotNull(globalRecord);
|
|
Assert.NotNull(systemRecord);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildRecordWhenEmpty()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
|
|
// Act
|
|
RecordValue record = scopes.BuildRecord(VariableScopeNames.Topic);
|
|
|
|
// Assert
|
|
Assert.NotNull(record);
|
|
Assert.Empty(record.Fields);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildRecordContainsSetValues()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
FormulaValue testValue = FormulaValue.New("test");
|
|
scopes.Set("key1", testValue, VariableScopeNames.Topic);
|
|
|
|
// Act
|
|
RecordValue record = scopes.BuildRecord(VariableScopeNames.Topic);
|
|
|
|
// Assert
|
|
Assert.NotNull(record);
|
|
Assert.Single(record.Fields);
|
|
Assert.Equal("key1", record.Fields.First().Name);
|
|
Assert.Equal(testValue, record.Fields.First().Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildRecordForAllScopeTypes()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
FormulaValue testValue = FormulaValue.New("test");
|
|
|
|
// Act & Assert
|
|
scopes.Set("envKey", testValue, VariableScopeNames.Environment);
|
|
RecordValue envRecord = scopes.BuildRecord(VariableScopeNames.Environment);
|
|
Assert.Single(envRecord.Fields);
|
|
|
|
scopes.Set("topicKey", testValue, VariableScopeNames.Topic);
|
|
RecordValue topicRecord = scopes.BuildRecord(VariableScopeNames.Topic);
|
|
Assert.Single(topicRecord.Fields);
|
|
|
|
scopes.Set("globalKey", testValue, VariableScopeNames.Global);
|
|
RecordValue globalRecord = scopes.BuildRecord(VariableScopeNames.Global);
|
|
Assert.Single(globalRecord.Fields);
|
|
|
|
scopes.Set("systemKey", testValue, VariableScopeNames.System);
|
|
RecordValue systemRecord = scopes.BuildRecord(VariableScopeNames.System);
|
|
Assert.Single(systemRecord.Fields);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetWithImplicitScope()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
FormulaValue testValue = FormulaValue.New("test");
|
|
scopes.Set("key1", testValue, VariableScopeNames.Topic);
|
|
|
|
// Act
|
|
FormulaValue result = scopes.Get("key1");
|
|
|
|
// Assert
|
|
Assert.Equal(testValue, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetWithSpecifiedScope()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
FormulaValue testValue = FormulaValue.New("test");
|
|
scopes.Set("key1", testValue, VariableScopeNames.Global);
|
|
|
|
// Act
|
|
FormulaValue result = scopes.Get("key1", VariableScopeNames.Global);
|
|
|
|
// Assert
|
|
Assert.Equal(testValue, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetDefaultScope()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
FormulaValue testValue = FormulaValue.New("test");
|
|
|
|
// Act
|
|
scopes.Set("key1", testValue);
|
|
|
|
// Assert
|
|
FormulaValue result = scopes.Get("key1", VariableScopeNames.Topic);
|
|
Assert.Equal(testValue, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetSpecifiedScope()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
FormulaValue testValue = FormulaValue.New("test");
|
|
|
|
// Act
|
|
scopes.Set("key1", testValue, VariableScopeNames.System);
|
|
|
|
// Assert
|
|
FormulaValue result = scopes.Get("key1", VariableScopeNames.System);
|
|
Assert.Equal(testValue, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void SetOverwritesExistingValue()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
FormulaValue initialValue = FormulaValue.New("initial");
|
|
FormulaValue newValue = FormulaValue.New("new");
|
|
|
|
// Act
|
|
scopes.Set("key1", initialValue, VariableScopeNames.Topic);
|
|
scopes.Set("key1", newValue, VariableScopeNames.Topic);
|
|
|
|
// Assert
|
|
FormulaValue result = scopes.Get("key1", VariableScopeNames.Topic);
|
|
Assert.Equal(newValue, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void RemoveSpecifiedScope()
|
|
{
|
|
// Arrange
|
|
WorkflowScopes scopes = new();
|
|
FormulaValue testValue = FormulaValue.New("test");
|
|
|
|
// Act
|
|
scopes.Set("key1", testValue);
|
|
|
|
// Assert
|
|
FormulaValue result = scopes.Get("key1");
|
|
Assert.Equal(testValue, result);
|
|
|
|
// Act
|
|
scopes.Reset("key1");
|
|
|
|
// Assert
|
|
FormulaValue resultBlank = scopes.Get("key1");
|
|
Assert.IsType<BlankValue>(resultBlank);
|
|
}
|
|
}
|