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
Runner.run_async runs an LlmAgent with neither new_message nor invocation_id instead of raising ValueError #7934
Describe the Bug: Runner.run_async documents "Raises: ValueError: ... If both invocation_id and new_message are None.", and _run_with_trace has that check ("Running an agent requires either a new_message or an invocation_id ..."). But when the root agent is an LlmAgent, run_async takes the _run_node_async branch first and returns before reaching the check. So the run starts with no user message and calls the model with empty contents.
Steps to Reproduce:
pip install google-adk==2.13.0
Run the script below. It uses a recording model, so no API key is needed.
Expected Behavior: ValueError, as documented, before the model is called.
Observed Behavior:
No error; the model is called once with no contents.
Environment Details:
ADK Library Version (pip show google-adk): 2.13.0, and main at 95d8610
Desktop OS: Linux
Python Version (python -V): 3.12
Model Information:
Are you using LiteLLM: No
Which model is being used: a BaseLlm subclass that records its calls (any model shows it)
Additional Context:
In runners.py the if isinstance(self.agent, LlmAgent): branch (and the BaseNode one after it) return before _run_with_trace, where the check is. Moving the check before those branches covers them all.
Hi! I was able to reproduce this locally on ADK 2.13.0. In Runner.run_async, the LlmAgent branch routes into _run_node_async and returns early before reaching the new_message/invocation_id check in _run_with_trace, resulting in calling the model with empty contents instead of raising ValueError.
I'd like to work on this and submit a PR with unit tests. Could you please assign this to me?
@yifanxiong272. Reproduced this on 2.13.0 and on current main for both an LlmAgent and a Workflow root while a BaseAgent root still raises. In 1.x every root raised so this looks like it came in with the 2.x node path.
@mohitdixit02 one thing on #7936: a few existing tests run with new_message=None on purpose to re-run over the session history (test_llm_agent_include_contents.py and two in test_compaction_runner_e2e.py) and they fail with the check moved to the top as-is.
As a workaround, raising only when there’s no new_message, no invocation_id and the session has no events kept those tests green and still raised for the empty case. Could you both check if that works on your side?
Before #7936 goes for review please give it a full run of the runner, include_contents and compaction tests and add a case for a session that already has history.
I've updated the check in #7936 to inspect not session.events before raising when new_message and invocation_id are absent.
Full runs of test_runners.py, test_compaction_runner_e2e.py, and test_llm_agent_include_contents.py are all fine, and I've added a unit test covering run_async execution over existing session history with new_message=None.
Thanks @mohitdixit02, cd15247 looks right. Moving the check above the branches covers LlmAgent, Workflow and BaseAgent roots, and the history case keeps the include_contents and compaction re-runs working.
One thing: a BaseAgent root now calls get_session twice, once at the top of run_async and again in _run_with_trace, and the check there is now the same as the new one. That’s an extra round trip per run on Database or Vertex session services, so could you pass the session into _run_with_trace (as you already do for _run_node_async) and drop the duplicate check?
test_run_async_with_existing_history_and_no_new_message_succeeds only checks that some events came back. Could you assert that the model actually received the earlier user turn, and add the same history case for a Workflow root?
@yifanxiong272 once that’s in, could you run your repro against #7936 to confirm it now raises? I’ve flagged the PR for review.
Passed session=session into _run_with_trace and removed the duplicate session fetch and check, avoiding the extra round trip.
Strengthened test_run_async_with_existing_history_and_no_new_message_succeeds to verify that mock_model.requests[0].contents received the earlier user turn.
Added test_run_async_workflow_root_with_existing_history_and_no_new_message_succeeds testing the same history scenario with a Workflow root.
Ran the repro from the report against #7936 at a3e2ba6: with no new_message and no invocation_id, run_async on an empty session now raises the ValueError before the model is called (on 2.13.0 it ran and called the model with empty contents). I also checked the history case from your earlier comment: with an earlier user turn in the session and new_message=None, the run proceeds and the model receives that turn, so the include_contents and compaction re-runs keep working. Thanks to both of you.
Thanks @mohitdixit02 and @yifanxiong272 for confirming the repro. Went through 1ea3061. The session is now fetched once and passed to all three branches, the duplicate check in _run_with_trace is gone, and the history tests check that the earlier turn reaches the model for both LlmAgent and Workflow roots. Main and v2.14.0 still only check in _run_with_trace so this is still needed, and the branch merges cleanly on current main.
One thing to call out: a BaseAgent root (e.g. SequentialAgent) with history and no new_message now runs instead of raising. That fits the new rule, but it’s a behaviour change, so a quick SequentialAgent test for the empty and history cases would pin it. Could you also update the PR description? It still describes the original top-level check and the 4-test run. I’ve flagged #7936 for CI approval and review.
Added unit tests for SequentialAgent covering both the empty session (ValueError) and history session cases
(test_run_async_sequential_agent_root_empty_and_history_cases). All 243 tests in test_runners.py are passing.
Updated the PR description to accurately reflect the history-aware check, single session fetch, and the updated test plan.
Thanks @mohitdixit02, d0ee589 covers it. The SequentialAgent test raises on the empty session and checks that the earlier turn reaches the model in the history case, and the PR description now matches the history-aware check and the single session fetch.
Re-ran the original repro on current main (2.14.1) and LlmAgent and Workflow roots still call the model with empty contents, so this is still needed. The branch also merges cleanly onto main, which has moved about 80 commits since your base.
One small optional nit: the session is now fetched before the mode check, so an LlmAgent root with an invalid mode does a session lookup (or auto-create) before raising. You might want to move the mode check above the fetch.
Otherwise this looks good from my side. It’s just waiting on a maintainer to approve the workflows and review.
I've moved the root LlmAgent mode validation above _get_or_create_session so invalid modes fail fast before performing session lookups or auto-creation (commit bad28cf4e). Also updated the unit test to verify that get_session is not called in that failure path.
Activity
mohitdixit02 commentedon Nov 2, 2026
Hi! I was able to reproduce this locally on ADK 2.13.0. In
Runner.run_async, theLlmAgentbranch routes into_run_node_asyncand returns early before reaching thenew_message/invocation_idcheck in_run_with_trace, resulting in calling the model with empty contents instead of raisingValueError.I'd like to work on this and submit a PR with unit tests. Could you please assign this to me?
surajksharma07 commentedon Nov 2, 2026
@yifanxiong272. Reproduced this on 2.13.0 and on current main for both an LlmAgent and a Workflow root while a BaseAgent root still raises. In 1.x every root raised so this looks like it came in with the 2.x node path.
@mohitdixit02 one thing on #7936: a few existing tests run with new_message=None on purpose to re-run over the session history (test_llm_agent_include_contents.py and two in test_compaction_runner_e2e.py) and they fail with the check moved to the top as-is.
As a workaround, raising only when there’s no new_message, no invocation_id and the session has no events kept those tests green and still raised for the empty case. Could you both check if that works on your side?
Before #7936 goes for review please give it a full run of the runner, include_contents and compaction tests and add a case for a session that already has history.
fix(runner): permit run_async without new_message when session has hi…
mohitdixit02 commentedon Nov 3, 2026
@surajksharma07
Checked on my end and that works cleanly.
I've updated the check in #7936 to inspect
not session.eventsbefore raising whennew_messageandinvocation_idare absent.Full runs of
test_runners.py,test_compaction_runner_e2e.py, andtest_llm_agent_include_contents.pyare all fine, and I've added a unit test coveringrun_asyncexecution over existing session history withnew_message=None.Pushed the update to the PR branch!
surajksharma07 commentedon Nov 5, 2026
Thanks @mohitdixit02, cd15247 looks right. Moving the check above the branches covers LlmAgent, Workflow and BaseAgent roots, and the history case keeps the include_contents and compaction re-runs working.
One thing: a BaseAgent root now calls get_session twice, once at the top of run_async and again in _run_with_trace, and the check there is now the same as the new one. That’s an extra round trip per run on Database or Vertex session services, so could you pass the session into _run_with_trace (as you already do for _run_node_async) and drop the duplicate check?
test_run_async_with_existing_history_and_no_new_message_succeeds only checks that some events came back. Could you assert that the model actually received the earlier user turn, and add the same history case for a Workflow root?
@yifanxiong272 once that’s in, could you run your repro against #7936 to confirm it now raises? I’ve flagged the PR for review.
fix(runner): avoid duplicate session fetch in _run_with_trace and str…
mohitdixit02 commentedon Nov 5, 2026
Thanks for the review! Pushed commit a3e2ba6:
yifanxiong272 commentedon Nov 6, 2026
Ran the repro from the report against #7936 at a3e2ba6: with no new_message and no invocation_id,
run_asyncon an empty session now raises the ValueError before the model is called (on 2.13.0 it ran and called the model with empty contents). I also checked the history case from your earlier comment: with an earlier user turn in the session and new_message=None, the run proceeds and the model receives that turn, so the include_contents and compaction re-runs keep working. Thanks to both of you.fix(runner): raise ValueError in run_async when new_message and invoc…
fix(runner): permit run_async without new_message when session has hi…
fix(runner): avoid duplicate session fetch in _run_with_trace and str…
surajksharma07 commentedon Nov 9, 2026
Thanks @mohitdixit02 and @yifanxiong272 for confirming the repro. Went through 1ea3061. The session is now fetched once and passed to all three branches, the duplicate check in _run_with_trace is gone, and the history tests check that the earlier turn reaches the model for both LlmAgent and Workflow roots. Main and v2.14.0 still only check in _run_with_trace so this is still needed, and the branch merges cleanly on current main.
One thing to call out: a BaseAgent root (e.g. SequentialAgent) with history and no new_message now runs instead of raising. That fits the new rule, but it’s a behaviour change, so a quick SequentialAgent test for the empty and history cases would pin it. Could you also update the PR description? It still describes the original top-level check and the 4-test run. I’ve flagged #7936 for CI approval and review.
test(runner): add SequentialAgent root empty and history test cases (g…
mohitdixit02 commentedon Nov 9, 2026
Thanks @surajksharma07!
I have addressed both items:
SequentialAgentcovering both the empty session (ValueError) and history session cases(
test_run_async_sequential_agent_root_empty_and_history_cases). All 243 tests intest_runners.pyare passing.surajksharma07 commentedon Nov 16, 2026
Thanks @mohitdixit02, d0ee589 covers it. The SequentialAgent test raises on the empty session and checks that the earlier turn reaches the model in the history case, and the PR description now matches the history-aware check and the single session fetch.
Re-ran the original repro on current main (2.14.1) and LlmAgent and Workflow roots still call the model with empty contents, so this is still needed. The branch also merges cleanly onto main, which has moved about 80 commits since your base.
One small optional nit: the session is now fetched before the mode check, so an LlmAgent root with an invalid mode does a session lookup (or auto-create) before raising. You might want to move the mode check above the fetch.
Otherwise this looks good from my side. It’s just waiting on a maintainer to approve the workflows and review.
fix(runner): validate root LlmAgent mode before session fetch (google…
mohitdixit02 commentedon Nov 16, 2026
Thanks @surajksharma07!
I've moved the root
LlmAgentmode validation above_get_or_create_sessionso invalid modes fail fast before performing session lookups or auto-creation (commitbad28cf4e). Also updated the unit test to verify thatget_sessionis not called in that failure path.