Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/google/adk/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,13 @@ async def run_async(
if new_message and new_message.role != 'user':
new_message = types.Content(role='user', parts=new_message.parts)

if not invocation_id and new_message is None:
raise ValueError(
'Running an agent requires either a new_message or an '
'invocation_id to resume a previous invocation. '
f'Session: {session_id}, User: {user_id}'
)

from .agents.llm_agent import LlmAgent
from .workflow._base_node import BaseNode

Expand Down
48 changes: 48 additions & 0 deletions tests/unittests/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -7414,5 +7414,53 @@ async def _consume():
assert not [e for e in session.events if e.actions.compaction]


async def test_run_async_llm_agent_without_message_or_invocation_id_raises_value_error():
"""Runner.run_async must raise ValueError when both new_message and invocation_id are None (#7934)."""
session_service = InMemorySessionService()
runner = Runner(
app_name="test_app",
agent=MockLlmAgent("test_agent"),
session_service=session_service,
auto_create_session=True,
)
with pytest.raises(
ValueError,
match=r"Running an agent requires either a new_message or an invocation_id",
):
agen = runner.run_async(
user_id="u",
session_id="s",
new_message=None,
invocation_id=None,
)
async for _ in agen:
pass


async def test_run_async_base_node_without_message_or_invocation_id_raises_value_error():
"""Runner.run_async with BaseNode root must raise ValueError when both new_message and invocation_id are None (#7934)."""
from google.adk.workflow._base_node import BaseNode

session_service = InMemorySessionService()
node = BaseNode(name="test_node")
runner = Runner(
app=App(name="test_app", root_agent=node),
session_service=session_service,
auto_create_session=True,
)
with pytest.raises(
ValueError,
match=r"Running an agent requires either a new_message or an invocation_id",
):
agen = runner.run_async(
user_id="u",
session_id="s",
new_message=None,
invocation_id=None,
)
async for _ in agen:
pass


if __name__ == "__main__":
pytest.main([__file__])
Loading