Skip to main content

Crate adk_plugin

Crate adk_plugin 

Source
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

§Using PluginConfig directly

use adk_plugin::{Plugin, PluginConfig, PluginManager};

// Create a logging plugin via PluginConfig
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()
});

§Using PluginBuilder

use adk_plugin::{PluginBuilder, PluginManager};

// Create the same plugin via the builder API
let logging_plugin = PluginBuilder::new("logging")
    .on_user_message(Box::new(|ctx, content| {
        Box::pin(async move {
            println!("User said: {:?}", content);
            Ok(None)
        })
    }))
    .on_event(Box::new(|ctx, event| {
        Box::pin(async move {
            println!("Event: {:?}", event);
            Ok(None)
        })
    }))
    .build();

// Use with Runner
let manager = PluginManager::new(vec![logging_plugin]);

Re-exports§

pub use adapted_plugin::AdaptedPlugin;

Modules§

adapted_plugin
Adapter wrapping a legacy closure-based Plugin as an EnhancedPlugin.

Structs§

EnhancedPluginManager
Manages enhanced plugins with priority-based pipeline execution.
Plugin
A Plugin bundles related callbacks for extending agent behavior.
PluginBuilder
Builder for creating plugins with a fluent API.
PluginConfig
Configuration for creating a Plugin.
PluginContext
A type-safe, concurrent key-value store for plugin shared state.
PluginManager
Manages a collection of plugins and coordinates callback execution.
PluginManagerConfig
Configuration for the PluginManager.

Enums§

AfterModelCallResult
Result from an after_model_call hook invocation.
AfterToolCallResult
Result from an after_tool_call hook invocation.
BeforeModelCallResult
Result from a before_model_call hook invocation.
BeforeToolCallResult
Result from a before_tool_call hook invocation.

Traits§

EnhancedPlugin
Enhanced plugin trait with fine-grained hooks and default no-op implementations.

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§

AfterRunCallback
Callback invoked after the agent run completes.
BeforeRunCallback
Callback invoked before the agent run starts.
OnEventCallback
Callback invoked for each event generated by the agent.
OnModelErrorCallback
Callback invoked when a model error occurs.
OnToolErrorCallback
Callback invoked when a tool execution fails (after retries are exhausted).
OnUserMessageCallback
Callback invoked when a user message is received.