adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

ADK Issue Summary: Infinite Loop with ThirdParty tools - CrewAI/LangChain Search Tool Calls

Open arjunprabhulal opened this issue 1 year ago • 9 comments

Describe the bug When using internet search tools with ADK agents, the agent gets stuck in an infinite loop of search tool calls. The framework does not properly detect when search operations should terminate, resulting in unlimited search requests without producing a final response.

To Reproduce Steps to reproduce the behavior:

  1. Install ADK: pip install google-adk
  2. Install search tool: pip install crewai-tools
  3. Create an agent with a search tool (like SerpApi or SerperDev)
  4. Run the agent with a query requiring internet search
  5. Observe that the agent keeps making search tool calls without stopping

Code sample to reproduce:

from google.adk import Agent, Runner
from google.adk.sessions import InMemorySessionService
from google.adk.tools.crewai_tool import CrewaiTool
from crewai_tools import SerpApiGoogleSearchTool
from google.genai import types

# Create search tool
search_tool = CrewaiTool(
    name="Web Search",
    description="Search the internet",
    tool=SerpApiGoogleSearchTool()
)

# Create agent
agent = Agent(
    name="search_agent",
    model="gemini-xxx",
    instruction="Answer questions using web search",
    tools=[search_tool]
)

# Set up session and runner
session_service = InMemorySessionService()
session = session_service.create_session(
    state={}, 
    app_name='search_app', 
    user_id='user123',
    session_id='session123'
)
runner = Runner(agent=agent, app_name='search_app', session_service=session_service)

# Run query - this will loop indefinitely
content = types.Content(role='user', parts=[types.Part(text="What is the current weather in New York?")])
events = runner.run(user_id='user123', session_id=session.id, new_message=content)
for event in events:
    print(event)

Expected behavior The agent should:

  1. Make a search tool call
  2. Process the results
  3. Provide a final text response
  4. Terminate the event loop

The is_final_response() method should correctly identify when search operations are complete and return True to end the processing.

Desktop (please complete the following information):

  • OS: macOS 14.3
  • Python version: 3.12.2
  • ADK version: 0.5.3

Additional context The root cause appears to be that:

  1. The is_final_response() method in Event class doesn't properly handle search tool responses
  2. There's no built-in limit for tool calls at the Runner level
  3. The agent doesn't recognize when it has sufficient information from searches

Current workaround: Implement custom logic to limit tool calls and force termination after processing search results.

arjunprabhulal avatar Apr 13 '25 03:04 arjunprabhulal

@hangfei @kweinmeister - It appears that above issue isn’t related to the ADK itself but rather to the litellm package. I’ve submitted a PR to address the infinite loop problem here: https://github.com/BerriAI/litellm/pull/9966. I have verified the fix locally using function calling with both Ollama/gemma3:27b and Ollama/llama3.2:latest , I will keep it above issue open until completely resolved

Image

arjunprabhulal avatar Apr 14 '25 05:04 arjunprabhulal

Thanks @arjunprabhulal !

Seems you have made Gemma working with ADK. One of user is asking for Gemma support. Could you share your setup and code snippet to help this user(https://github.com/google/adk-python/discussions/67)? cc: @lianggecm

hangfei avatar Apr 14 '25 05:04 hangfei

@hangfei I have created the repo https://github.com/arjunprabhulal/adk-gemma3-function-calling , this requires patching in your local as mentioned in the document

There's a known issue with Ollama's JSON format responses and LiteLLM's parsing that can cause a KeyError: 'name' error. This happens when Ollama returns JSON format that isn't specifically a tool call format. Error looks like: KeyError: 'name' in litellm/llms/ollama/completion/transformation.py A fix has been submitted in https://github.com/BerriAI/litellm/pull/9966 for the LiteLLM package but is still pending approval and merging. This bug might cause your application to crash or enter an infinite loop when using function calling with Ollama models. Temporary workarounds: Manually patch your local LiteLLM installation with the changes from PR #9966 Avoid using format=json in Ollama requests if possible Wait for the PR to be merged and update to the next LiteLLM release that includes the fix

arjunprabhulal avatar Apr 14 '25 11:04 arjunprabhulal

This issue should be fixed in the latest wheel. Feel free to re-open if you still see it.

hangfei avatar Apr 24 '25 01:04 hangfei

I am seeing this issue even now with search and function tools.

ankitdave06 avatar May 18 '25 17:05 ankitdave06

It was working yesteday and now its no longer working with this issue:

Name: google-adk Version: 1.7.0 Summary: Agent Development Kit

Even the basic get_weather sample ends on this infinite loop :'(

masterchop avatar Jul 20 '25 18:07 masterchop

It was working yesteday and now its no longer working with this issue:

Name: google-adk Version: 1.7.0 Summary: Agent Development Kit

Even the basic get_weather sample ends on this infinite loop :'(

any fix on this ?

proxybase-user avatar Nov 20 '25 07:11 proxybase-user

It was working yesteday and now its no longer working with this issue: Name: google-adk Version: 1.7.0 Summary: Agent Development Kit Even the basic get_weather sample ends on this infinite loop :'(

any fix on this ?

sorry, i dont recall what i did but i think i just had to switch from ollama_chat/model to ollama/model

I am sorry.

masterchop avatar Nov 20 '25 08:11 masterchop

The problem still exist as of today.

maxshatskiy avatar Feb 28 '26 11:02 maxshatskiy