How Do Agents Access State Variables? Understanding State Value Retrieval in LLM Agents #2489
Replies: 2 comments 3 replies
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: The Hello! I can provide some information on how agents access state variables in ADK. There are two primary ways to interact with the session state:
In your example, You can also have an agent automatically save its output to the session state by using the I hope this helps clarify how state variables are accessed in ADK! [1] https://google.github.io/adk-docs/agents/custom-agents/ |
|
@shenshiqiSSQ To recap: the LLM never reads session state directly. {{variable}} in an instruction injects the value before the prompt is sent while state['key'] only works from tool/callback/custom-agent code. The deep_research sample's wording just describes where the value comes from, it actually reaches the LLM through conversation history in the SequentialAgent pipeline. Closing this out since it looks addressed, feel free to reopen or comment if anything's still unclear. |
Uh oh!
There was an error while loading. Please reload this page.
I have a question: In the instruction for an agent like this:
instruction="Read state['current_code'] (if exists) and state['requirements']. Generate/refine Python code to meet requirements. Save to state['current_code']."
I'm unsure whether the agent actually knows the contents of state or if it retrieves information from the context. I know that using {{}} (e.g., {{current_code}}) in the instruction will trigger state value substitution, but does the agent automatically fetch values when the format is state['current_code'] or just 'current_code'?
All reactions