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

Tool call response is ignored — assistant does not produce final message after tool response

Open Dandyoung opened this issue 1 year ago • 4 comments

After a tool is called and a response is returned (from a LiteLLM + TGI backend using OpenAI-compatible API), the ADK agent repeatedly re-calls the same tool instead of producing a final assistant message using the tool's result. This leads to repeated tool calls and eventually raises an UnprocessableEntityError (422) from the backend (missing field 'function' in response).

To Reproduce Install Google ADK from PyPI

Setup local HuggingFace TGI server with microsoft/phi-4 model

Configure ADK agent using LiteLlm :

Image

Describe the bug After a tool is called and a response is returned (from a LiteLLM + TGI backend using OpenAI-compatible API), the ADK agent repeatedly re-calls the same tool instead of producing a final assistant message using the tool's result. This leads to repeated tool calls and eventually raises an UnprocessableEntityError (422) from the backend (missing field 'function' in response).

To Reproduce

  1. Install Google ADK from PyPI
  2. Setup local HuggingFace TGI server with microsoft/phi-4 model
  3. Configure ADK agent using LiteLlm:
from google.adk.models.lite_llm import LiteLlm

llm = LiteLlm(
    model="phi-4-local",
    api_base="http://localhost:12320/v1",
    custom_llm_provider="openai",
    api_key="dummy",
    tool_choice={"type": "function", "function": {"name": "get_weather"}}
)
  1. Define a simple Python function for the tool:
def get_weather(city: str) -> dict:
    return {"status": "success", "report": f"{city} is sunny with 22°C."}
  1. Run conversation:
await call_agent_async("What's the weather in Seoul?")
  1. Tool is called, but assistant does not generate final message → tool is called again and again → 422 error

Expected behavior After receiving tool output, the assistant should produce a final content using the tool result and stop tool-calling. The final response should be inserted into the session and returned to the user.

Screenshots / Logs Tool response:

{"status": "success", "report": "Seoul is sunny with 22°C."}

But ADK re-calls the tool, causing:

422 UnprocessableEntityError - missing field `function`

Desktop (please complete the following information): OS: Ubuntu 22.04

Python version: 3.10

ADK version: google-adk==0.0.X (latest as of 2025-04-17)

LiteLLM: latest

TGI: serving microsoft/phi-4

Additional context Using OpenAI-compatible API (/v1) with HuggingFace TGI

Tool is correctly returned from LiteLLM (verified logs)

ADK appears not to insert a final assistant message with types.Content(role='assistant', parts=[Part(text=...)]) after tool execution

Image

Dandyoung avatar Apr 17 '25 10:04 Dandyoung

Thank you for reporting this @Dandyoung!

Can you please some information about your Agent definition? How does that look like?

ankursharmas avatar Apr 28 '25 20:04 ankursharmas

Hi, @ankursharmas, thanks for the response!

Here is how my Agent is defined :

# --- Agent definition ---
weather_agent = Agent(
    name="weather_agent_phi4",
    model=phi4_llm,
    description="Weather information provider agent",
    instruction=(
        "You are a weather assistant. When a user asks about the weather in a city, "
        "you should call the 'get_weather' tool to retrieve the weather information. "
        "After the tool is called, you must summarize the tool's response into a natural, user-friendly sentence. "
        "If 'status' is 'error', you must relay the 'error_message' directly to the user. "
        "After executing the tool once, **do not** repeatedly call the tool or retry. "
        "Always generate a final assistant message based on the tool's response."
    ),
    tools=[get_weather]
)

The model I'm using is a LiteLLM wrapper around a locally hosted HuggingFace TGI server (Microsoft Phi-4 model) with OpenAI-compatible /v1 API.

Let me know if you need any additional information.

Dandyoung avatar Apr 29 '25 03:04 Dandyoung

hello, I am facing the same issue using LiteLLM + TGI backend serving Qwen/Qwen3-8B. My agent definition is similar to the one the OP gave. The tools are correctly called by the agent but I have not been able to get a single final response after a tool call.

Here's a snippet of my agent definition

root_agent = LlmAgent(
    name="weather_time_agent",
    model=LiteLlm(
        model="huggingface/tgi",
        api_base="http://localhost:8080/v1/",
        repetition_penalty = 1.05,
    ),
    description=("Agent to answer questions about the time and weather in a city."),
    instruction=(
        "You are a helpful agent who can answer user questions about the time and weather in a city." \
        "You should call the 'get_weather' tool to retrieve the weather information."
        "If you determine a function call IS NOT required: Respond directly to the user's prompt in plain text, providing the answer or information requested."
    ),
    tools=[get_weather, get_current_time],
)

and here is a snippet of the tools definition

def get_weather(city: str) -> dict:
    """Retrieves the current weather report for a specified city.

    Args:
        city (str): The name of the city for which to retrieve the weather report.

    Returns:
        dict: status and result or error msg.
    """
    print(f"--- Tool: get_weather called for city: {city} ---")
    city_normalized = city.lower().replace(" ", "")

    mock_weather_db = {
        "newyork": {"status": "success", "report": "The weather in New York is sunny with a temperature of 25°C."},
        "london": {"status": "success", "report": "It's cloudy in London with a temperature of 15°C."},
        "tokyo": {"status": "success", "report": "Tokyo is experiencing light rain and a temperature of 18°C."},
    }

    if city_normalized in mock_weather_db:
        return mock_weather_db[city_normalized]
    else:
        return {"status": "error", "error_message": f"Weather information for '{city}' is not available."}

def get_current_time(city: str) -> dict:
    """Returns the current time in a specified city.

    Args:
        city (str): The name of the city for which to retrieve the current time.

    Returns:
        dict: status and result or error msg.
    """

    if city.lower() == "new york":
        tz_identifier = "America/New_York"
    else:
        return {
            "status": "error",
            "error_message": (
                f"Sorry, I don't have timezone information for {city}."
            ),
        }

    tz = ZoneInfo(tz_identifier)
    now = datetime.datetime.now(tz)
    report = (
        f'The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}'
    )
    return {"status": "success", "report": report}

Below is the error message i'm getting Image

As you can see, the response from the function call event is the one expected but it is not used to generate a final answer and then i get the error.

Find also the traceback attached traceback.txt

Let me know if you need anymore information.

Thank you !

MathieuVReine avatar Jul 01 '25 16:07 MathieuVReine

Hi @Dandyoung and thanks to everyone who participated in this thread.

We're currently doing some housekeeping on our issue tracker. Given the rapid pace of development and the number of updates since this was last active, there's a good chance this issue has been resolved in a newer version. To help us keep our backlog focused on current issues, we are closing this as stale.

If you're still facing this problem, could you please update to the very latest version of the library and confirm the issue still exists? If it does, please comment here, and we will be happy to reopen this issue and investigate further.

Thanks for your contribution and understanding!

surajksharma07 avatar Oct 07 '25 06:10 surajksharma07