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 agentsTool/Toolset- For extending agents with capabilitiesSession/State- For managing conversation contextEvent- For streaming agent responsesAdkError/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