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

Web UI: Local LLM stops responding if `Token Streaming` enabled in the UI

Open pixelsoccupied opened this issue 1 year ago • 8 comments

Describe the bug When using export OLLAMA_API_BASE="http://localhost:11434" && adk web with Token Streaming enabled, local LLM stops responding (with or without stream=True in LiteLLM). But thankfully back to normal if disabled.

To Reproduce

Code

import datetime
from zoneinfo import ZoneInfo
from google.adk.agents import Agent
# Ensure this import is present from your setup cells
from google.adk.models.lite_llm import LiteLlm


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.
    """
    if city.lower() == "new york":
        return {
            "status": "success",
            "report": (
                "The weather in New York is sunny with a temperature of 25 degrees"
                " Celsius (41 degrees Fahrenheit)."
            ),
        }
    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}


root_agent = Agent(
    name="weather_time_agent",
    model=LiteLlm(model="ollama_chat/qwen2.5:32b-instruct-q4_K_M", stream=True), # Note the issue happen with or without this `stream=True` 
    description=(
        "Agent to answer questions about the time and weather in a city."
    ),
    instruction=(
        "You are a helpful agent who can answer user 3questions about the time and weather in a city."
    ),
    tools=[get_weather, get_current_time],
)

Run

# run local llm
ollama run qwen2.5:32b-instruct-q4_K_M

# run Web UI
export OLLAMA_API_BASE="http://localhost:11434" && adk web

Expected behavior LLM responds just as it would with Token Streaming disabled

Screenshots Image Image

Desktop (please complete the following information):

  • OS: macOS
  • Python version(python -V): Python 3.12.0
  • ADK version(pip show google-adk): 0.2.0

Additional context Used Safari and Chrome

pixelsoccupied avatar Apr 19 '25 20:04 pixelsoccupied

@selcukgun do you know if token-streaming is supported for LiteLlm model?

hangfei avatar Apr 20 '25 05:04 hangfei

@selcukgun @hangfei Hi, I also want to know if token-streaming is supported for LiteLlm model?

zerone-agent avatar Apr 22 '25 07:04 zerone-agent

Is there a config i can set to increase the logging verbosity? please share any tips to debug...would love the understand the codebase and help out :)

pixelsoccupied avatar Apr 25 '25 15:04 pixelsoccupied

Any news on this?

BenSnaas avatar Apr 28 '25 14:04 BenSnaas

token-streaming is not supported.

@selcukgun to consider when to support this.

hangfei avatar Apr 28 '25 20:04 hangfei

@pixelsoccupied we are still working on a adk contributor tutorial. cc: @polong-lin

hangfei avatar Apr 28 '25 20:04 hangfei

I need this feature too. Would love to to help out.

sr198 avatar Apr 29 '25 11:04 sr198

Hi everyone, this issue is caused by ollama not supporting streaming when tool calls are included. The issue has been resolved in ollama v0.8.0. FYI

My runtime information:

adk: v1.1.1 ollama: v0.9.0

jinmiaoluo avatar May 30 '25 00:05 jinmiaoluo