Skip to content

Temp prefixed state key not available on after_agent_callback #3047

@LucasBarzotto

Description

@LucasBarzotto

Describe the bug
The documentation states that state variables prefixed with temp: should be available during the entire invocation process:

temp: Prefix (Temporary Invocation State):

Scope: Specific to the current invocation (the entire process from an agent receiving user input to generating the final output for that input).

However, if the agent output_key is set with a temp: prefixed key, this key is not present anymore in the state during after_agent_callback

To Reproduce
The following code works as expected

from google.adk.agents import LlmAgent
 from google.adk.agents.callback_context import CallbackContext
 from google.genai import types
 
 
 def _callback_test(callback_context: CallbackContext) -> types.Content | None:
     print(callback_context.state["test_output"])
     return None
 
 
 root_agent = LlmAgent(
     name="test_agent",
     model="gemini-2.5-flash",
     instruction="You are a helpful assistant that can generate a 10 words random text.",
     output_key="test_output",
     after_agent_callback=_callback_test,
 )

But the following code fails, because it can't find the key in the after_agent_callback execution

from google.adk.agents import LlmAgent
 from google.adk.agents.callback_context import CallbackContext
 from google.genai import types
 
 
 def _callback_test(callback_context: CallbackContext) -> types.Content | None:
     print(callback_context.state["temp:test_output"])
     return None
 
 
 root_agent = LlmAgent(
     name="test_agent",
     model="gemini-2.5-flash",
     instruction="You are a helpful assistant that can generate a 10 words random text.",
     output_key="temp:test_output",
     after_agent_callback=_callback_test,
 )

Expected behavior
Temp keys should remain available during the entire invocation process

Desktop (please complete the following information):

  • OS: windows, mac
  • Python version: 3.13
  • ADK version: 1.15.1

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-2.5-flash

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementationhelp wanted[Community] Extra attention is neededneeds review[Status] The PR/issue is awaiting review from the maintainer

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions