fix: extract tool arguments from ToolExecutionStartEvent in sidecar

The CopilotTurnExecutionState was ignoring ToolExecutionStartData.Arguments
when creating tool-calling activity events, despite the Copilot SDK providing
them. This caused the activity panel to show 'Viewed a file' / 'Used rg'
with no contextual details (file paths, search patterns, etc.).

The fix adds NormalizeRawToolArguments to WorkflowRequestInfoInterpreter for
converting the raw object? payload (typically JsonElement) into the normalized
dictionary, then passes ToolExecutionStartData.Arguments through
CreateToolCallingActivity.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David KayaandCopilot committed 2026-04-08 10:47:55 +02:00
1 parent 931ec27f42
commit 2c165e453f
6 files changed
+73 -3

No files matched your search

@@ -98,7 +98,8 @@ internal sealed class CopilotTurnExecutionState
string toolName = toolExecutionStart.Data.ToolName.Trim();
ToolNamesByCallId[toolCallId] = toolName;
ActiveAgent = agent;
AgentActivityEventDto? toolActivity = CreateToolCallingActivity(agent, toolName, toolCallId);
AgentActivityEventDto? toolActivity = CreateToolCallingActivity(
agent, toolName, toolCallId, toolExecutionStart.Data.Arguments);
if (toolActivity is not null)
{
_pendingEvents.Enqueue(toolActivity);
@@ -295,7 +296,8 @@ internal sealed class CopilotTurnExecutionState
private AgentActivityEventDto? CreateToolCallingActivity(
AgentIdentity agent,
string toolName,
string toolCallId)
string toolCallId,
object? rawArguments = null)
{
if (toolName.StartsWith("handoff_to_", StringComparison.Ordinal))
{
@@ -312,6 +314,7 @@ internal sealed class CopilotTurnExecutionState
AgentName = agent.AgentName,
ToolName = toolName,
ToolCallId = toolCallId,
ToolArguments = WorkflowRequestInfoInterpreter.NormalizeRawToolArguments(rawArguments),
};
}
@@ -205,6 +205,26 @@ internal static class WorkflowRequestInfoInterpreter
return false;
}
public static IReadOnlyDictionary<string, object?>? NormalizeRawToolArguments(object? rawArguments)
{
return rawArguments switch
{
null => null,
JsonElement { ValueKind: JsonValueKind.Object } element => NormalizeToolArgumentObject(element),
IEnumerable<KeyValuePair<string, object?>> dictionary => NormalizeToolArguments(dictionary),
_ => NormalizeRawToolArgumentsViaJson(rawArguments),
};
}
private static IReadOnlyDictionary<string, object?>? NormalizeRawToolArgumentsViaJson(object value)
{
string json = JsonSerializer.Serialize(value, value.GetType(), JsonOptions);
using JsonDocument document = JsonDocument.Parse(json);
return document.RootElement.ValueKind == JsonValueKind.Object
? NormalizeToolArgumentObject(document.RootElement)
: null;
}
private static IReadOnlyDictionary<string, object?>? NormalizeToolArguments(
IEnumerable<KeyValuePair<string, object?>>? arguments)
{