You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Output key doesn't work with temp state scope #4564
Describe the Bug:
I am running a Sequential Agent. I want to save the output of first agent as output_key with temporary scope (valid for that invocation). However, when I use the following code - output_key='temp:output_key'
I get no value in state. I checked that that its probably due to _trim_temp_delta_state function in BaseSessionService.
Steps to Reproduce:
Create a sequential agent with subagents having output keys
prefix output key with temp
Expected Behavior:
For a SequentialAgent, the lifecycle of invocation starts from the first agent till the last agent. Therefore the 'temp' prefixed state should be available across the agents. But right now its available only for the start of an (sub)agent till that agent produces response.
Observed Behavior:
temp prefixed state not transferred across agents
Environment Details:
ADK Library Version: 1.24.1
Desktop OS:** MacOS
Python Version (python -V): 3.12
Model Information:
Are you using LiteLLM: Yes
Which model is being used: Claude 4.5
Minimal Reproduction Code:
Please provide a code snippet or a link to a Gist/repo that isolates the issue.
Thank you for sharing your observation; it appears to be correct. We tried to reproduce the issue and observed that if a temp prefix is used, the output_key cannot be utilized in the subsequent subagent and we get error. Additionally, we found that if the temp state is updated while creating the session, that state is removed and cannot be used.
Hello @seanzhougoogle , could you please have a look at this and share your inputs?
Sharing sample code and observation below for your reference.
Code: google-adk==1.25.1
from google.adk.agents import Agent,SequentialAgent,LlmAgent
from google.adk.models.lite_llm import LiteLlm
from google.adk.sessions import InMemorySessionService
from google.adk.runners import Runner
import os
import asyncio
from dotenv import load_dotenv
from google.adk.models.google_llm import Gemini
from google.genai import types
from google.adk.tools.agent_tool import AgentTool
from google.adk.agents.invocation_context import InvocationContext
load_dotenv(override=True)
def create_code_pipeline_agent():
GEMINI_MODEL = "gemini-2.5-flash"
# --- 1. Define Sub-Agents for Each Pipeline Stage ---
# Code Writer Agent
# Takes the initial specification (from user query) and writes code.
code_writer_agent = Agent(
name="CodeWriterAgent",
model=GEMINI_MODEL,
instruction="""
You are a Python Code Generator.
Based *only* on the user's request, write Python code that fulfills the requirement.
Output *only* the complete Python code block, enclosed in triple backticks (```python ... ```).
Do not add any other text before or after the code block.
""",
description="Writes initial Python code based on a specification.",
output_key="generated_code"
)
# Code Reviewer Agent
# Takes the code generated by the previous agent (read from state) and provides feedback.
code_reviewer_agent = Agent(
name="CodeReviewerAgent",
model=GEMINI_MODEL,
instruction="""
You are an expert Python Code Reviewer.
Your task is to provide constructive feedback on the provided code.
**Code to Review:**
```python
{generated_code}
```
**Review Criteria:**
1. **Correctness:** Does the code work as intended? Are there logic errors?
2. **Readability:** Is the code clear and easy to understand? Follows PEP 8 style guidelines?
3. **Efficiency:** Is the code reasonably efficient? Any obvious performance bottlenecks?
4. **Edge Cases:** Does the code handle potential edge cases or invalid inputs gracefully?
5. **Best Practices:** Does the code follow common Python best practices?
**Output:**
Provide your feedback as a concise, bulleted list. Focus on the most important points for improvement.
If the code is excellent and requires no changes, simply state: "No major issues found."
Output *only* the review comments or the "No major issues" statement.
""",
description="Reviews code and provides feedback.",
output_key="review_comments"
)
# Code Refactorer Agent
# Takes the original code and the review comments (read from state) and refactors the code.
code_refactorer_agent = Agent(
name="CodeRefactorerAgent",
model=GEMINI_MODEL,
instruction="""
You are a Python Code Refactoring AI.
Your goal is to improve the given Python code based on the provided review comments.
**Original Code:**
```python
{generated_code}
```
**Review Comments:**
{review_comments}
**Task:**
Carefully apply the suggestions from the review comments to refactor the original code.
If the review comments state "No major issues found," return the original code unchanged.
Ensure the final code is complete, functional, and includes necessary imports and docstrings.
**Output:**
Output *only* the final, refactored Python code block, enclosed in triple backticks (```python ... ```).
Do not add any other text before or after the code block.
""",
description="Refactors code based on review comments.",
output_key="temp:refactored_code"
)
# --- 2. Create the SequentialAgent ---
# This agent orchestrates the pipeline by running the sub_agents in order.
code_pipeline_agent = SequentialAgent(
name="CodePipelineAgent",
sub_agents=[(code_writer_agent), code_reviewer_agent, code_refactorer_agent],
# tools=[AgentTool(code_writer_agent), AgentTool(code_reviewer_agent), AgentTool(code_refactorer_agent)],
description="Executes a sequence of code writing, reviewing, and refactoring.",
)
return code_pipeline_agent
async def main(query: str):
APP_NAME = "CodePipelineApp"
USER_ID = "Llalit"
SESSION_ID = "session_123"
session_service = InMemorySessionService()
session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID,state={"temp:hindi_comments":"With every code line write a comment in Hindi explaining what the code does.","help":"Help user as much as possible"})
runner = Runner(agent=create_code_pipeline_agent(), app_name=APP_NAME, session_service=session_service)
inputs = types.Content(role="user",parts=[types.Part(text=query)])
print("current state: ",session.state,"\n\n\n\n")
async for events in runner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=inputs):
updated_session = await session_service.get_session(
app_name=APP_NAME,
user_id=USER_ID,
session_id=SESSION_ID)
print("\n===== SESSION STATE =====")
print(updated_session.state)
if events.is_final_response:
print(events.content.parts[0].text)
print("=========================================\n\n\n\n",events.content.parts[0].text)
if __name__ == "__main__":
user_query = "Write a Python function that takes a list of numbers and returns the list sorted in ascending order."
asyncio.run(main(user_query))
Observations:
current state: {'help': 'Help user as much as possible'}
===== SESSION STATE =====
{'help': 'Help user as much as possible', 'generated_code': '```python\ndef sort_numbers_ascending(numbers):\n """\n Sorts a list of numbers in ascending order.\n\n Args:\n numbers: A list of numbers (integers or floats).\n\n Returns:\n A new list containing the numbers from the input list, sorted in\n ascending order.\n """\n return sorted(numbers)\n```'}
```python
def sort_numbers_ascending(numbers):
"""
Sorts a list of numbers in ascending order.
Args:
numbers: A list of numbers (integers or floats).
Returns:
A new list containing the numbers from the input list, sorted in
ascending order.
"""
return sorted(numbers)
===== SESSION STATE =====
{'help': 'Help user as much as possible', 'generated_code': 'python\ndef sort_numbers_ascending(numbers):\n """\n Sorts a list of numbers in ascending order.\n\n Args:\n numbers: A list of numbers (integers or floats).\n\n Returns:\n A new list containing the numbers from the input list, sorted in\n ascending order.\n """\n return sorted(numbers)\n', 'review_comments': '- No major issues found.'}
No major issues found.
===== SESSION STATE =====
{'help': 'Help user as much as possible', 'generated_code': 'python\ndef sort_numbers_ascending(numbers):\n """\n Sorts a list of numbers in ascending order.\n\n Args:\n numbers: A list of numbers (integers or floats).\n\n Returns:\n A new list containing the numbers from the input list, sorted in\n ascending order.\n """\n return sorted(numbers)\n', 'review_comments': '- No major issues found.'}
defsort_numbers_ascending(numbers):
""" Sorts a list of numbers in ascending order. Args: numbers: A list of numbers (integers or floats). Returns: A new list containing the numbers from the input list, sorted in ascending order. """returnsorted(numbers)
=========================================
defsort_numbers_ascending(numbers):
""" Sorts a list of numbers in ascending order. Args: numbers: A list of numbers (integers or floats). Returns: A new list containing the numbers from the input list, sorted in ascending order. """returnsorted(numbers)
Key observations to note here:
1. `"temp:hindi_comments"` is missing, event though it was included with `temp` prefix while creating session.
2. Updated session state does not include `"temp:refactored_code"`
3. Additionally if we use `"temp:generated_code"`, we get error while calling `code_reviewer_agent` as it required `output_key="generated_code"` from `code_writer_agent`.
Activity
llalitkumarrr commentedon Feb 23, 2026
Hello @maheshwaritanay ,
Thank you for sharing your observation; it appears to be correct. We tried to reproduce the issue and observed that if a
tempprefix is used, theoutput_keycannot be utilized in the subsequent subagent and we get error. Additionally, we found that if thetempstate is updated while creating the session, that state is removed and cannot be used.Hello @seanzhougoogle , could you please have a look at this and share your inputs?
Sharing sample code and observation below for your reference.
Code:
google-adk==1.25.1Observations:
===== SESSION STATE =====
{'help': 'Help user as much as possible', 'generated_code': '
python\ndef sort_numbers_ascending(numbers):\n """\n Sorts a list of numbers in ascending order.\n\n Args:\n numbers: A list of numbers (integers or floats).\n\n Returns:\n A new list containing the numbers from the input list, sorted in\n ascending order.\n """\n return sorted(numbers)\n', 'review_comments': '- No major issues found.'}===== SESSION STATE =====
{'help': 'Help user as much as possible', 'generated_code': '
python\ndef sort_numbers_ascending(numbers):\n """\n Sorts a list of numbers in ascending order.\n\n Args:\n numbers: A list of numbers (integers or floats).\n\n Returns:\n A new list containing the numbers from the input list, sorted in\n ascending order.\n """\n return sorted(numbers)\n', 'review_comments': '- No major issues found.'}=========================================
fix: temp-scoped state now visible to subsequent agents in same invoc…
rohityan commentedon Feb 25, 2026
Hi @sasha-gitg , PTAL
fix: temp-scoped state now visible to subsequent agents in same invoc…
fix: temp-scoped state now visible to subsequent agents in same invoc…
fix: temp-scoped state now visible to subsequent agents in same invoc…