Skip to content

AttributeError in create_empty_state prevents adding current session to eval sets in ADK UI for Workflow-based agents #5995

Closed

Description

@vannicktrinquier

Describe the Bug:
Seems that when running a Workflow-based agent, via the ADK 2.X development server, attempting to add a session to an evaluation set causes the server to crash with an AttributeError. This feature is important for end-users to create eval test case quickly from the UI and built confidence on their agent behavior.

Looks like the crash occurs because the state initialization utility (create_empty_state) assumes the root agent is a standard BaseAgent and attempts to traverse its child agents by accessing the .sub_agents attribute.
However, Workflow instances do not have a sub_agents attribute; their child agents (nodes) are stored under .graph.nodes.

Steps to Reproduce:

  1. Define a root agent as an ADK Workflow:
from google.adk import Workflow
xxxx = Workflow(
    name="xxxx",
    edges=[("START", orchestrator_node)],
)
  1. Start the ADK web server:
uv run adk web .. --port 8081
  1. Go to the UI, create a new evaluation test
Image
  1. Add current session to eval set
Image
  1. Error is returned
Image
  1. From the adk console we can set the error is coming from those:
INFO:     127.0.0.1:50564 - "POST /dev/apps/xxxxx/eval_sets/eval_set_1/add_session HTTP/1.1" 500 Internal Server Error
...

See below for rest of logs.

Expected Behavior:
The empty state for the workflow agent is created successfully without any errors, allowing the session to be added to the evaluation set. And the current session can be added as eval case

Observed Behavior:
The server fails with a 500 Internal Server Error due to an unhandled AttributeError exception in _create_empty_state.

Environment Details:

  • ADK Library Version (pip show google-adk): 2.1.0
  • Desktop OS: macOS
  • Python Version (python -V): Python 3.13.3

Model Information:

  • Which model is being used: gemini-3.5-flash

Regression:
N/A (As Workflows are a new feature structure in ADK 2.x). But eval set were working as expected in ADK 1.X

Logs:

INFO:     127.0.0.1:50564 - "POST /dev/apps/xxxxx/eval_sets/eval_set_1/add_session HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "xxxxx/.venv/lib/python3.13/site-packages/uvicorn/protocols/http/h11_impl.py", line 415, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self.scope, self.receive, self.send
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
...
...
...

  File "xxxxx/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 328, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "xxxxx/.venv/lib/python3.13/site-packages/google/adk/cli/dev_server.py", line 863, in add_session_to_eval_set
    initial_session_state = create_empty_state(root_agent)
  File "xxxxx/.venv/lib/python3.13/site-packages/google/adk/cli/utils/state.py", line 54, in create_empty_state
    _create_empty_state(agent, non_initialized_states)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "xxxxx/.venv/lib/python3.13/site-packages/google/adk/cli/utils/state.py", line 26, in _create_empty_state
    for sub_agent in agent.sub_agents:
                     ^^^^^^^^^^^^^^^^
  File "xxxxx/.venv/lib/python3.13/site-packages/pydantic/main.py", line 1042, in __getattr__
    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'Workflow' object has no attribute 'sub_agents'

Screenshots / Video:
See above

How often has this issue occurred?:

  • Always (100%)

