-
Notifications
You must be signed in to change notification settings - Fork 5.6k
refactor: subagents as platform extension (enables subagents in code mode) #6160
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
Changes from 8 commits
c6356c5
23ab12d
a6a2886
23d9847
d5c1af7
501ffa6
7617ac5
cc4ecd3
bc2adc9
b08a336
eef0d0f
4fe73d3
73423df
cac9773
9bba173
9f5d3ee
ead2b0f
95d8782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| use anyhow::Result; | ||
| use axum::http::{HeaderMap, HeaderName}; | ||
| use chrono::{DateTime, Utc}; | ||
| use futures::future; | ||
| use futures::stream::{FuturesUnordered, StreamExt}; | ||
| use futures::{future, FutureExt}; | ||
| use rmcp::service::{ClientInitializeError, ServiceError}; | ||
| use rmcp::transport::streamable_http_client::{ | ||
| AuthRequiredError, StreamableHttpClientTransportConfig, StreamableHttpError, | ||
|
|
@@ -262,6 +262,7 @@ impl ExtensionManager { | |
| session_id: None, | ||
| extension_manager: None, | ||
| tool_route_manager: None, | ||
| sub_recipes: None, | ||
| }), | ||
| provider, | ||
| } | ||
|
|
@@ -280,6 +281,10 @@ impl ExtensionManager { | |
| self.context.lock().await.clone() | ||
| } | ||
|
|
||
| pub async fn get_provider(&self) -> Option<Arc<dyn crate::providers::base::Provider>> { | ||
| self.provider.lock().await.clone() | ||
| } | ||
|
|
||
| pub async fn supports_resources(&self) -> bool { | ||
| self.extensions | ||
| .lock() | ||
|
|
@@ -1080,26 +1085,24 @@ impl ExtensionManager { | |
| } | ||
|
|
||
| let arguments = tool_call.arguments.clone(); | ||
| let client = client.clone(); | ||
| let notifications_receiver = client.lock().await.subscribe().await; | ||
|
|
||
| let fut = async move { | ||
| let client_guard = client.lock().await; | ||
| client_guard | ||
| .call_tool(&tool_name, arguments, cancellation_token) | ||
| .await | ||
| .map_err(|e| match e { | ||
| ServiceError::McpError(error_data) => error_data, | ||
| _ => { | ||
| ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), e.maybe_to_value()) | ||
| } | ||
| }) | ||
| }; | ||
| let mut result = client | ||
| .lock() | ||
| .await | ||
| .call_tool_deferred(&tool_name, arguments, cancellation_token) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of a new function, how about changing this so that McpClientTrait::call_tool always returns a notification stream, with the default impl calling .subscribe()? I'm also seeing that all of the platform extensions just return a dummy channel for subscribe, but ToolCallResult has an Option for the notifcations stream, so it would make more sense to have the trait fn itself return an Option
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a good idea, but I don't necessarily want to do it in this PR. |
||
| .await | ||
| .map_err(|e| match e { | ||
| ServiceError::McpError(error_data) => error_data, | ||
| _ => ErrorData::new(ErrorCode::INTERNAL_ERROR, e.to_string(), e.maybe_to_value()), | ||
| })?; | ||
|
|
||
| Ok(ToolCallResult { | ||
| result: Box::new(fut.boxed()), | ||
| notification_stream: Some(Box::new(ReceiverStream::new(notifications_receiver))), | ||
| }) | ||
| if result.notification_stream.is_none() { | ||
| result.notification_stream = | ||
| Some(Box::new(ReceiverStream::new(notifications_receiver))); | ||
| } | ||
|
|
||
| Ok(result) | ||
| } | ||
|
|
||
| pub async fn list_prompts_from_extension( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.