Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions dotnet/src/SemanticKernel.UnitTests/Orchestration/PlanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,39 @@ public void CanCreatePlanWithGoalAndSubPlans()
Assert.Equal(goal, plan.Description);
Assert.Equal(2, plan.Steps.Count);
}

[Fact]
public async Task CanExecutePlanWithOneStepAndStateAsync()
{
// Arrange
var kernel = new Mock<IKernel>();
var log = new Mock<ILogger>();
var memory = new Mock<ISemanticTextMemory>();
var skills = new Mock<ISkillCollection>();

var returnContext = new SKContext(
new ContextVariables(),
memory.Object,
skills.Object,
log.Object
);

var mockFunction = new Mock<ISKFunction>();
mockFunction.Setup(x => x.InvokeAsync(It.IsAny<SKContext>(), null, null, null))
.Callback<SKContext, CompleteRequestSettings, ILogger, CancellationToken?>((c, s, l, ct) =>
returnContext.Variables.Update("Here is a poem about " + c.Variables.Input))
.Returns(() => Task.FromResult(returnContext));


var plan = new Plan(mockFunction.Object);
plan.State.Set("input", "Cleopatra");

// Act
var result = await plan.InvokeAsync();

// Assert
Assert.NotNull(result);
Assert.Equal($"Here is a poem about Cleopatra", result.Result);
mockFunction.Verify(x => x.InvokeAsync(It.IsAny<SKContext>(), null, null, null), Times.Once);
}
}
2 changes: 1 addition & 1 deletion dotnet/src/SemanticKernel/Orchestration/Plan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public Task<SKContext> InvokeAsync(string input, SKContext? context = null, Comp
public async Task<SKContext> InvokeAsync(SKContext? context = null, CompleteRequestSettings? settings = null, ILogger? log = null,
CancellationToken? cancel = null)
{
context ??= new SKContext(new ContextVariables(), null!, null, log ?? NullLogger.Instance, cancel ?? CancellationToken.None);
context ??= new SKContext(this.State, null!, null, log ?? NullLogger.Instance, cancel ?? CancellationToken.None);

if (this.Function is not null)
{
Expand Down