adk_agent/lib.rs
1//! # adk-agent
2//!
3//! Agent implementations for ADK (LLM, Custom, Workflow agents).
4//!
5//! ## Overview
6//!
7//! This crate provides ready-to-use agent implementations:
8//!
9//! - [`LlmAgent`] - Core agent powered by LLM reasoning
10//! - [`CustomAgent`] - Define custom logic without LLM
11//! - [`SequentialAgent`] - Execute agents in sequence
12//! - [`ParallelAgent`] - Execute agents concurrently, with optional [`SharedState`](adk_core::SharedState) coordination
13//! - [`LoopAgent`] - Iterate until a sub-agent escalates or the iteration limit is reached
14//! - [`ConditionalAgent`] - Branch based on conditions
15//! - [`LlmConditionalAgent`] - Route to a sub-agent by a model classification
16//! - [`DecisionAgent`] - Route to a sub-agent by a typed decision with a rationale and a
17//! confidence, made with structured output
18//! - [`TeamSpec`] - Validate and compile a portable team from existing agents
19//!
20//! `CodeActAgent` (feature `codeact`), `CodingAgent` (feature `coding`), and `AmbientAgent`
21//! (feature `ambient`) are feature-gated.
22//!
23//! ## Quick Start
24//!
25//! ```rust,no_run
26//! use std::sync::Arc;
27//!
28//! use adk_agent::LlmAgentBuilder;
29//! use adk_model::GeminiModel;
30//!
31//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
32//! let api_key = std::env::var("GOOGLE_API_KEY")?;
33//! let model = Arc::new(GeminiModel::new(&api_key, "gemini-3.8-flash")?);
34//!
35//! let agent = LlmAgentBuilder::new("assistant")
36//! .description("Helpful AI assistant")
37//! .instruction("Be helpful and concise.")
38//! .model(model)
39//! .build()?;
40//! # let _ = agent;
41//! # Ok(())
42//! # }
43//! ```
44//!
45//! ## Workflow Agents
46//!
47//! Combine agents for complex workflows:
48//!
49//! ```rust
50//! use std::sync::Arc;
51//!
52//! use adk_agent::{LoopAgent, ParallelAgent, SequentialAgent};
53//! use adk_core::Agent;
54//!
55//! fn workflows(a: Arc<dyn Agent>, b: Arc<dyn Agent>, c: Arc<dyn Agent>) {
56//! // Sequential: A -> B -> C
57//! let _seq = SequentialAgent::new("pipeline", vec![a.clone(), b.clone(), c.clone()]);
58//!
59//! // Parallel: A, B, C simultaneously
60//! let _par = ParallelAgent::new("team", vec![a, b, c.clone()]);
61//!
62//! // Loop: repeat until a sub-agent escalates
63//! let _loop_agent = LoopAgent::new("iterator", vec![c]).with_max_iterations(10);
64//! }
65//! ```
66//!
67//! ## Guardrails (optional)
68//!
69//! Enable the `guardrails` feature for input, output, and tool guardrails:
70//!
71//! ```rust,ignore
72//! use adk_agent::{LlmAgentBuilder, guardrails::{ContentFilter, GuardrailSet, PiiRedactor}};
73//!
74//! let input_guardrails = GuardrailSet::new()
75//! .with(ContentFilter::harmful_content())
76//! .with(PiiRedactor::new());
77//!
78//! let agent = LlmAgentBuilder::new("assistant")
79//! .model(model)
80//! .input_guardrails(input_guardrails)
81//! .build()?;
82//! ```
83//!
84//! ## Features
85//!
86//! No feature is on by default.
87//!
88//! | Feature | Enables |
89//! |---------|---------|
90//! | `skills` | `with_skills`, `with_auto_skills` and the other skill methods on every agent builder |
91//! | `skills-progressive-disclosure` | `adk-skill`'s progressive-disclosure skill tools; implies `skills` |
92//! | `guardrails` | `input_guardrails`, `output_guardrails` and `tool_guardrails` through `adk-guardrail` |
93//! | `enhanced-plugins` | `enhanced_plugin` and `enhanced_plugins`: the `EnhancedPlugin` pipeline intercepting tool and model calls |
94//! | `team-tools` | `Delegate` relationships in a [`TeamSpec`], lowered to `AgentTool`s |
95//! | `codeact` | `CodeActAgent` |
96//! | `coding` | `CodingAgent` over `adk-devtools` |
97//! | `sandbox` | `LlmAgentBuilder::sandbox_config` through `adk-sandbox` |
98//! | `ambient` | `AmbientAgent` with `CronTrigger`, `WebhookTrigger` and `FileWatchTrigger` |
99//! | `record-payloads` | Trace payloads recorded in full, instead of truncated to `RunConfig::trace_payload_max_bytes`, when `RunConfig::record_payloads` is set |
100#![allow(clippy::result_large_err)]
101#![deny(missing_docs)]
102
103mod acting_agent_context;
104#[cfg(feature = "ambient")]
105pub mod ambient;
106
107#[cfg(feature = "coding")]
108pub mod coding;
109
110#[cfg(feature = "codeact")]
111pub mod codeact;
112
113pub mod compaction;
114mod custom_agent;
115mod grounding;
116pub mod guardrails;
117mod invocation_hooks;
118mod llm_agent;
119mod requested_call;
120mod skill_shim;
121pub mod subagents;
122pub mod team;
123pub mod tool_call_markup;
124mod tool_ledger;
125mod workflow;
126
127pub use adk_core::AfterToolCallbackFull;
128pub use adk_core::Agent;
129pub use adk_core::OnToolErrorCallback;
130pub use compaction::LlmEventSummarizer;
131pub use custom_agent::{CustomAgent, CustomAgentBuilder};
132pub use guardrails::GuardrailSet;
133pub use llm_agent::{
134 DEFAULT_MAX_ITERATIONS, DEFAULT_TOOL_TIMEOUT, LlmAgent, LlmAgentBuilder, extract_typed,
135};
136pub use team::{
137 BlackboardHistoryPolicy, BlackboardPolicy, BlackboardSchedule, BlackboardSpec,
138 BlackboardTransition, CircuitBreakerPolicy, CompiledBlackboardTeam, CompiledTeam,
139 PERCEIVER_CAPABILITY, REASONER_CAPABILITY, RelationshipApprovalPolicy,
140 RelationshipFailureStrategy, RelationshipKind, RelationshipPolicy, ResolvedTeamMember,
141 StaticTeamAgentRegistry, TEAM_EDGE_ID_KEY, TEAM_EXECUTION_STATE_KEY, TEAM_ROOT_INVOCATION_KEY,
142 TeamAgentDescriptor, TeamAgentHealth, TeamAgentRegistry, TeamArchitectureTemplate, TeamBudget,
143 TeamContextPolicy, TeamEdgeExecution, TeamError, TeamExecutionAnalysis, TeamExecutionSnapshot,
144 TeamExecutionStatus, TeamExecutionUsage, TeamFailurePolicy, TeamHistoryPolicy,
145 TeamLifecycleContext, TeamLifecycleDecision, TeamLifecycleHook, TeamLifecycleOutcome,
146 TeamLifecyclePhase, TeamManagerBranch, TeamMemberSpec, TeamPolicy, TeamRegistryRequirement,
147 TeamRelationship, TeamReplayError, TeamResumePlan, TeamResumePolicy, TeamRuntimeError,
148 TeamSpec, TeamStateMergePolicy, TeamTerminationPolicy, VERIFIER_CAPABILITY,
149 WorkflowArchitectureTemplate, analyze_team_execution, opinion_schema, perceiver_input_schema,
150 reasoner_input_schema, validate_team_replay, verifier_input_schema,
151};
152pub use tool_call_markup::{normalize_content, normalize_option_content};
153pub use tool_ledger::held_call_ledger_key;
154pub use workflow::{
155 ConditionalAgent, DEFAULT_LOOP_MAX_ITERATIONS, DecisionAgent, DecisionAgentBuilder,
156 LlmConditionalAgent, LlmConditionalAgentBuilder, LoopAgent, ParallelAgent, SequentialAgent,
157};
158
159#[cfg(feature = "ambient")]
160pub use ambient::{
161 AmbientAgent, AmbientAgentStatus, CronTrigger, EventSource, FileWatchTrigger, TriggerEvent,
162 WebhookTrigger,
163};