Expand description
§adk-plugin
Plugin system for ADK-Rust agents.
This crate provides a plugin architecture similar to adk-go’s plugin package, allowing you to extend agent behavior through callbacks at various lifecycle points.
§Overview
Plugins can hook into:
- Run lifecycle: Before/after the entire agent run
- User messages: Modify or inspect user input
- Events: Modify or inspect agent events
- Agent callbacks: Before/after agent execution
- Model callbacks: Before/after LLM calls
- Tool callbacks: Before/after tool execution
§Quick Start
ⓘ
use adk_plugin::{Plugin, PluginConfig, PluginManager};
// Create a logging plugin
let logging_plugin = Plugin::new(PluginConfig {
name: "logging".to_string(),
on_user_message: Some(Box::new(|ctx, content| {
Box::pin(async move {
println!("User said: {:?}", content);
Ok(None) // Don't modify
})
})),
on_event: Some(Box::new(|ctx, event| {
Box::pin(async move {
println!("Event: {:?}", event);
Ok(None) // Don't modify
})
})),
..Default::default()
});
// Create plugin manager
let manager = PluginManager::new(vec![logging_plugin]);
// Use with Runner
let runner = Runner::new(RunnerConfig {
plugin_manager: Some(manager),
..config
});Structs§
- Plugin
- A Plugin bundles related callbacks for extending agent behavior.
- Plugin
Builder - Builder for creating plugins with a fluent API.
- Plugin
Config - Configuration for creating a Plugin.
- Plugin
Manager - Manages a collection of plugins and coordinates callback execution.
- Plugin
Manager Config - Configuration for the PluginManager.
Functions§
- collect_
metrics - Helper to create a metrics collection callback.
- log_
events - Helper to create a simple logging callback for events.
- log_
user_ messages - Helper to create a simple logging callback for user messages.
Type Aliases§
- After
RunCallback - Callback invoked after the agent run completes.
- Before
RunCallback - Callback invoked before the agent run starts.
- OnEvent
Callback - Callback invoked for each event generated by the agent.
- OnModel
Error Callback - Callback invoked when a model error occurs.
- OnTool
Error Callback - Callback invoked when a tool error occurs.
- OnUser
Message Callback - Callback invoked when a user message is received.