-
Notifications
You must be signed in to change notification settings - Fork 1k
.NET: Sample on Worflows mixing Agents And Executors, showcasing best patte… #1562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET: Sample on Worflows mixing Agents And Executors, showcasing best patte… #1562
Conversation
…rns which are reusable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a foundational workflow sample demonstrating how to combine executors and agents sequentially, addressing a critical learning gap in the Agent Framework documentation. The sample implements a content moderation pipeline that shows developers how to bridge type mismatches between executors (working with simple types) and agents (requiring ChatMessage/TurnToken) using adapter executors.
Key Changes:
- Introduces sample 07_MixedWorkflowAgentsAndExecutors showing sequential Executor → Agent → Executor → Agent chaining
- Demonstrates adapter pattern for type conversion (string to ChatMessage) and chat protocol handling (TurnToken)
- Implements practical content moderation pipeline with jailbreak detection and safety-aware responses
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| 07_MixedWorkflowAgentsAndExecutors/README.md | Comprehensive documentation explaining adapter pattern, chat protocol requirements, and workflow architecture |
| 07_MixedWorkflowAgentsAndExecutors/Program.cs | Sample implementation with custom executors, adapter executors, and AI agents demonstrating sequential chaining |
| 07_MixedWorkflowAgentsAndExecutors/07_MixedWorkflowAgentsAndExecutors.csproj | Project configuration with required dependencies |
| Workflows/README.md | Updated table of contents to include new sample |
| agent-framework-dotnet.slnx | Added project reference to solution |
...samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
…WorkflowAgentsAndExecutors/Program.cs Co-authored-by: Copilot <[email protected]>
… patte… (#1562) * Sample on Worflows mixing Agents And Executors, showcasing best patterns which are reusable. * Update dotnet/samples/GettingStarted/Workflows/README.md Co-authored-by: Copilot <[email protected]> * Update dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs Co-authored-by: Copilot <[email protected]> * minor fix --------- Co-authored-by: Copilot <[email protected]>
|
@markwallace-microsoft, can we try to merge again? it failed due to "#1562 was automatically removed from the merge queue due to failed status checks." Wait, I see the issue : Error: /home/runner/work/agent-framework/agent-framework/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs(135,65): error CS0121: The call is ambiguous between the following methods or properties: 'InProcessExecution.StreamAsync(Workflow, string?, CancellationToken)' and 'InProcessExecution.StreamAsync(Workflow, TInput, string?, CancellationToken)' [/home/runner/work/agent-framework/agent-framework/dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/07_MixedWorkflowAgentsAndExecutors.csproj] This is a bit weird mesage, not? Let me see if i can improve this... |
|
Hi @alliscode & @markwallace-microsoft :) Fixed the last pending issue due to an ambiguous signature with: I guess this was added recently as when getting the last MAF bits it was not building :) - now it builds again. |
… patte… (microsoft#1562) * Sample on Worflows mixing Agents And Executors, showcasing best patterns which are reusable. * Update dotnet/samples/GettingStarted/Workflows/README.md Co-authored-by: Copilot <[email protected]> * Update dotnet/samples/GettingStarted/Workflows/_Foundational/07_MixedWorkflowAgentsAndExecutors/Program.cs Co-authored-by: Copilot <[email protected]> * minor fix * fixed ambiguous signature due to framework changes. --------- Co-authored-by: Copilot <[email protected]>
|
I am having a issue with this sample when I run it where the executors after the jailbreakDetector are not executed. Confirmed that the jailbreakDetector is working by setting the ShowAgentThinking to true, but after the agent's response (where the output format is correct) the workflow finishes abruptly without any exceptions. The executors after the jailbreakDetector (JailbreakSyncExecutor, responseAgent and FinalOutputExecutor) are not executed at all. Here is the output I get when I run the sample (with ShowAgentThinking set to true): And here is the mermaid string of the workflow: |
|
Hi @fthbrmnby thanks for checking this issue in! |
Root Cause AnalysisBreaking Change Assessment: AIAgentHostExecutor Message OutputSummaryThe Root CauseCommit Details
What ChangedBefore (old behavior): // Individual ChatMessage objects were sent one by one as they were built from streaming updates
ChatMessage? currentStreamingMessage = null;
// ... streaming logic ...
await context.SendMessageAsync(currentStreamingMessage, cancellationToken: cancellationToken).ConfigureAwait(false);After (new behavior): // The entire Messages collection is sent at once
await context.SendMessageAsync(updates.ToAgentRunResponse().Messages, cancellationToken: cancellationToken).ConfigureAwait(false);
// or in non-streaming mode:
await context.SendMessageAsync(response.Messages, cancellationToken: cancellationToken).ConfigureAwait(false);Technical DetailsMessage Router BehaviorThe // From MessageRouter.RouteMessageAsync
if (this._typedHandlers.TryGetValue(message.GetType(), out MessageHandlerF? handler))
{
result = await handler(message, context, cancellationToken).ConfigureAwait(false);
}This means:
Type Mismatch
Impact on Sample CodeOriginal Code (broken)internal sealed class JailbreakSyncExecutor() : Executor<ChatMessage>("JailbreakSync")
{
public override async ValueTask HandleAsync(ChatMessage message, ...)Fixed Code (working)internal sealed class JailbreakSyncExecutor() : Executor<List<ChatMessage>>("JailbreakSync")
{
public override async ValueTask HandleAsync(List<ChatMessage> message, ...)Affected PatternsAny executor that:
Must now be changed to accept RecommendationWhen connecting a custom executor after an AI agent in a workflow, use:
Related Files Changed
Workaround Alternatives
|
|
@joslat thank you. I think there should be a type checking mechanism between workflow executors or workflow edges where the workflow checks for message types and warn the user instead of skipping executors silently or the message types between executors should be added to |
Closes #1561 1561
Motivation and Context
Why is this change required?
Developers learning the Agent Framework face a critical learning gap when trying to integrate custom executors with AI agents in workflows. While existing samples demonstrate:
• Executor-only workflows (01_ExecutorsAndEdges, 02_Streaming)
• Agent-only workflows (03_AgentsInWorkflows, 04_AgentWorkflowPatterns)
• Concurrent fan-out/fan-in patterns (Concurrent, WorkflowAsAnAgent)
No foundational sample exists that teaches the sequential chaining pattern: Executor → Agent → Executor → Agent.
What problem does it solve?
This sample addresses three fundamental knowledge gaps:
• Message accumulation via context.SendMessageAsync(chatMessage)
• Processing trigger via context.SendMessageAsync(new TurnToken())
No existing sample explains or demonstrates this protocol.
• Why adapters are necessary
• How to implement them correctly
• How to chain multiple agents through executors
What scenario does it contribute to?
This sample demonstrates a real-world content moderation pipeline that:
• ✅ Accepts user input through an executor
• ✅ Processes data with deterministic executors (text transformation)
• ✅ Converts types using adapter executor (string → ChatMessage + TurnToken)
• ✅ Leverages AI agent for security analysis (jailbreak detection)
• ✅ Processes agent output with another adapter executor
• ✅ Chains to a second AI agent for final response
• ✅ Outputs formatted results through a final executor
Real-world use cases enabled:
• Content moderation and safety screening
• Multi-stage data enrichment (fetch → analyze → format → validate)
• Compliance checking with AI-powered decision making
• Quality assurance pipelines with AI reviewers
Related Issues
This PR addresses the foundational gap identified in the workflow samples learning path, specifically the missing bridge between basic executor/agent concepts (samples 01-04) and advanced patterns.
See #1561