Skip to content

Commit 9a37411

Browse files
joslatCopilotlokitothcrickman
authored
.NET: Joslat fix sample issue (microsoft#3270)
* adds support for labels in edges, fixes rendering of labels in dot and mermaid, adds rendering of labels in edges * Update dotnet/src/Microsoft.Agents.AI.Workflows/Visualization/WorkflowVisualizer.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * escaping edge labels, adding tests for labels containing strange characters that would break the diagram and enabling the previous signature so the API has backwards compatibility. * Unify label in EdgeData * Edge API adjustments, removed useless "sanitizer" * fixed test * Fix in Sample * update --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jacob Alber <jaalber@microsoft.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
1 parent ea7818d commit 9a37411

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

  • dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors

dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static async Task Main()
129129
private static async Task ExecuteWorkflowAsync(Workflow workflow, string input)
130130
{
131131
// Configure whether to show agent thinking in real-time
132-
const bool ShowAgentThinking = false;
132+
const bool ShowAgentThinking = true;
133133

134134
// Execute in streaming mode to see real-time progress
135135
await using StreamingRun run = await InProcessExecution.StreamAsync(workflow, input);
@@ -230,14 +230,23 @@ public override async ValueTask HandleAsync(string message, IWorkflowContext con
230230
/// Executor that synchronizes agent output and prepares it for the next stage.
231231
/// This demonstrates how executors can process agent outputs and forward to the next agent.
232232
/// </summary>
233-
internal sealed class JailbreakSyncExecutor() : Executor<ChatMessage>("JailbreakSync")
233+
/// <remarks>
234+
/// The AIAgentHostExecutor sends response.Messages which has runtime type List&lt;ChatMessage&gt;.
235+
/// The message router uses exact type matching via message.GetType().
236+
/// </remarks>
237+
internal sealed class JailbreakSyncExecutor() : Executor<List<ChatMessage>>("JailbreakSync")
234238
{
235-
public override async ValueTask HandleAsync(ChatMessage message, IWorkflowContext context, CancellationToken cancellationToken = default)
239+
public override async ValueTask HandleAsync(List<ChatMessage> message, IWorkflowContext context, CancellationToken cancellationToken = default)
236240
{
237241
Console.WriteLine(); // New line after agent streaming
238242
Console.ForegroundColor = ConsoleColor.Magenta;
239243

240-
string fullAgentResponse = message.Text?.Trim() ?? "UNKNOWN";
244+
// Combine all response messages (typically just one for simple agents)
245+
string fullAgentResponse = string.Join("\n", message.Select(m => m.Text?.Trim() ?? "")).Trim();
246+
if (string.IsNullOrEmpty(fullAgentResponse))
247+
{
248+
fullAgentResponse = "UNKNOWN";
249+
}
241250

242251
Console.WriteLine($"[{this.Id}] Full Agent Response:");
243252
Console.WriteLine(fullAgentResponse);
@@ -278,17 +287,24 @@ public override async ValueTask HandleAsync(ChatMessage message, IWorkflowContex
278287
/// <summary>
279288
/// Executor that outputs the final result and marks the end of the workflow.
280289
/// </summary>
281-
internal sealed class FinalOutputExecutor() : Executor<ChatMessage, string>("FinalOutput")
290+
/// <remarks>
291+
/// The AIAgentHostExecutor sends response.Messages which has runtime type List&lt;ChatMessage&gt;.
292+
/// The message router uses exact type matching via message.GetType().
293+
/// </remarks>
294+
internal sealed class FinalOutputExecutor() : Executor<List<ChatMessage>, string>("FinalOutput")
282295
{
283-
public override ValueTask<string> HandleAsync(ChatMessage message, IWorkflowContext context, CancellationToken cancellationToken = default)
296+
public override ValueTask<string> HandleAsync(List<ChatMessage> message, IWorkflowContext context, CancellationToken cancellationToken = default)
284297
{
298+
// Combine all response messages (typically just one for simple agents)
299+
string combinedText = string.Join("\n", message.Select(m => m.Text ?? "")).Trim();
300+
285301
Console.WriteLine(); // New line after agent streaming
286302
Console.ForegroundColor = ConsoleColor.Green;
287303
Console.WriteLine($"\n[{this.Id}] Final Response:");
288-
Console.WriteLine($"{message.Text}");
304+
Console.WriteLine($"{combinedText}");
289305
Console.WriteLine("\n[End of Workflow]");
290306
Console.ResetColor();
291307

292-
return ValueTask.FromResult(message.Text ?? string.Empty);
308+
return ValueTask.FromResult(combinedText);
293309
}
294310
}

0 commit comments

Comments
 (0)