Skip to main content

adk_plugin/
lib.rs

1//! # adk-plugin
2//!
3//! Plugin system for ADK-Rust agents.
4//!
5//! This crate provides a plugin architecture similar to adk-go's plugin package,
6//! allowing you to extend agent behavior through callbacks at various lifecycle points.
7//!
8//! ## Overview
9//!
10//! Plugins can hook into:
11//! - **Run lifecycle**: Before/after the entire agent run
12//! - **User messages**: Modify or inspect user input
13//! - **Events**: Modify or inspect agent events
14//! - **Agent callbacks**: Before/after agent execution
15//! - **Model callbacks**: Before/after LLM calls
16//! - **Tool callbacks**: Before/after tool execution
17//!
18//! ## Quick Start
19//!
20//! ### Using `PluginConfig` directly
21//!
22//! ```rust,ignore
23//! use adk_plugin::{Plugin, PluginConfig, PluginManager};
24//!
25//! // Create a logging plugin via PluginConfig
26//! let logging_plugin = Plugin::new(PluginConfig {
27//!     name: "logging".to_string(),
28//!     on_user_message: Some(Box::new(|ctx, content| {
29//!         Box::pin(async move {
30//!             println!("User said: {:?}", content);
31//!             Ok(None) // Don't modify
32//!         })
33//!     })),
34//!     on_event: Some(Box::new(|ctx, event| {
35//!         Box::pin(async move {
36//!             println!("Event: {:?}", event);
37//!             Ok(None) // Don't modify
38//!         })
39//!     })),
40//!     ..Default::default()
41//! });
42//! ```
43//!
44//! ### Using `PluginBuilder`
45//!
46//! ```rust,ignore
47//! use adk_plugin::{PluginBuilder, PluginManager};
48//!
49//! // Create the same plugin via the builder API
50//! let logging_plugin = PluginBuilder::new("logging")
51//!     .on_user_message(Box::new(|ctx, content| {
52//!         Box::pin(async move {
53//!             println!("User said: {:?}", content);
54//!             Ok(None)
55//!         })
56//!     }))
57//!     .on_event(Box::new(|ctx, event| {
58//!         Box::pin(async move {
59//!             println!("Event: {:?}", event);
60//!             Ok(None)
61//!         })
62//!     }))
63//!     .build();
64//!
65//! // Use with Runner
66//! let manager = PluginManager::new(vec![logging_plugin]);
67//! ```
68
69mod callbacks;
70mod manager;
71mod plugin;
72
73pub use callbacks::*;
74pub use manager::{PluginManager, PluginManagerConfig};
75pub use plugin::{Plugin, PluginBuilder, PluginConfig};