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 instruction_template;
69pub mod model;
70pub mod tool;
71pub mod types;
72
73pub use agent::{Agent, EventStream};
74pub use agent_loader::{AgentLoader, MultiAgentLoader, SingleAgentLoader};
75pub use callbacks::{
76 AfterAgentCallback, AfterModelCallback, AfterToolCallback, BeforeAgentCallback,
77 BeforeModelCallback, BeforeModelResult, BeforeToolCallback, GlobalInstructionProvider,
78 InstructionProvider,
79};
80pub use context::{
81 Artifacts, CallbackContext, IncludeContents, InvocationContext, Memory, MemoryEntry,
82 ReadonlyContext, ReadonlyState, RunConfig, Session, State, StreamingMode,
83};
84pub use error::{AdkError, Result};
85pub use event::{Event, EventActions, KEY_PREFIX_APP, KEY_PREFIX_TEMP, KEY_PREFIX_USER};
86pub use instruction_template::inject_session_state;
87pub use model::{
88 FinishReason, GenerateContentConfig, Llm, LlmRequest, LlmResponse, LlmResponseStream,
89 UsageMetadata,
90};
91pub use tool::{Tool, ToolContext, ToolPredicate, Toolset};
92pub use types::{Content, Part};