inject_session_state

Function inject_session_state 

Source
pub async fn inject_session_state(
    ctx: &dyn InvocationContext,
    template: &str,
) -> Result<String, AdkError>
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 Injects session state and artifact values into an instruction template

Supports the following placeholder syntax:

  • {var_name} - Required session state variable (errors if missing)
  • {var_name?} - Optional variable (empty string if missing)
  • {artifact.file_name} - Artifact content insertion
  • {app:var}, {user:var}, {temp:var} - Prefixed state variables

§Examples

let template = "Hello {user_name}, your score is {score}";
let result = inject_session_state(ctx, template).await?;
// Result: "Hello Alice, your score is 100"

§Errors

Returns an error if:

  • A required variable is not found in session state
  • A required artifact cannot be loaded
  • The artifact service is not initialized