Activity

  1. added
    web[Component] This issue will be transferred to adk-web
    on Jun 6, 2026
  2. added theissue type on Jun 6, 2026
  3. adk-bot commented on Jun 6, 2026

    @adk-bot
    Collaborator

    GitHub Issue #5995 Analysis: AttributeError in create_empty_state prevents adding current session to eval sets in ADK UI for Workflow-based agents

    Executive Summary

    1. What is broken? When running a Workflow-based agent via the ADK development server, attempting to add a session to an evaluation set causes a crash with AttributeError: 'Workflow' object has no attribute 'sub_agents' in _create_empty_state. This occurs because create_empty_state assumes the root agent is a standard BaseAgent and directly accesses the sub_agents attribute, whereas Workflow objects inherit from BaseNode and organize their sub-agents/nodes in .graph.nodes.
    2. Is there a linked PR that fixes this issue? None.
    3. Recommendation: Should Fix (High Priority). This bug completely prevents developers from adding active workflow sessions to evaluation sets in the ADK UI, breaking an essential workflow and core feedback loop for ADK 2.x Workflow-based development. The fix is high-impact with very low complexity and risk.
    Detailed Analysis

    1. Root Cause Analysis ("What is broken?")

    When a user clicks "Add current session to eval set" in the ADK UI, the dev server handles the POST request via the endpoint add_session_to_eval_set in src/google/adk/cli/dev_server.py:L848-L880.

    To determine the initial state structure of the agentic application, it loads the root agent and calls:

    initial_session_state = create_empty_state(root_agent)

    In src/google/adk/cli/utils/state.py:L25-L36:

    def _create_empty_state(agent: BaseAgent, all_state: dict[str, Any]):
      for sub_agent in agent.sub_agents:
        _create_empty_state(sub_agent, all_state)
    
      if (
          isinstance(agent, LlmAgent)
          and agent.instruction
          and isinstance(agent.instruction, str)
      ):
        for key in re.findall(r'{([\w]+)}', agent.instruction):
          all_state[key] = ''

    If the agent is a graph-based Workflow, it is an instance of BaseNode rather than a standard BaseAgent and does not define a .sub_agents attribute. Accessing agent.sub_agents on line 26 yields:

    AttributeError: 'Workflow' object has no attribute 'sub_agents'
    

    2. Existing Pull Requests ("Is there a linked PR that fixes this issue?")

    • Linked PR: None
    • PR URL: N/A
    • Analysis: No open or closed pull requests exist referencing this issue.

    3. Recommendation

    • Recommendation: Should Fix (High Priority)
    • Rationale:
      • Impact: It blocks standard developer workflows (specifically evaluation setup and benchmarking) for graph-based Workflows, which are a cornerstone feature of ADK 2.x.
      • Proposed Fix: The recursive search in _create_empty_state should be updated to safely traverse both standard hierarchical sub-agents (sub_agents) and workflow graph nodes (graph.nodes) using dynamic attribute fetching (getattr), avoiding circular imports and handling generic BaseNode hierarchies cleanly:
        def _create_empty_state(node: BaseNode, all_state: dict[str, Any]):
          for sub_agent in getattr(node, 'sub_agents', []) or []:
            _create_empty_state(sub_agent, all_state)
        
          graph = getattr(node, 'graph', None)
          if graph is not None:
            for sub_node in getattr(graph, 'nodes', []) or []:
              _create_empty_state(sub_node, all_state)
        
          if (
              isinstance(node, LlmAgent)
              and node.instruction
              and isinstance(node.instruction, str)
          ):
            for key in re.findall(r'{([\w]+)}', node.instruction):
              all_state[key] = ''
      • Risk: Extremely low. Calling getattr operates seamlessly for standard components and fixes the traversal crash for Workflow models.

    Summary of work completed:

  4. sanketpatil06 commented on Jun 9, 2026

    @sanketpatil06

    Hi @vannicktrinquier , Thanks for reporting this issue. We were able to reproduce it on our end.
    We see that PR (#6001) has already been raised to address this issue and is currently under review. Would you mind checking it and letting us know if it resolves the issue for you?

  5. added
    request clarification[Status] The maintainer need clarification or more information from the author
    on Jun 11, 2026
  6. vannicktrinquier commented on Jun 16, 2026

    @vannicktrinquier
    Author

    Hi @sanketpatil06,
    I have tested from my side by cloning the PR branch of #6001 and updated my current project to use the fixed code.
    And I confirm, working from my side. I am able to save an evaluation as expected and content of file is relevant.
    Thanks

  7. removed
    request clarification[Status] The maintainer need clarification or more information from the author
    on Jun 16, 2026
  8. added
    needs review[Status] The PR/issue is awaiting review from the maintainer
    on Jun 22, 2026
  9. self-assigned this
    on Jul 29, 2026
  10. added a commit that references this issue on Aug 7, 2026
    568b4f6
  11. added a commit that references this issue on Aug 11, 2026
    65169c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

needs review[Status] The PR/issue is awaiting review from the maintainerweb[Component] This issue will be transferred to adk-web

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions