Expand description
Adapter wrapping a legacy closure-based Plugin as an EnhancedPlugin.
The AdaptedPlugin struct bridges the existing closure-based plugin system
to the new trait-based EnhancedPlugin interface, enabling legacy plugins
to participate in the enhanced pipeline without modification.
§Overview
Legacy plugins use callbacks that receive only a CallbackContext for tool hooks,
and (CallbackContext, LlmRequest) / (CallbackContext, LlmResponse) for model hooks.
They cannot modify tool arguments or results directly. The adapter:
- Delegates
name()to the innerPlugin::name() - Uses a configurable priority (default 100)
- Invokes legacy
before_tool/after_toolcallbacks for side effects, but always returnsContinuewith unchanged args/result - Maps legacy
BeforeModelResulttoBeforeModelCallResult - Maps legacy
AfterModelCallbackresults toAfterModelCallResult - Delegates
close()to the innerPlugin::close()
§Example
ⓘ
use adk_plugin::{AdaptedPlugin, Plugin, PluginConfig};
let legacy_plugin = Plugin::new(PluginConfig {
name: "my-legacy-plugin".to_string(),
before_tool: Some(Box::new(|ctx| {
Box::pin(async move {
tracing::info!("tool starting");
Ok(None)
})
})),
..Default::default()
});
// Wrap with default priority (100)
let adapted = AdaptedPlugin::new(legacy_plugin, 100);Structs§
- Adapted
Plugin - Wraps a legacy closure-based
Pluginas anEnhancedPlugin.