State: The Session's Scratchpad (ADK)
Conceptually, session.state is a collection (dictionary or Map) holding key-value pairs.
Organizing State with Prefixes: Scope Matters
なし
user
app
temp
sub-agentsにはtempだけ?
Accessing Session State in Agent Instructions
{key}
To use a key that may or may not be present, you can include a question mark (?) after the key (e.g. {topic?}).
{を出したければ{{
How State is Updated: Recommended Methods
State should always be updated as part of adding an Event to the session history using session_service.append_event()
1. The Easy Way: output_key (for Agent Text Responses)
2. The Standard Way: EventActions.state_delta (for Complex Updates)
For more complex scenarios (updating multiple keys, non-string values, specific scopes like user: or app:, or updates not tied directly to the agent's final text), you manually construct the state_delta within EventActions.
3. Via CallbackContext or ToolContext (Recommended for Callbacks and Tools)
callback_context.state['my_key'] = my_value
tool_context.state['my_key'] = my_value
Best Practices for State Design Recap