Skip to content

.NET: [BREAKING] feat: Improve Agent hosting inside Workflows - #3142

Merged
Jacob Alber (lokitoth) merged 5 commits into
mainfrom
dev/dotnet_workflow/agent_hosting_improvements
Jan 23, 2026
Merged

.NET: [BREAKING] feat: Improve Agent hosting inside Workflows#3142
Jacob Alber (lokitoth) merged 5 commits into
mainfrom
dev/dotnet_workflow/agent_hosting_improvements

Conversation

@lokitoth

Copy link
Copy Markdown
Contributor

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

  • Adds support for HIL and uninvoked FunctionCalls for hosted agents
  • Adds configurability for emitting streaming updates and the final combined response
  • Adds support for forwarding the incoming conversation to make supporting things like Handoffs easier
  • Adds support for overwriting other agents' ChatRole when invoking hosted agents
  • Builds out internal-only support for direct ExternalRequest "raising" by Executor

Breaking:

  • Changes AIAgentBinding to contain AIAgentHostOptions rather than a bool

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

CopilotAI review requested due to automatic review settings January 8, 2026 16:15
@lokitothJacob Alber (lokitoth) added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible labels Jan 8, 2026

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 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 AIAgentHostOptions to provide fine-grained configuration for agent hosting (replacing the previous boolean flag)
  • Adds support for intercepting and handling UserInputRequestContent and FunctionCallContent through 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
FileDescription
AIAgentHostOptions.csNew configuration class for agent hosting behavior with properties for event emission, request interception, role reassignment, and message forwarding
AIAgentHostExecutor.csMajor refactor to support request interception, port handlers, turn continuation, and configurable event emission
AIAgentBinding.csBreaking change - now accepts AIAgentHostOptions instead of a boolean, maintains backward compatibility with overload
RouteBuilder.csAdds AddPortHandler method to support dynamic port registration and routing
Executor.csAdds Configure method to enable port handler registration via IExternalRequestContext
ChatProtocolExecutor.csAdds AutoSendTurnToken option and ProcessTurnMessagesAsync helper method
EdgeMap.csAdds TryRegisterPort method for dynamic port registration at runtime
InProcessRunnerContext.csSplits binding into BindExternalRequestContext and BindWorkflowContext for proper lifecycle management
AIContentExternalHandler.csNew helper class for managing pending requests and responses for AIContent-based request/response patterns
RequestPortExtensions.csNew extension methods for validating and processing ExternalResponse messages
PortBinding.csNew class representing the binding between a RequestPort and its sink
AgentWorkflowBuilder.csUpdated to use new AIAgentHostOptions with proper role reassignment and message forwarding
AggregateTurnMessagesExecutor.csRenamed from CollectChatMessagesExecutor for clarity
TestRequestAgent.csNew comprehensive test agent supporting function calls and user input requests
TestReplayAgent.csExtracted from SpecializedExecutorSmokeTests for reuse
RoleCheckAgent.csNew test agent for validating role reassignment behavior
AIAgentHostExecutorTests.csComprehensive test coverage for new agent hosting features
DynamicRequestPortTests.csTests for dynamic port registration and message delivery

Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/AIAgentHostOptions.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Outdated
Comment threaddotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/TestRequestAgent.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/AIAgentHostOptions.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/PortBinding.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AIAgentHostExecutor.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/ChatProtocolExecutor.cs Outdated
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/RouteBuilder.cs
Comment threaddotnet/src/Microsoft.Agents.AI.Workflows/AIAgentsAbstractionsExtensions.cs Outdated
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking changeUsage: [PRs], Target: all PRs that introduce changes that are not backward compatible.NETUsage: [Issues, PRs], Target: .NetworkflowsUsage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@lokitoth@TaoChenOSU@alliscode