pub trait Agent: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn description(&self) -> &str;
fn sub_agents(&self) -> &[Arc<dyn Agent>];
fn run<'life0, 'async_trait>(
&'life0 self,
ctx: Arc<dyn InvocationContext>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Event, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
// Provided methods
fn interaction_mode(&self) -> AgentInteractionMode { ... }
fn supports_agent_transfer(&self) -> bool { ... }
fn capabilities(&self) -> AgentCapabilities { ... }
fn topology(&self) -> Option<AgentTopology> { ... }
fn configure_run(&self, _agent_name: &str, _config: &mut RunConfig) { ... }
fn transfer_targets_for(&self, _agent_name: &str) -> Option<Vec<String>> { ... }
fn strict_transfer_policy(&self) -> bool { ... }
fn govern_transfer<'life0, 'life1, 'async_trait>(
&'life0 self,
_request: &'life1 AgentTransferRequest,
) -> Pin<Box<dyn Future<Output = Result<AgentTransferDecision, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
}Expand description
The fundamental trait for all ADK agents.
Every agent — whether a simple LLM wrapper, a multi-step workflow, or a
composite orchestrator — implements this trait. The runtime invokes
run with an InvocationContext and consumes the returned
EventStream.
Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Returns a human-readable description of this agent’s purpose.
Sourcefn sub_agents(&self) -> &[Arc<dyn Agent>]
fn sub_agents(&self) -> &[Arc<dyn Agent>]
Returns the child agents managed by this agent.
Sourcefn run<'life0, 'async_trait>(
&'life0 self,
ctx: Arc<dyn InvocationContext>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Event, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
ctx: Arc<dyn InvocationContext>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Event, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Executes the agent and returns a stream of events.
Provided Methods§
Sourcefn interaction_mode(&self) -> AgentInteractionMode
fn interaction_mode(&self) -> AgentInteractionMode
Returns the agent’s primary interaction pattern.
Existing agents remain request/response by default. Realtime agents override this without introducing a new atomic agent kind or changing composition semantics.
Sourcefn supports_agent_transfer(&self) -> bool
fn supports_agent_transfer(&self) -> bool
Whether this agent participates in LLM-driven agent transfer and may be resumed directly across conversation turns.
When a session persists across turns, the runner inspects history to
decide which agent should handle the next user message. LLM-based and
custom agents return the default true, so the runner can hand a new
turn back to whichever agent responded last.
Deterministic workflow agents (sequential, parallel, loop, conditional)
override this to return false. Their sub-agents must not be resumed
individually: doing so would skip the workflow’s other sub-agents on
subsequent turns. Returning false makes the runner resume the workflow
root instead, so every sub-agent runs again on each turn.
Sourcefn capabilities(&self) -> AgentCapabilities
fn capabilities(&self) -> AgentCapabilities
Declares the execution-plane capabilities this agent supports.
The default remains compatible with existing custom agents: transfer,
shared-state, cancellation, and request metadata follow the established
Agent and InvocationContext contracts. Runtime tool injection and
exact-call relationship confirmation are opt-in because an implementation
must actively consume those facilities.
Sourcefn topology(&self) -> Option<AgentTopology>
fn topology(&self) -> Option<AgentTopology>
Returns portable composition metadata when this agent owns an explicit topology.
Leaf agents and legacy composites return None. The default keeps this
additive API backward compatible for existing Agent implementations.
Sourcefn configure_run(&self, _agent_name: &str, _config: &mut RunConfig)
fn configure_run(&self, _agent_name: &str, _config: &mut RunConfig)
Applies agent-composition policy to a run before the runtime creates the
invocation context for agent_name.
Composite agents can use this hook to inject invocation-scoped tools, constrain transfer targets, or tighten depth and concurrency limits. The default is a no-op, preserving the behavior of existing agents.
Sourcefn transfer_targets_for(&self, _agent_name: &str) -> Option<Vec<String>>
fn transfer_targets_for(&self, _agent_name: &str) -> Option<Vec<String>>
Returns the exact handoff targets allowed for agent_name, when this
agent owns an explicit transfer topology.
None asks the runtime to retain its legacy parent/peer discovery.
Some(vec![]) explicitly forbids handoff from the named agent.
Sourcefn strict_transfer_policy(&self) -> bool
fn strict_transfer_policy(&self) -> bool
Whether transfer-policy violations should fail the run.
Legacy agent trees return false, so missing targets and exceeded depth
retain their historical warn-and-stop behavior. Validated composites
return true to make topology violations observable errors.
Sourcefn govern_transfer<'life0, 'life1, 'async_trait>(
&'life0 self,
_request: &'life1 AgentTransferRequest,
) -> Pin<Box<dyn Future<Output = Result<AgentTransferDecision, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn govern_transfer<'life0, 'life1, 'async_trait>(
&'life0 self,
_request: &'life1 AgentTransferRequest,
) -> Pin<Box<dyn Future<Output = Result<AgentTransferDecision, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Applies asynchronous policy to an otherwise valid transfer.
Runner calls this after exact target validation and before control moves to the target. Ordinary agents allow transfers, preserving legacy behavior; validated composites can attach authorization, lifecycle hooks, audit logging, or other policy without teaching Runner their schema.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".