adk_core/lib.rs
1//! # adk-core
2//!
3//! Core traits and types for ADK agents, tools, sessions, and events.
4#![allow(clippy::result_large_err)]
5//!
6//! ## Overview
7//!
8//! This crate provides the foundational abstractions for the Agent Development Kit:
9//!
10//! - [`Agent`] - The fundamental trait for all agents
11//! - [`Tool`] / [`Toolset`] - For extending agents with custom capabilities
12//! - [`Session`] / [`State`] - For managing conversation context
13//! - [`Event`] - For streaming agent responses
14//! - [`AdkError`] / [`Result`] - Unified error handling
15//!
16//! ## Quick Start
17//!
18//! ```rust,no_run
19//! use adk_core::{Agent, Tool, Event, Result};
20//! use std::sync::Arc;
21//!
22//! // All agents implement the Agent trait
23//! // All tools implement the Tool trait
24//! // Events are streamed as the agent executes
25//! ```
26//!
27//! ## Core Traits
28//!
29//! ### Agent
30//!
31//! The [`Agent`] trait defines the interface for all agents:
32//!
33//! ```rust,ignore
34//! #[async_trait]
35//! pub trait Agent: Send + Sync {
36//! fn name(&self) -> &str;
37//! fn description(&self) -> Option<&str>;
38//! async fn run(&self, ctx: Arc<dyn InvocationContext>) -> Result<EventStream>;
39//! }
40//! ```
41//!
42//! ### Tool
43//!
44//! The [`Tool`] trait defines custom capabilities:
45//!
46//! ```rust,ignore
47//! #[async_trait]
48//! pub trait Tool: Send + Sync {
49//! fn name(&self) -> &str;
50//! fn description(&self) -> &str;
51//! async fn execute(&self, ctx: Arc<dyn ToolContext>, args: Value) -> Result<Value>;
52//! }
53//! ```
54//!
55//! ## State Management
56//!
57//! State uses typed prefixes for organization:
58//!
59//! - `user:` - User preferences (persists across sessions)
60//! - `app:` - Application state (application-wide)
61//! - `temp:` - Temporary data (cleared each turn)
62
63pub mod agent;
64pub mod agent_loader;
65pub mod callbacks;
66pub mod context;
67pub mod error;
68pub mod event;
69pub mod identity;
70pub mod instruction_template;
71pub mod model;
72pub mod request_context;
73pub mod tool;
74pub mod types;
75
76pub use agent::{Agent, EventStream, ResolvedContext};
77pub use agent_loader::{AgentLoader, MultiAgentLoader, SingleAgentLoader};
78pub use callbacks::{
79 AfterAgentCallback, AfterModelCallback, AfterToolCallback, AfterToolCallbackFull,
80 BaseEventsSummarizer, BeforeAgentCallback, BeforeModelCallback, BeforeModelResult,
81 BeforeToolCallback, EventsCompactionConfig, GlobalInstructionProvider, InstructionProvider,
82 OnToolErrorCallback,
83};
84pub use context::{
85 Artifacts, CallbackContext, IncludeContents, InvocationContext, MAX_STATE_KEY_LEN, Memory,
86 MemoryEntry, ReadonlyContext, ReadonlyState, RunConfig, Session, State, StreamingMode,
87 ToolConfirmationDecision, ToolConfirmationPolicy, ToolConfirmationRequest, ToolOutcome,
88 validate_state_key,
89};
90pub use error::{AdkError, ErrorCategory, ErrorComponent, ErrorDetails, Result, RetryHint};
91pub use event::{
92 Event, EventActions, EventCompaction, KEY_PREFIX_APP, KEY_PREFIX_TEMP, KEY_PREFIX_USER,
93};
94pub use identity::{
95 AdkIdentity, AppName, ExecutionIdentity, IdentityError, InvocationId, SessionId, UserId,
96};
97pub use instruction_template::inject_session_state;
98pub use model::{
99 CacheCapable, CitationMetadata, CitationSource, ContextCacheConfig, FinishReason,
100 GenerateContentConfig, Llm, LlmRequest, LlmResponse, LlmResponseStream, UsageMetadata,
101};
102pub use request_context::RequestContext;
103pub use tool::{
104 RetryBudget, Tool, ToolContext, ToolPredicate, ToolRegistry, Toolset, ValidationMode,
105};
106pub use types::{Content, FunctionResponseData, MAX_INLINE_DATA_SIZE, Part};
107
108// Re-export async_trait so the #[tool] macro's generated code can reference it
109// via adk_tool::async_trait (adk_tool re-exports from adk_core).
110pub use async_trait::async_trait;