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

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.
PluginBuilder
Builder for creating plugins with a fluent API.
PluginConfig
Configuration for creating a Plugin.
PluginManager
Manages a collection of plugins and coordinates callback execution.
PluginManagerConfig
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§

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 error occurs.
OnUserMessageCallback
Callback invoked when a user message is received.