adk-docs icon indicating copy to clipboard operation
adk-docs copied to clipboard

docs: Add nested state access documentation for template injection

Open Jainish-S opened this issue 1 week ago • 0 comments

Related PR: https://github.com/google/adk-python/pull/3673 Related issue: https://github.com/google/adk-python/issues/575

Summary

Documents the new nested state access feature for instruction templates, allowing developers to use dot notation and optional chaining to access nested properties.

What's New

Dot notation: Access nested values with {user.profile.role} Optional chaining: Safely handle missing values with {user?.profile?.role?}

Example

def inject_nested_state(callback_context: CallbackContext):
    callback_context.state["user"] = {
        "name": "Alice",
        "profile": {"role": "Software Engineer"}
    }

async def build_instruction(readonly_context: ReadonlyContext) -> str:
    template = "User {user.name} has role {user.profile.role}"
    return await instructions_utils.inject_session_state(template, readonly_context)

Changes

  • Added "Accessing Nested State with Dot Notation" section to docs/sessions/state.md
  • Documented syntax, behavior, and error handling
  • Provided Python code examples
  • Updated "Important Considerations" section

Jainish-S avatar Nov 22 '25 12:11 Jainish-S