Skip to main content

adk_agent/
lib.rs

1//! # adk-agent
2#![allow(clippy::result_large_err)]
3#![deny(missing_docs)]
4//!
5//! Agent implementations for ADK (LLM, Custom, Workflow agents).
6//!
7//! ## Overview
8//!
9//! This crate provides ready-to-use agent implementations:
10//!
11//! - [`LlmAgent`] - Core agent powered by LLM reasoning
12//! - [`CustomAgent`] - Define custom logic without LLM
13//! - [`SequentialAgent`] - Execute agents in sequence
14//! - [`ParallelAgent`] - Execute agents concurrently, with optional [`SharedState`](adk_core::SharedState) coordination
15//! - [`LoopAgent`] - Iterate until exit condition
16//! - [`ConditionalAgent`] - Branch based on conditions
17//! - [`TeamSpec`] - Validate and compile a portable team from existing agents
18//!
19//! ## What's New in 0.6.0
20//!
21//! - **`ParallelAgent::with_shared_state()`**: Opt-in builder method that creates a fresh
22//!   [`SharedState`](adk_core::SharedState) per `run()` invocation, enabling sub-agents to
23//!   exchange data via `set_shared`/`get_shared`/`wait_for_key` through the context chain.
24//! - **`AgentToolContext` delegation**: Tools executed by `LlmAgent` now have access to
25//!   `shared_state()` via the context chain, enabling tool-level coordination in parallel workflows.
26//! - **Tool confirmation**: `LlmAgentBuilder::require_tool_confirmation()` and
27//!   `require_tool_confirmation_for_all()` for human-in-the-loop tool authorization.
28//!
29//! ## Quick Start
30//!
31//! ```rust,no_run
32//! use adk_agent::LlmAgentBuilder;
33//! use std::sync::Arc;
34//!
35//! // LLM Agent requires a model (from adk-model)
36//! // let agent = LlmAgentBuilder::new("assistant")
37//! //     .description("Helpful AI assistant")
38//! //     .model(Arc::new(model))
39//! //     .build()?;
40//! ```
41//!
42//! ## Workflow Agents
43//!
44//! Combine agents for complex workflows:
45//!
46//! ```rust,ignore
47//! // Sequential: A -> B -> C
48//! let seq = SequentialAgent::new("pipeline", vec![a, b, c]);
49//!
50//! // Parallel: A, B, C simultaneously
51//! let par = ParallelAgent::new("team", vec![a, b, c]);
52//!
53//! // Loop: repeat until exit
54//! let loop_agent = LoopAgent::new("iterator", vec![worker]).with_max_iterations(10);
55//! ```
56//!
57//! ## Guardrails (optional)
58//!
59//! Enable the `guardrails` feature for input/output validation:
60//!
61//! ```rust,ignore
62//! use adk_agent::{LlmAgentBuilder, guardrails::{GuardrailSet, ContentFilter, PiiRedactor}};
63//!
64//! let input_guardrails = GuardrailSet::new()
65//!     .with(ContentFilter::harmful_content())
66//!     .with(PiiRedactor::new());
67//!
68//! let agent = LlmAgentBuilder::new("assistant")
69//!     .input_guardrails(input_guardrails)
70//!     .build()?;
71//! ```
72
73#[cfg(feature = "ambient")]
74pub mod ambient;
75
76#[cfg(feature = "coding")]
77pub mod coding;
78
79#[cfg(feature = "codeact")]
80pub mod codeact;
81
82pub mod compaction;
83mod custom_agent;
84pub mod guardrails;
85mod llm_agent;
86mod skill_shim;
87pub mod team;
88pub mod tool_call_markup;
89mod workflow;
90
91pub use adk_core::AfterToolCallbackFull;
92pub use adk_core::Agent;
93pub use adk_core::OnToolErrorCallback;
94pub use compaction::LlmEventSummarizer;
95pub use custom_agent::{CustomAgent, CustomAgentBuilder};
96pub use guardrails::GuardrailSet;
97pub use llm_agent::{
98    DEFAULT_MAX_ITERATIONS, DEFAULT_TOOL_TIMEOUT, LlmAgent, LlmAgentBuilder, extract_typed,
99};
100pub use team::{
101    BlackboardHistoryPolicy, BlackboardPolicy, BlackboardSchedule, BlackboardSpec,
102    BlackboardTransition, CircuitBreakerPolicy, CompiledBlackboardTeam, CompiledTeam,
103    RelationshipApprovalPolicy, RelationshipFailureStrategy, RelationshipKind, RelationshipPolicy,
104    ResolvedTeamMember, StaticTeamAgentRegistry, TEAM_EDGE_ID_KEY, TEAM_EXECUTION_STATE_KEY,
105    TEAM_ROOT_INVOCATION_KEY, TeamAgentDescriptor, TeamAgentHealth, TeamAgentRegistry,
106    TeamArchitectureTemplate, TeamBudget, TeamContextPolicy, TeamEdgeExecution, TeamError,
107    TeamExecutionAnalysis, TeamExecutionSnapshot, TeamExecutionStatus, TeamExecutionUsage,
108    TeamFailurePolicy, TeamHistoryPolicy, TeamLifecycleContext, TeamLifecycleDecision,
109    TeamLifecycleHook, TeamLifecycleOutcome, TeamLifecyclePhase, TeamManagerBranch, TeamMemberSpec,
110    TeamPolicy, TeamRegistryRequirement, TeamRelationship, TeamReplayError, TeamResumePlan,
111    TeamResumePolicy, TeamRuntimeError, TeamSpec, TeamStateMergePolicy, TeamTerminationPolicy,
112    WorkflowArchitectureTemplate, analyze_team_execution, validate_team_replay,
113};
114pub use tool_call_markup::{normalize_content, normalize_option_content};
115pub use workflow::{
116    ConditionalAgent, DEFAULT_LOOP_MAX_ITERATIONS, LlmConditionalAgent, LlmConditionalAgentBuilder,
117    LoopAgent, ParallelAgent, SequentialAgent,
118};
119
120#[cfg(feature = "ambient")]
121pub use ambient::{
122    AmbientAgent, AmbientAgentStatus, CronTrigger, EventSource, FileWatchTrigger, TriggerEvent,
123    WebhookTrigger,
124};