Support MCP Elicitation, Sampling, and Roots via new McpSessionHost - #6833
Conversation
…host communication This change introduces a new communication pattern between workbenches and host agents: - Adds WorkbenchHost protocol for handling workbench requests - Implements base classes for workbench requests and responses - Updates AssistantAgent to implement WorkbenchHost interface - Adds host binding capability to Workbench base class 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Introduces McpAssistantAgent combining AssistantAgent with MCP hosting capabilities - Adds McpWorkbenchHost for handling sampling, elicitation, and roots listing - Implements MCP-specific request/response types for workbench communication - Refactors McpSessionActor to use workbench host pattern - Adds support for different elicitor types (functions, agents, custom elicitors) Note: Tests need to be updated to reflect the new MCP workbench host architecture 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Victor Dibia (@victordibia) Eric Zhu (@ekzhu) Let me know what you think of this approach. I think this is more extensible than my one-off change to support sampling. Any new features that MCP (or other tools) may add that require host communication would be centralized in this new WorkbenchHost type. (I asked Claude to write my commit messages, let me know if you have any questions) |
|
This looks good to me. Do you think it make sense that we just add MCP features into the |
- Replace WorkbenchHost with McpSessionHost pattern: This isolates the changes (mostly) to just the mcp extension
- See python/packages/autogen-ext/src/autogen_ext/tools/mcp/host/README.md for details.
- Add GroupChatAgentElicitor and ChatCompletionClientElicitor
- Restructure host module into separate directory
- Update tests and examples to use new session host pattern
- Support direct rpc communication with ChatAgent via runtime
This enables a caller to invoke an rpc on an agent in the runtime and await the agent's response directly
- Revert "Add WorkbenchHost protocol and request/response system for workbench-host communication"
This reverts commit ea3e584
Neede type annotations
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6833 +/- ##
==========================================
+ Coverage 81.06% 81.22% +0.16%
==========================================
Files 239 244 +5
Lines 18333 18512 +179
==========================================
+ Hits 14861 15036 +175
- Misses 3472 3476 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I like that we separate the host from the agent class. Can you help me understand why it needs to modify the group chat and update the runtime? |
|
Eric Zhu (@ekzhu) Sorry for the late reply! Because elicitation happens during other MCP calls (esp. tool calls in our case here), it happens out-of-order with respect to the agent's message handler. I wanted to take advantage of the Runtime's existing connections to fulfill the elicitation request asynchronously. I recognize that this touches very core code is therefore potentially not great. Ideally we'd use the Handoff mechanism. But that would require the agent noticing that it's turn is being interrupted mid tool call, store that state, handoff, wait for its next turn, then finish its request. So in my mind, hijacking the runtime is more elegant than having to force an agent to manage that much state. I could be convinced otherwise. |
|
Looking forward to this addition |
|
Eric Zhu (@ekzhu) Revisiting this update. Is it still desirable to integrate this? I saw you referenced it in the agent-framework. I could update this to provide cleaner public getters for GroupChat properties that I'm "illegally" accessing in the current version. |
Let's get this in. I think as long as it is adding to the behavior rather than affecting existing usage should be fine. |
Rather than allowing elicitor to arbitrarily target any agent in a GroupChat (and thus having to modify the autogen-agentchat chat container implementation), just use a more abstract stream (e.g. stdio) based elicitor that is outside of the group chat itself Also update roots and sampling to follow the Elicitor component class pattern for consistency and serialization
|
Eric Zhu (@ekzhu) I simplified the implementation, now it is isolated to the MCP Workbench (and new McpSessionHost). Doesn't mess with the GroupChat logic anymore. To recap: MCP Servers sometimes need to make (non-tool call) requests to the Host. Currently, the allowed requests are ListRoots, Elicitation, and Sampling. Our McpWorkbench already handles connection to the MCP Server and tool calling. This PR introduces a McpSessionHost which delegates MCP Server elicitation, sampling, and roots requests to optional handlers. The handlers are abstract and extensible Components: Elicitor, Sampler, RootsProvider. I also provide concrete subclasses: StreamElicitor, StdioElicitor, ChatCompletionClientSampler, and StaticRootsProvider. |
|
We could try and get autogen added to: https://modelcontextprotocol.io/clients as well. The row would look pretty good:
Not many clients have sampling, roots, and elicitation supported. |
Good idea! |
|
This is a long waited feature! I am sure it will propel autogen as the go to framework for MCP workflows. Good job guys! Moreover, adding tool annotations to workbench list_tools() would make it even better - #6929 |
Why are these changes needed?
With the introduction of sampling and elicitation to MCP, "workbenches" need the ability to initiate communication with the host agent/user/system.
This is an initial attempt at introducing an extensible WorkbenchHost protocol that implementers can extend the functionality of agents' workbenches without altering the agent themselves. See the
McpAssistantAgentin autogen-ext for an example and implementation of MCP Sampling, Roots, and Elicitation.Related issue number
N/A
Checks
I need to remove old tests and add new ones. I expect checks to fail at the moment.