Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

LiteLlm with SSE streaming records the answer twice in gen_ai.output.messages

Aberta Para iniciantes
#7,630 7 comentários 0 reações 1 responsável Ver no GitHub

Mantenedores costumam responder em até 4 dias

@surajksharma07 já está trabalhando nisso.

Desde 22/10/2026.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
78/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python

Direção de pesquisa

Comece por src/google/adk/telemetry/_instrumentation.py, especialmente por record_llm_response, e compare como ele trata respostas parciais transmitidas em streaming em relação à resposta agregada. Em seguida, leia o código de streaming do LiteLlm em src/google/adk/models/lite_llm.py, perto das linhas vinculadas. Reproduza o problema com o exemplo fornecido de StreamingMode.SSE e verifique se a saída capturada contém uma única mensagem de resposta completa, correspondente a StreamingMode.NONE.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

models

🔴 Required Information

Describe the Bug:
with StreamingMode.SSE and a LiteLlm model the generate_content span ends up with every streamed chunk in gen_ai.output.messages and then the full answer again at the end. so the answer shows up twice and all the chunks have an empty finish_reason. without streaming its one message like expected. only visible with message content capture on (OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT)

looks like the text chunks get yielded as partial responses with no finish reason (lite_llm.py#L4475-L4485) and only the final aggregated response gets one (#L4556-L4558). record_llm_response keeps recording until it sees a finish reason (_instrumentation.py#L568-L595) so every chunk plus the aggregate goes in. since its in the LiteLlm wrapper i'd expect real providers to do the same but i only tested with litellm's mock_response

Steps to Reproduce:

  1. pip install google-adk litellm
  2. run this (no api key needed, it uses litellm's mock_response)
import asyncio
import json
import os

os.environ["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = "SPAN_ONLY"

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter

spans = InMemorySpanExporter()
provider = TracerProvider()
provider.add_span_processor(SimpleSpanProcessor(spans))
trace.set_tracer_provider(provider)

from google.adk.agents import Agent
from google.adk.agents.run_config import RunConfig, StreamingMode
from google.adk.models.lite_llm import LiteLlm
from google.adk.runners import InMemoryRunner
from google.genai import types


async def run(mode):
  spans.clear()
  model = LiteLlm(model="openai/gpt-4o", mock_response="Oslo is 4C and cloudy today.", api_key="unused")
  runner = InMemoryRunner(agent=Agent(name="a", model=model), app_name="p")
  session = await runner.session_service.create_session(app_name="p", user_id="u")
  msg = types.Content(role="user", parts=[types.Part(text="weather?")])
  async for _ in runner.run_async(user_id="u", session_id=session.id, new_message=msg,
                                  run_config=RunConfig(streaming_mode=mode)):
    pass
  await runner.close()
  span = next(s for s in spans.get_finished_spans() if s.name.startswith("generate_content"))
  messages = json.loads(span.attributes["gen_ai.output.messages"])
  print(f"{mode.name}: {len(messages)} output message(s)")
  for m in messages:
    print("  ", repr(m.get("finish_reason")), "".join(p.get("content", "") for p in m["parts"]))


asyncio.run(run(StreamingMode.NONE))
asyncio.run(run(StreamingMode.SSE))

Expected Behavior:
one output message with the full answer, same as without streaming

Observed Behavior:

NONE: 1 output message(s)
   'stop' Oslo is 4C and cloudy today.
SSE: 11 output message(s)
   '' Osl
   '' o i
   '' s 4
   '' C a
   '' nd
   '' clo
   '' udy
   ''  to
   '' day
   '' .
   'stop' Oslo is 4C and cloudy today.

Environment Details:

  • ADK Library Version (pip show google-adk): 2.12.0 (main at 77a74f0)
  • Desktop OS: macOS
  • Python Version (python -V): 3.12.15

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used: openai/gpt-4o via litellm mock_response

🟡 Optional Information

Regression:
havent checked older versions

maybe skip the partial chunks when recording output messages and keep just the aggregate? happy to send a PR if that sounds right

Linguagem predominante
Python
Estrelas
21.9k
Forks
4.2k
Merge médio
3d 16h
PRs com merge (30d)
6

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de google/adk-python

Todas as issues de google/adk-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.