Skip to content

fix(runner): raise ValueError in run_async when new_message and invoc… - #7936

Open
mohitdixit02 wants to merge 5 commits into
google:mainfrom
mohitdixit02:fix/runner-run-async-validate-message
Open

mohitdixit02 wants to merge 5 commits into
google:mainfrom
mohitdixit02:fix/runner-run-async-validate-message

Conversation

@mohitdixit02

@mohitdixit02 mohitdixit02 commented Nov 2, 2026 •

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
When Runner.run_async is invoked on an empty session without a new_message or invocation_id, it is expected to raise a ValueError. However:

  1. When the root agent was an LlmAgent or a BaseNode, run_async branched into _run_node_async() and returned before reaching the validation check in _run_with_trace, dispatching empty contents ([[]]) to the underlying model.
  2. An unconditional check on not new_message and not invocation_id would break valid workflows and conversational sessions where events already exist in history and the caller only wishes to continue/resume execution without appending a new user turn.
  3. The session lookup was duplicated: run_async fetched the session for validation, and subsequent inner methods (_run_node_async, _run_with_trace) performed redundant fetches.

Solution:

  1. Moved the empty-session check to Runner.run_async immediately following session retrieval:
    if not new_message and not invocation_id and not session.events:
      raise ValueError(
          'Running an agent requires either a new_message or an invocation_id'
          f' for session: {session_id}'
      )
  2. Passed the fetched session directly into _run_node_async and _run_with_trace, removing duplicate session lookups and removing the redundant check inside _run_with_trace.
  3. Allowed sessions containing pre-existing event history to proceed normally without requiring new_message, preserving execution across LlmAgent, Workflow, and BaseAgent (SequentialAgent) roots.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Summary of targeted pytest runs:

pytest tests/unittests/test_runners.py -k "test_run_async_llm_agent_without_message_or_invocation_id_raises_value_error or
test_run_async_base_node_without_message_or_invocation_id_raises_value_error or
test_run_async_with_existing_history_and_no_new_message_succeeds or
test_run_async_workflow_root_with_existing_history_and_no_new_message_succeeds or
test_run_async_sequential_agent_root_empty_and_history_cases"

collected 243 items / 238 deselected / 5 selected
tests/unittests/test_runners.py .....                                    [100%]
================ 5 passed, 238 deselected, 2 warnings in 3.70s ================

Full test file execution:

pytest tests/unittests/test_runners.py
====================== 243 passed, 63 warnings in 7.19s =======================

Manual End-to-End (E2E) Tests:

Verified against the reproduction script in #7934 with an LlmAgent and a recording model:

    runner = Runner(
        app_name="demo",
        agent=LlmAgent(name="greeter", model=Recorder()),
        session_service=InMemorySessionService(),
    )
    await runner.session_service.create_session(app_name="demo", user_id="u", session_id="s")
    events = [event async for event in runner.run_async(user_id="u", session_id="s", new_message=None)]
  • Before: Executed model call with empty contents (events: 1, model calls: [[]]).
  • After: Raises ValueError: Running an agent requires either a new_message or an invocation_id for session: s.
  • With History: When session.events has prior conversation turns, calling run_async(user_id="u", session_id="s", new_message=None) succeeds and delivers the history to the agent without raising.

Checklist

  • I have read the CONTRIBUTING.md https://github.com/google/adk-python/blob/main/CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

@mohitdixit02
mohitdixit02 force-pushed the fix/runner-run-async-validate-message branch from a3e2ba6 to 1ea3061 Compare November 6, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runner.run_async runs an LlmAgent with neither new_message nor invocation_id instead of raising ValueError

2 participants