Ask LLM Agent with include_contents="none" and Tools Loops Infinitely
** Please make sure you read the contribution guide and file the issues in the right place. ** Contribution guide.
Describe the bug When an ask_llm_agent is configured with both tools and include_contents="none", the execution of the tool enters an infinite loop, never terminating. This behavior is unexpected and indicates a bug that needs to be addressed.
To Reproduce Steps to reproduce the behavior:
- Create an ask_llm_agent:
- Configure the agent to use one or more tools.
- Set include_contents="none" in the agent's configuration.
Expected behavior The ask_llm_agent should execute the tool once, process its output, and provide a response, even when include_contents="none" is set. The agent should not enter an infinite loop.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Windows
- Python version(python -V): 3.11
- ADK version(pip show google-adk): Main version
Additional context Add any other context about the problem here.
Yes, I'm seeing the same thing. Probable duplicate of #784.
I think the problem is in
llm_flows/contents.py (https://github.com/google/adk-python/blob/main/src/google/adk/flows/llm_flows/contents.py#L46)
class _ContentLlmRequestProcessor(BaseLlmRequestProcessor):
"""Builds the contents for the LLM request."""
@override
async def run_async(
self, invocation_context: InvocationContext, llm_request: LlmRequest
) -> AsyncGenerator[Event, None]:
from ...agents.llm_agent import LlmAgent
agent = invocation_context.agent
if not isinstance(agent, LlmAgent):
return
if agent.include_contents != 'none':
llm_request.contents = _get_contents(
invocation_context.branch,
invocation_context.session.events,
agent.name,
)
# Maintain async generator behavior
if False: # Ensures it behaves as a generator
yield # This is a no-op but maintains generator structure
If the agent has include_contents="none", then the output of the tool call are not fed into the contents of the follow-on request to the LLM.
same for me. what is the expected behavior of include_contents='none'?
Now it seems the tool_calls and response in current round is never attached to the next llm call
@FengShi0705 I have seen the contents list and it shows the function_response but still retrying the function call.
I have this exact problem when deploying my adk app to agent engine. Interestingly not if I run it via script/runner locally. Also, the solution to include the current turn in the contents feels hacky and defeats the purpose of an option to isolate an instance from the context.