adk-core
Core traits and types for ADK-Rust agents, tools, sessions, and events.
Overview
adk-core provides the foundational abstractions for ADK-Rust. It defines the core traits and types that all other ADK crates build upon:
- Agent trait - The fundamental abstraction for all agents
- Tool / Toolset traits - For extending agents with custom capabilities
- Llm trait - For LLM provider integrations
- SchemaAdapter trait - Provider-aware JSON Schema normalization for MCP tools
- Context hierarchy - ReadonlyContext → CallbackContext → ToolContext/InvocationContext
- Content / Part - Message content structures
- Event system - For streaming agent responses
- Session / State - For managing conversation context
- Error types - Unified error handling
This crate is model-agnostic and contains no LLM-specific code.
Installation
[]
= "2.0.0"
Or use the meta-crate:
[]
= "2.0.0"
Core Traits
Agent
Tool
ToolExecutionStrategy::Auto includes a call in its concurrent subset only when the selected tool returns true from both is_read_only() and is_concurrency_safe(). It runs that safe subset first, then executes the remaining calls sequentially. Both methods default to false, so existing implementations remain sequential.
Toolset
Llm
SchemaAdapter
Provider-specific schema normalization for MCP tools. Each Llm implementation returns its adapter via schema_adapter(). See GenericSchemaAdapter for the default implementation.
Key Types
Content & Part
// Message content with role and parts
let content = new
.with_text
.with_inline_data
.with_file_uri;
// Part variants
Multimodal Function Responses
Tools can return images, audio, or file references alongside JSON:
// Tool returns JSON with inline_data — framework extracts automatically
Ok
// Direct construction
let frd = with_inline_data;
// File references (URIs to external files)
let frd = with_file_data;
Event
// Events stream from agent execution
let event = new;
event.content // Access response content
event.actions // State changes, transfers, escalation
// Provider-specific metadata (replaces GCP-specific fields)
event.provider_metadata // HashMap<String, String>
First-class tool events
Events expose typed, render-ready views of tool activity, so UIs consume tool
calls and results generically without matching Part internals:
for call in event.tool_calls
for result in event.tool_results
Because a tool's result is an ordinary event, the output of any tool —
streaming or one-shot — is renderable. Use call_id to correlate a call with
its result (and progress chunks).
Streaming tool progress
A tool can push intermediate output while still running via
ToolContext::emit_progress("stdout", chunk). The framework forwards each chunk
as a partial event on the same EventStream; detect them with:
if let Some = event.tool_progress_stream
The default emit_progress is a no-op, so non-streaming tools are unaffected.
EventActions
EventCompaction
When context compaction is enabled, older events are summarized into a single compacted event:
High-Stakes Tooling & Context Engineering
For production agents, adk-core provides types to ensure that an agent's instructions (the cognitive frame) always match its tool capabilities (the physical frame).
ResolvedContext
An "atomic unit" containing the final system instruction and the collection of verified, binary Arc<dyn Tool> instances. This prevents "Phantom Tool" hallucinations.
ToolRegistry
A foundational trait for mapping string-based tool names (from config or skills) to concrete executable tool instances.
ValidationMode
Defines how the framework handles cases where a requested tool is missing:
- Strict: Rejects the match/operation if any tool is missing.
- Permissive: Binds available tools, omits missing ones, and logs a warning.
Context Hierarchy
ReadonlyContext (read-only access)
├── invocation_id, agent_name, user_id, app_name, session_id
└── user_content()
CallbackContext (extends ReadonlyContext)
└── artifacts()
ToolContext (extends CallbackContext)
├── function_call_id()
├── actions() / set_actions()
└── search_memory()
InvocationContext (extends CallbackContext)
├── agent(), memory(), session()
├── run_config()
└── end_invocation() / ended()
Security
Inline Data Size Limit
Content::with_inline_data() and Part::inline_data() enforce a 10 MB limit (MAX_INLINE_DATA_SIZE) to prevent oversized payloads.
State Key Validation
validate_state_key() rejects keys that are empty, exceed 256 bytes (MAX_STATE_KEY_LEN), contain path separators (/, \, ..), or null bytes.
use validate_state_key;
assert!;
assert!;
Provider Metadata
The Event struct uses a generic provider_metadata: HashMap<String, String> field for provider-specific data (e.g., GCP Vertex, Azure OpenAI), keeping the core type provider-agnostic.
State Management
State uses typed prefixes for organization:
| Prefix | Scope | Persistence |
|---|---|---|
user: |
User preferences | Across sessions |
app: |
Application state | Application-wide |
temp: |
Temporary data | Cleared each turn |
// Access state via session
let value = session.state.get;
session.state.set;
State keys are validated with validate_state_key() — max length is MAX_STATE_KEY_LEN (256 bytes), and keys must be valid UTF-8 with no control characters.
Callbacks
// Callback type aliases
pub type BeforeAgentCallback = .. + Send + Sync>;
pub type AfterAgentCallback = .. + Send + Sync>;
pub type BeforeModelCallback = .. + Send + Sync>;
pub type AfterModelCallback = .. + Send + Sync>;
pub type BeforeToolCallback = .. + Send + Sync>;
pub type AfterToolCallback = .. + Send + Sync>;
// Instruction providers
pub type InstructionProvider = .. + Send + Sync>;
pub type GlobalInstructionProvider = .. + Send + Sync>;
Context Compaction
Types for sliding-window context compaction (summarizing older events to reduce LLM context size):
/// Trait for summarizing events during compaction.
/// Configuration for automatic context compaction.
Streaming Modes
ToolExecutionStrategy
Controls how multiple tool calls from a single LLM response are dispatched:
Set per-agent via LlmAgentBuilder::tool_execution_strategy(). Parallel is an explicit override that does not inspect tool metadata.
Related Crates
- adk-rust - Meta-crate with all components
- adk-agent - Agent implementations
- adk-model - LLM integrations
- adk-tool - Tool implementations
License
Apache-2.0
Part of ADK-Rust
This crate is part of the ADK-Rust framework for building AI agents in Rust.