Register and share your invite link to earn from video plays and referrals.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture ๆŠ•็จฟใฏๅ€‹ไบบใฎๆ„่ฆ‹ใงใ™ใ€‚
Joined May 2026
279 Following    412 Followers
# Practical and Useful Patterns with ADK State manages your agent's "current situation." With dynamic prompts and scoped data management, build truly intelligent conversations ๐ŸŽฏ ๐Ÿ“Œ **Title**: State ๐Ÿ”— **URL**: ## ๐Ÿงฉ Overview State is the working memory accessible via `session.state`. It holds "data needed right now in this conversation" -- like shopping cart contents or information gathered step by step during a booking flow. State's key feature is **prefix-based scoping**: - `app:` - Data shared across the entire app (global settings for all users) - `user:` - Data shared per user (user preferences, persisted across sessions) - `temp:` - Temporary data valid only within the current session - No prefix - Standard session scope Additionally, embedding `{state_var}` in agent instructions enables dynamic prompts that adapt in real time. ## ๐Ÿ›  How to Use Set values on `session.state` using dictionary-style access -- for example, `session.state["booking_date"] = "2026-07-15"`, `session.state["party_size"] = 4`, and `session.state["seat_type"] = "window"` for standard session-scoped data. For scoped state, use the `user:` prefix (e.g., `"user:preferred_language"`) for per-user persistent data, `temp:` (e.g., `"temp:search_results"`) for data that disappears when the session ends, and `app:` (e.g., `"app:maintenance_mode"`) for data shared across all users. Additionally, embed placeholders like `{booking_date}`, `{party_size}`, and `{user:preferred_language}` in the `Agent`'s `instruction` parameter to dynamically inject state values into the agent's prompt at runtime. ## ๐Ÿ— Practical Usage **Restaurant booking flow:** Gather information progressively through conversation, accumulating in State: 1. "I'd like a reservation for 4 tomorrow evening" โ†’ Save `booking_date`, `party_size` to State 2. "Window seat please" โ†’ Add `seat_type` 3. "I'm allergic to nuts" โ†’ Add `allergies` 4. At final confirmation, pull all info from State to generate a confirmation message With `{booking_date}` embedded in instructions, the agent always responds with awareness of the latest booking status. **Persisting user preferences:** Using the `user:` prefix, carry forward information like "this person prefers English" or "this person is vegetarian" even when sessions change. ## ๐Ÿ’ก Use Cases - ๐Ÿ›’ E-commerce: Manage cart contents in State. `temp:` for search filters, `user:` for shipping address - โœˆ๏ธ Travel booking: Progressively accumulate dates, party size, seat type in State - ๐Ÿค– Personalization: Learn and persist user preferences via `user:` scope - ๐Ÿ“Š Dashboards: Share system-wide status via `app:` scope ## โš ๏ธ Caveats - Storing large amounts of data in State degrades performance. Consider Artifacts for bulky data - Changes to `app:` scope affect all users. Use with caution - When embedding `{state_var}` in instructions, unset values may display the placeholder as-is. Provide defaults - Establish key naming conventions to avoid collisions โœจ Leverage State's scoped management and dynamic prompts to build context-aware, intelligent agents. Perfect for booking flows and personalization! #ADK# #AIAgent#
Show more