Skip to content

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

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

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

Conversation

@mohitdixit02

Copy link
Copy Markdown

Link to Issue or Description of Change

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

Problem:
Runner.run_async documents:
Raises: ValueError: If the session is not found; If both invocation_id and new_message are None.

However, when the root agent is an LlmAgent or a BaseNode, run_async branched into _run_node_async() and returned before reaching the validation check in _run_with_trace. As a result, calling run_async with new_message=None and invocation_id=None ran without error and called the model with empty contents ([[]]).

Solution:
Enforced the if not invocation_id and new_message is None: check at the entry of Runner.run_async before delegating to _run_node_async or _run_with_trace.
This ensures all root agent types (LlmAgent, BaseNode, and BaseAgent) uniformly validate the arguments and raise ValueError as documented.

Testing Plan

Unit Tests:

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

Summary of passed pytest results:

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_applies_state_delta_when_resuming_without_new_message"

collected 238 items / 234 deselected / 4 selected
tests/unittests/test_runners.py ....                                     [100%]
====================== 4 passed, 234 deselected in 6.03s ======================

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 to resume a previous invocation. Session: s, User: u.

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.

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