Skip to content

Commit 70b7bdb

Browse files
.Net: KernelProcessEventData deserialized in LocalAgentStep (#13203)
### Motivation and Context 1. **Why is this change required?** Because `LocalAgentStep` was passing `KernelProcessEventData` wrappers directly into `KernelArguments`, unlike `LocalStep` which unwraps them. This inconsistency caused agents to receive JSON-like data instead of the actual payload. 2. **What problem does it solve?** It ensures that agents receive the real value (e.g. the user’s message text) instead of the wrapper object, preventing confusing model responses like *“you seem to be passing a json”*. 3. **What scenario does it contribute to?** Agent-based process pipelines (for example a simple chat process where user input is sent to an agent). The agent now correctly sees the user input as plain text or object, improving reliability and user experience. ### Description This PR updates `LocalAgentStep` so that it unwraps `KernelProcessEventData` before passing it into `KernelArguments["message"]`. * If `TargetEventData` is a `KernelProcessEventData`, we now call `.ToObject()` to get the real value. * If it is not, we keep the value as it is. * This makes `LocalAgentStep` consistent with `LocalStep.AssignStepFunctionParameterValues`. With this change, agents no longer receive the wrapper object but the actual payload (for example the plain user input), which avoids the model interpreting it as JSON. ### Contribution Checklist - [X] The code builds clean without any errors or warnings - [X] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [X] All unit tests pass - [X] I didn't break anyone 😄 Co-authored-by: Dmytro Struk <[email protected]>
1 parent 3eb869e commit 70b7bdb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

dotnet/src/Experimental/Process.LocalRuntime/LocalAgentStep.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ internal override async Task HandleMessageAsync(ProcessMessage message)
4545
await this._initializeTask.Value.ConfigureAwait(false);
4646

4747
string targetFunction = "Invoke";
48-
KernelArguments arguments = new() { { "message", message.TargetEventData }, { "writtenToThread", message.writtenToThread == this._agentThread.ThreadId } };
48+
KernelArguments arguments = new()
49+
{
50+
{ "message", message.TargetEventData switch
51+
{
52+
KernelProcessEventData proxyData => proxyData.ToObject(),
53+
_ => message.TargetEventData
54+
}
55+
},
56+
{ "writtenToThread", message.writtenToThread == this._agentThread.ThreadId }
57+
};
4958
if (!this._functions.TryGetValue(targetFunction, out KernelFunction? function) || function == null)
5059
{
5160
throw new ArgumentException($"Function Invoke not found in plugin {this.Name}");

0 commit comments

Comments
 (0)