Concept 4Session state & the 4 state layers
03a–03d · Art #3a–#3d

Instead of playing "telephone" through chat history, ADK agents read and write to session.state using 4 prefix scopes:

1

Unprefixed state['destination']: scoped to the current session_id only.**

2

user: state['user:vehicle_fuel_type']: scoped to user_id, persists across all future sessions of that user!

3

app: state['app:system_banner']: global across all users of the app.

4

temp: state['temp:scratchpad']: ephemeral, wiped automatically at the end of the current turn!

** Unless you want to persist the Session State to an external Session Storage (Firestore, PostgreSQL etc.)

Variable Injection in Instructions ({user:key?})
await session_service.create_session(
app_name=app_name,
user_id="user_zelda",
session_id="zelda_session_1",
state={
**global_app_config,
"user:user_preferred_language": "Italian",
}
)
cameriere_agent = LlmAgent(
name="cameriere",
model="gemini-2.5-flash",
# ADK dynamically injects session.state keys
instruction="""You are the SostaApp Maître D'.
Active Traveler Profile from Blackboard:
- User ID: {user:user_preferred_language}
""",
)