Skip to main content

adk_core/
lib.rs

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