Replies: 1 comment
-
|
This is reference aliasing, not Semantic Kernel intentionally rewriting history.
If Return a snapshot from read functions instead of the live state. For example: [KernelFunction("get_lights")]
public IReadOnlyList<LightSnapshot> GetLights() =>
_lights.Select(light => new LightSnapshot(
light.Id,
light.Name,
light.IsOn
)).ToArray();
public sealed record LightSnapshot(int Id, string Name, bool IsOn);The same rule should apply to mutation results: return new LightSnapshot(light.Id, light.Name, light.IsOn);Using immutable records is preferable to returning the domain entities. A JSON round-trip/deep copy would also break the reference, but a dedicated snapshot DTO is cheaper and makes the history semantics explicit. A minimal confirmation is: var first = GetLights();
ChangeState(2, true);
Assert.False(first.Single(x => x.Id == 2).IsOn);That assertion will fail when |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
Specs
Semantic Kernel1.65.0`Microsoft.SemanticKernel.Connectors.Ollama1.65.0-alphagpt-oss:20bWhat I have
A
LightsPluginlike the docs example. I add the plugin to the kernel, create a history object with a simple system prompt ("You are a helpful assistant"). User messages are passed toGetChatMessageContentAsync(as part of the history) withFunctionChoiceBehavior.Auto()and the kernel for tool support.Repro steps
get_lightsfunction and returns the result.toggle_lightfunction; porch light successfully turns on.Problem
After step 2, the recorded history entry for the step 1 function call (
Microsoft.SemanticKernel.FunctionResultContent) is altered — it now shows the porch light as"on", even thoughget_lightsran before the toggle instruction. I confirmed this both in the debugger and by inspecting HTTP traffic (mitmproxy). Attached are raw request exports for step 1 and step 2 showing the altered history:Step 1 request
Step 2 request (after the porch light has been turned on)
Question
Is this expected behavior (i.e., are
FunctionResultContenthistory items mutated by later actions), or is something in my usage causing the earlier history item to be updated?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions