Skip to content

Conversation

@joslat
Copy link
Contributor

@joslat joslat commented Oct 19, 2025

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:

  1. Type Mismatch Problem: Executors naturally work with simple types (string, int, custom objects), while agents expect ChatMessage or List. Without guidance, developers don't understand why direct connections fail.
  2. Chat Protocol Requirements: Agents use ChatProtocolExecutor internally and require both:
    • Message accumulation via context.SendMessageAsync(chatMessage)
    • Processing trigger via context.SendMessageAsync(new TurnToken())
    No existing sample explains or demonstrates this protocol.
  3. Adapter Pattern Implementation: Developers need translator executors to bridge the gap, but no sample shows:
    • 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

@Copilot Copilot AI review requested due to automatic review settings October 19, 2025 21:34
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation .NET labels Oct 19, 2025
@github-actions github-actions bot changed the title Sample on Worflows mixing Agents And Executors, showcasing best patte… .NET: Sample on Worflows mixing Agents And Executors, showcasing best patte… Oct 19, 2025
Copy link
Contributor

Copilot AI left a 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

@markwallace-microsoft markwallace-microsoft added this pull request to the merge queue Oct 21, 2025
github-merge-queue bot pushed a commit that referenced this pull request Oct 21, 2025
… 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]>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 21, 2025
@joslat
Copy link
Contributor Author

joslat commented Oct 21, 2025

@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."
But here I see everything green...

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]
0 Warning(s)
1 Error(s)

This is a bit weird mesage, not? Let me see if i can improve this...

@joslat
Copy link
Contributor Author

joslat commented Oct 21, 2025

Hi @alliscode & @markwallace-microsoft :)

Fixed the last pending issue due to an ambiguous signature with:
await using StreamingRun run = await InProcessExecution.StreamAsync(workflow, input);

I guess this was added recently as when getting the last MAF bits it was not building :) - now it builds again.

@joslat joslat requested a review from alliscode October 21, 2025 13:04
@alliscode alliscode enabled auto-merge October 21, 2025 21:19
@alliscode alliscode added this pull request to the merge queue Oct 21, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 21, 2025
@alliscode alliscode added this pull request to the merge queue Oct 21, 2025
Merged via the queue into microsoft:main with commit 4554de0 Oct 21, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Need for Simplified Sample Demonstrating Executor-Agent Integration in Workflows

3 participants