Skip to main content

IdentitySource

Trait IdentitySource 

Source
pub trait IdentitySource:
    Debug
    + Send
    + Sync {
    // Required method
    fn current<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<AgentPrincipal, AdkError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn principal_for<'life0, 'life1, 'async_trait>(
        &'life0 self,
        agent_name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<AgentPrincipal>, AdkError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn credential<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<AgentCredential, AdkError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Core traits and types.

Always available regardless of feature flags. Includes:

  • Agent - The fundamental trait for all agents
  • Tool / Toolset - For extending agents with capabilities
  • Session / State - For managing conversation context
  • Event - For streaming agent responses
  • AdkError / Result - Unified error handling Says who the running agents are, and proves it.

The runner reads the source at the start of every run, so a source backed by a rotating workload identity (SPIFFE Workload API, a cloud metadata server) is read fresh each time. The root agent acts as principal_for its name, falling back to current; every other agent in the tree acts as principal_for its name, falling back to AgentPrincipal::derived. A principal’s AgentId must stay the same across redeploys; the deployment belongs in AgentPrincipal::instance.

§Example

use adk_core::{AgentId, AgentPrincipal, IdentitySource, StaticIdentitySource};

let source = StaticIdentitySource::new(
    AgentPrincipal::new(AgentId::new("urn:adk:agent:billing")?).with_tenant("acme"),
);
assert_eq!(source.current().await?.id.as_str(), "urn:adk:agent:billing");
assert!(source.credential().await.is_err());

Required Methods§

Source

fn current<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<AgentPrincipal, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

The principal the workload runs as; the root agent’s unless principal_for maps it.

Provided Methods§

Source

fn principal_for<'life0, 'life1, 'async_trait>( &'life0 self, agent_name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<AgentPrincipal>, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

The principal of the agent named agent_name, when the source maps it.

The default maps no agent, so only the root agent acts as current.

Source

fn credential<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<AgentCredential, AdkError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

A credential proving the principal’s identity.

§Errors

The default returns identity.credential.unavailable.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§