-
Notifications
You must be signed in to change notification settings - Fork 1k
.NET: [BREAKING] feat: Improve Agent hosting inside Workflows #3142
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
base: main
Are you sure you want to change the base?
Conversation
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 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
* 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)
15a25dd to
c93cb93
Compare
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