IndexError in ParallelAgent when using include_contents="none" with parallel tool calls
Please make sure you read the contribution guide and file the issues in the right place. Contribution guide.
Describe the bug
ADK crashes with IndexError when using ParallelAgent with LlmAgent instances that have include_contents="none" and make parallel tool calls. The error occurs in _rearrange_events_for_latest_function_response when trying to access events[-2] on an empty or insufficient events list.
To Reproduce Steps to reproduce the behavior:
- Create a ParallelAgent with multiple LlmAgent sub-agents
- Set
include_contents="none"on the LlmAgent instances - Provide tools to the agents (e.g., a weather function tool)
- Run the agent with a prompt that causes parallel tool execution
- See IndexError crash
Expected behavior
The ParallelAgent should handle parallel tool calls from sub-agents with include_contents="none" without crashing, properly managing the event list even when content history is limited.
Screenshots Error log:
% adk run .
[user]: tell me about the weather in paris
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.12/bin/adk", line 8, in <module>
sys.exit(main())
^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 1161, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 1082, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 1697, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 1443, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 788, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/cli/cli_tools_click.py", line 260, in cli_run
asyncio.run(
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/cli/cli.py", line 178, in run_cli
await run_interactively(
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/cli/cli.py", line 97, in run_interactively
async for event in runner.run_async(
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/runners.py", line 203, in run_async
async for event in invocation_context.agent.run_async(invocation_context):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 201, in run_async
async for event in self._run_async_impl(ctx):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/parallel_agent.py", line 105, in _run_async_impl
async for event in _merge_agent_run(agent_runs):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/parallel_agent.py", line 71, in _merge_agent_run
yield task.result()
^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 201, in run_async
async for event in self._run_async_impl(ctx):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 275, in _run_async_impl
async for event in self._llm_flow.run_async(ctx):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 283, in run_async
async for event in self._run_one_step_async(invocation_context):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 303, in _run_one_step_async
async for event in self._preprocess_async(invocation_context, llm_request):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 338, in _preprocess_async
async for event in processor.run_async(invocation_context, llm_request):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line 55, in run_async
llm_request.contents = _get_current_turn_contents(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line 281, in _get_current_turn_contents
return _get_contents(current_branch, events[i:], agent_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line 239, in _get_contents
result_events = _rearrange_events_for_latest_function_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line 143, in _rearrange_events_for_latest_function_response
function_calls = events[-2].get_function_calls()
~~~~~~^^^^
IndexError: list index out of range
Desktop (please complete the following information):
- OS: macOS (Darwin 24.5.0)
- Python version(python -V): 3.12
- ADK version(pip show google-adk): 1.6.1
Model Information: Affected multiple models:
- gemini-2.5-flash
- gemini-2.0-flash
- vertex_ai/claude-sonnet-4@20250514 via LiteLlm
Additional context
The error occurs in /google/adk/flows/llm_flows/contents.py:143 when the code assumes there are at least 2 events in the list (events[-2]) but the list is shorter. This suggests the include_contents="none" setting affects event collection in a way that breaks the parallel execution flow's assumptions about event history availability.
Simple example:
from google.adk.agents import ParallelAgent, LlmAgent
from google.adk.tools import FunctionTool
def get_weather_report(city: str) -> dict:
if city.lower() == "london":
return {"status": "success", "report": "The current weather in London is cloudy with a temperature of 18 degrees Celsius and a chance of rain."}
elif city.lower() == "paris":
return {"status": "success", "report": "The weather in Paris is sunny with a temperature of 25 degrees Celsius."}
else:
return {"status": "error", "error_message": f"Weather information for '{city}' is not available."}
weather_tool = FunctionTool(func=get_weather_report)
llm_agent_1 = LlmAgent(
name=f"llm_agent_1",
model="gemini-2.5-flash",
instruction=(
"You are a helpful agent. Always use your tools to help user"
),
include_contents="none",
tools=[weather_tool]
)
llm_agent_2 = LlmAgent(
name=f"llm_agent_2",
model="gemini-2.5-flash",
instruction=(
"You are a helpful agent. Always use your tools to help user"
),
include_contents="none",
tools=[weather_tool]
)
root_agent = ParallelAgent(name="workflow", sub_agents=[
llm_agent_1,
llm_agent_2
])
Additional Information - Version Compatibility
This issue reproduces on both ADK versions but with different error messages:
ADK 1.6.1:
IndexError: list index out of range
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/contents.py", line
143, in _rearrange_events_for_latest_function_response
function_calls = events[-2].get_function_calls()
~~~~~~^^^^
ADK 1.13.0 (latest):
+ Exception Group Traceback (most recent call last):
| File "/Library/Frameworks/Python.framework/Versions/3.12/bin/adk", line 7, in <module>
| sys.exit(main())
| ^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 1161, in __call__
| return self.main(*args, **kwargs)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 1082, in main
| rv = self.invoke(ctx)
| ^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 1697, in invoke
| return _process_result(sub_ctx.command.invoke(sub_ctx))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 1443, in invoke
| return ctx.invoke(self.callback, **ctx.params)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/click/core.py", line 788, in invoke
| return __callback(*args, **kwargs)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/cli/cli_tools_click.py", line 271, in cli_run
| asyncio.run(
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
| return runner.run(main)
| ^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
| return self._loop.run_until_complete(task)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
| return future.result()
| ^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/cli/cli.py", line 187, in run_cli
| await run_interactively(
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/cli/cli.py", line 110, in run_interactively
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/runners.py", line 248, in run_async
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/runners.py", line 244, in _run_with_trace
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/runners.py", line 288, in _exec_with_plugin
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/runners.py", line 238, in execute
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 248, in run_async
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 238, in _run_with_trace
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/parallel_agent.py", line 188, in _run_async_impl
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/parallel_agent.py", line 144, in _merge_agent_run
| async with asyncio.TaskGroup() as tg:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/taskgroups.py", line 145, in __aexit__
| raise me from None
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/parallel_agent.py", line 135, in process_an_agent
| async for event in events_for_one_agent:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 248, in run_async
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 238, in _run_with_trace
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 288, in _run_async_impl
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 401, in run_async
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 437, in _run_one_step_async
| async for llm_response in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 761, in _call_llm_async
| async for event in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 745, in _call_llm_with_tracing
| async for llm_response in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 937, in _run_and_handle_error
| raise model_error
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 921, in _run_and_handle_error
| async for response in agen:
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/adk/models/google_llm.py", line 200, in generate_content_async
| response = await self.api_client.aio.models.generate_content(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/genai/models.py", line 7427, in generate_content
| response = await self._generate_content(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/genai/models.py", line 6394, in _generate_content
| response = await self._api_client.async_request(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/genai/_api_client.py", line 1101, in async_request
| result = await self._async_request(http_request=http_request, stream=False)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/genai/_api_client.py", line 1046, in _async_request
| return await self._async_retry( # type: ignore[no-any-return]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 111, in __call__
| do = await self.iter(retry_state=retry_state)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 153, in iter
| result = await action(retry_state)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/tenacity/_utils.py", line 99, in inner
| return call(*args, **kwargs)
| ^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/tenacity/__init__.py", line 418, in exc_check
| raise retry_exc.reraise()
| ^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/tenacity/__init__.py", line 185, in reraise
| raise self.last_attempt.result()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 449, in result
| return self.__get_result()
| ^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
| raise self._exception
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 114, in __call__
| result = await fn(*args, **kwargs)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/genai/_api_client.py", line 1027, in _async_request_once
| await errors.APIError.raise_for_async_response(response)
| File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/google/genai/errors.py", line 155, in raise_for_async_response
| raise ClientError(status_code, response_json, response)
| google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'The request is not supported by this model.', 'status': 'INVALID_ARGUMENT'}}
+------------------------------------
@TaurusLAK include_content="none" and using tools are contradicted from concepts.
include_content="none" means you don't want agent to preserve any conversation history and just react based on system instruction + user input. Using tools would require agent to preserve conversation history, aka not setting include_content="none"
I think this should answer your question. Feel free to re-open if you have more questions.
@Jacksunwei Thanks for the reply,
Our usecase: We have a workflow with multiple agents. On of them is the planner that creates tasks to process incoming user request. The agent creates instructions for executor agents (experts) that have access to various tools (RAG, MCP, DBs etc). Each executor's task is embedded into their system prompt using ADK capabilities. Our goal is to give these executors isolated context so they focus only on their specific system prompt, which is already enriched with their particular task. However, we're encountering the IndexError when using include_contents="none" in ParallelAgent scenarios. How can we achieve proper context isolation for expert agents while avoiding this bug? Is there an alternative approach to limit context history that doesn't trigger this IndexError?
P.S. I don't have permissions to reopen the issue, can you reopen it or should I create a new one?
@Jacksunwei I am also facing a similar issue.
I have a workflow SequentialAgent[ ParalletAgent(sub_agents=[sa_1, sa_2, sa_3]) -> LLMAgent]. The ParallelAgent decides whether the LLMAgents should be invoked or not. When invoked, I want to be able to run the LLMAgent based independent of any context along with the input, but setting include_content="none" in LLMAgent uses
"For context:"
"[sa_3] said: ..."
Currently, I am handling this with mutating the request passed in callback.