pub trait SamplingHandler: Send + Sync {
// Required method
fn handle_create_message<'life0, 'async_trait>(
&'life0 self,
request: SamplingRequest,
) -> Pin<Box<dyn Future<Output = Result<SamplingResponse, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
}Available on crate features
mcp-sampling and tools only.Expand description
Trait for handling MCP sampling/createMessage requests.
Implementors receive the MCP sampling request and return a response.
The default implementation (provided by LlmSamplingHandler in task 8.2)
routes through the agent’s LLM provider.
§Example
ⓘ
use adk_tool::sampling::{SamplingHandler, SamplingRequest, SamplingResponse};
use adk_core::Result;
struct MyHandler;
#[async_trait::async_trait]
impl SamplingHandler for MyHandler {
async fn handle_create_message(
&self,
request: SamplingRequest,
) -> Result<SamplingResponse> {
// Custom sampling logic
todo!()
}
}Required Methods§
Sourcefn handle_create_message<'life0, 'async_trait>(
&'life0 self,
request: SamplingRequest,
) -> Pin<Box<dyn Future<Output = Result<SamplingResponse, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn handle_create_message<'life0, 'async_trait>(
&'life0 self,
request: SamplingRequest,
) -> Pin<Box<dyn Future<Output = Result<SamplingResponse, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Handle a sampling/createMessage request from an MCP server.
Receives the sampling parameters and returns the generated message.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".