adk-plugin
Plugin system for ADK-Rust agents.
Overview
adk-plugin provides a plugin architecture for extending ADK agent behavior through callbacks at various lifecycle points.
Features
- Run lifecycle hooks: Before/after the entire agent run
- User message processing: Modify or inspect user input
- Event processing: Modify or inspect agent events
- Agent callbacks: Before/after agent execution
- Model callbacks: Before/after LLM calls, error handling
- Tool callbacks: Before/after tool execution, error handling
Installation
[]
= "0.3.1"
Quick Start
use ;
// Create a logging plugin using the builder
let logging_plugin = new
.on_user_message
.on_event
.build;
// Create a caching plugin
let cache_plugin = new;
// Create plugin manager
let manager = new;
// Use with Runner
Callback Types
Run Lifecycle
| Callback | Description |
|---|---|
on_user_message |
Called when user message received, can modify |
on_event |
Called for each event, can modify |
before_run |
Called before run starts, can skip run |
after_run |
Called after run completes (cleanup) |
Agent Callbacks
| Callback | Description |
|---|---|
before_agent |
Called before agent execution |
after_agent |
Called after agent execution |
Model Callbacks
| Callback | Description |
|---|---|
before_model |
Called before LLM call, can modify request or skip |
after_model |
Called after LLM call, can modify response |
on_model_error |
Called on LLM error, can provide fallback |
Tool Callbacks
| Callback | Description |
|---|---|
before_tool |
Called before tool execution |
after_tool |
Called after tool execution |
on_tool_error |
Called on tool error, can provide fallback |
Example: Caching Plugin
use ;
use HashMap;
use Arc;
use RwLock;
// Simple in-memory cache
let cache = new;
let cache_read = cache.clone;
let cache_write = cache.clone;
let caching_plugin = new;
Example: Metrics Plugin
use ;
use ;
use Arc;
let run_count = new;
let run_count_start = run_count.clone;
let run_count_end = run_count.clone;
let = collect_metrics;
let metrics_plugin = new;
Related Crates
- adk-rust - Meta-crate with all components
- adk-core - Core traits and types
- adk-agent - Agent implementations
- adk-runner - Agent execution runtime
License
Apache-2.0
Part of ADK-Rust
This crate is part of the ADK-Rust framework for building AI agents in Rust.