adk_agent/lib.rs
1//! # adk-agent
2#![allow(clippy::result_large_err)]
3//!
4//! Agent implementations for ADK (LLM, Custom, Workflow agents).
5//!
6//! ## Overview
7//!
8//! This crate provides ready-to-use agent implementations:
9//!
10//! - [`LlmAgent`] - Core agent powered by LLM reasoning
11//! - [`CustomAgent`] - Define custom logic without LLM
12//! - [`SequentialAgent`] - Execute agents in sequence
13//! - [`ParallelAgent`] - Execute agents concurrently, with optional [`SharedState`](adk_core::SharedState) coordination
14//! - [`LoopAgent`] - Iterate until exit condition
15//! - [`ConditionalAgent`] - Branch based on conditions
16//!
17//! ## What's New in 0.6.0
18//!
19//! - **`ParallelAgent::with_shared_state()`**: Opt-in builder method that creates a fresh
20//! [`SharedState`](adk_core::SharedState) per `run()` invocation, enabling sub-agents to
21//! exchange data via `set_shared`/`get_shared`/`wait_for_key` through the context chain.
22//! - **`AgentToolContext` delegation**: Tools executed by `LlmAgent` now have access to
23//! `shared_state()` via the context chain, enabling tool-level coordination in parallel workflows.
24//! - **Tool confirmation**: `LlmAgentBuilder::require_tool_confirmation()` and
25//! `require_tool_confirmation_for_all()` for human-in-the-loop tool authorization.
26//!
27//! ## Quick Start
28//!
29//! ```rust,no_run
30//! use adk_agent::LlmAgentBuilder;
31//! use std::sync::Arc;
32//!
33//! // LLM Agent requires a model (from adk-model)
34//! // let agent = LlmAgentBuilder::new("assistant")
35//! // .description("Helpful AI assistant")
36//! // .model(Arc::new(model))
37//! // .build()?;
38//! ```
39//!
40//! ## Workflow Agents
41//!
42//! Combine agents for complex workflows:
43//!
44//! ```rust,ignore
45//! // Sequential: A -> B -> C
46//! let seq = SequentialAgent::new("pipeline", vec![a, b, c]);
47//!
48//! // Parallel: A, B, C simultaneously
49//! let par = ParallelAgent::new("team", vec![a, b, c]);
50//!
51//! // Loop: repeat until exit
52//! let loop_agent = LoopAgent::new("iterator", vec![worker]).with_max_iterations(10);
53//! ```
54//!
55//! ## Guardrails (optional)
56//!
57//! Enable the `guardrails` feature for input/output validation:
58//!
59//! ```rust,ignore
60//! use adk_agent::{LlmAgentBuilder, guardrails::{GuardrailSet, ContentFilter, PiiRedactor}};
61//!
62//! let input_guardrails = GuardrailSet::new()
63//! .with(ContentFilter::harmful_content())
64//! .with(PiiRedactor::new());
65//!
66//! let agent = LlmAgentBuilder::new("assistant")
67//! .input_guardrails(input_guardrails)
68//! .build()?;
69//! ```
70
71pub mod compaction;
72mod custom_agent;
73pub mod guardrails;
74mod llm_agent;
75pub mod tool_call_markup;
76mod workflow;
77
78pub use adk_core::AfterToolCallbackFull;
79pub use adk_core::Agent;
80pub use adk_core::OnToolErrorCallback;
81pub use compaction::LlmEventSummarizer;
82pub use custom_agent::{CustomAgent, CustomAgentBuilder};
83pub use guardrails::GuardrailSet;
84pub use llm_agent::{DEFAULT_MAX_ITERATIONS, DEFAULT_TOOL_TIMEOUT, LlmAgent, LlmAgentBuilder};
85pub use tool_call_markup::{normalize_content, normalize_option_content};
86pub use workflow::{
87 ConditionalAgent, DEFAULT_LOOP_MAX_ITERATIONS, LlmConditionalAgent, LlmConditionalAgentBuilder,
88 LoopAgent, ParallelAgent, SequentialAgent,
89};