.NET: [BREAKING] feat: Improve Agent hosting inside Workflows#3142
Merged
.NET: [BREAKING] feat: Improve Agent hosting inside Workflows#3142
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the Agent hosting capabilities within Workflows by introducing comprehensive support for Human-in-the-Loop (HIL) scenarios, uninvoked function calls, and configurable execution behavior. The changes enable more flexible agent orchestration patterns and better control over message flow and event emission.
Key Changes:
- Introduces
AIAgentHostOptionsto provide fine-grained configuration for agent hosting (replacing the previous boolean flag) - Adds support for intercepting and handling
UserInputRequestContentandFunctionCallContentthrough dynamic port registration - Implements role reassignment capabilities to allow agents to see other agents' messages as user messages
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| AIAgentHostOptions.cs | New configuration class for agent hosting behavior with properties for event emission, request interception, role reassignment, and message forwarding |
| AIAgentHostExecutor.cs | Major refactor to support request interception, port handlers, turn continuation, and configurable event emission |
| AIAgentBinding.cs | Breaking change - now accepts AIAgentHostOptions instead of a boolean, maintains backward compatibility with overload |
| RouteBuilder.cs | Adds AddPortHandler method to support dynamic port registration and routing |
| Executor.cs | Adds Configure method to enable port handler registration via IExternalRequestContext |
| ChatProtocolExecutor.cs | Adds AutoSendTurnToken option and ProcessTurnMessagesAsync helper method |
| EdgeMap.cs | Adds TryRegisterPort method for dynamic port registration at runtime |
| InProcessRunnerContext.cs | Splits binding into BindExternalRequestContext and BindWorkflowContext for proper lifecycle management |
| AIContentExternalHandler.cs | New helper class for managing pending requests and responses for AIContent-based request/response patterns |
| RequestPortExtensions.cs | New extension methods for validating and processing ExternalResponse messages |
| PortBinding.cs | New class representing the binding between a RequestPort and its sink |
| AgentWorkflowBuilder.cs | Updated to use new AIAgentHostOptions with proper role reassignment and message forwarding |
| AggregateTurnMessagesExecutor.cs | Renamed from CollectChatMessagesExecutor for clarity |
| TestRequestAgent.cs | New comprehensive test agent supporting function calls and user input requests |
| TestReplayAgent.cs | Extracted from SpecializedExecutorSmokeTests for reuse |
| RoleCheckAgent.cs | New test agent for validating role reassignment behavior |
| AIAgentHostExecutorTests.cs | Comprehensive test coverage for new agent hosting features |
| DynamicRequestPortTests.cs | Tests for dynamic port registration and message delivery |
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestRequestAgent.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows/ChatProtocolExecutor.cs
Outdated
Show resolved
Hide resolved
15a25dd to
c93cb93
Compare
c93cb93 to
6717b6c
Compare
TaoChenOSU
approved these changes
Jan 16, 2026
6717b6c to
5be91cc
Compare
alliscode
reviewed
Jan 20, 2026
alliscode
reviewed
Jan 20, 2026
dotnet/src/Microsoft.Agents.AI.Workflows/AIAgentsAbstractionsExtensions.cs
Outdated
Show resolved
Hide resolved
alliscode
approved these changes
Jan 20, 2026
5be91cc to
15d4ffc
Compare
15d4ffc to
074771f
Compare
074771f to
fa33a8b
Compare
This was referenced Jan 26, 2026
This was referenced Jan 27, 2026
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
…oft#3142) * refactor: Rename AggregateTurnMessagesExecutor * feat: Rework Agent Hosting for Configurability and HIL support * Adds support for selecting whether updates and/or full responses are emitted to events * Adds support for HIL/FunctionCalls (including interception) * Implements internal support for ExternalRequests from any executor (not just RequestPort) * test: Add tests for new AIAgentHostExecutor functionality * feat: Unify non-Handoff Agent Hosting * doc: More explicit documentation for `overwrite` in RouteBuilder
This was referenced Feb 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Our initial implementation of hosting Agents in Workflows unblocked a number of scenarios but had some rough edges, resulting in the need to create custom Executors for, e.g., implementing Orchestrations. This leads to accumulating inconsistencies in behaviour as fixes and changes come in, resulting in issues like #2888.
In addition, there is a lack of support for HIL in both cases, resulting in custom-built support for hosting Agents in Declarative Workflows.
Description
Breaking:
Contribution Checklist