Skip to content

strip_thinking_tokens crashes on list-shaped streaming delta content (AttributeError: 'list' object has no attribute 'find') #6323

Description

@KSerProject

Versions: livekit-agents 1.6.3 (the code is unchanged on current main), livekit-plugins-openai, Python 3.12.

Setup: openai.LLM plugin pointed at an OpenAI-compatible provider (Mistral, base_url=https://api.mistral.ai/v1), wrapped in llm.FallbackAdapter.

What happens: the OpenAI-compatible streaming schema allows delta.content to be either a str or a list of typed content parts ([{"type": "text", "text": "…"}]). Mistral has started emitting the list form on some streamed chunks. llm/utils.py::strip_thinking_tokens assumes str | None and calls content.find(...), raising AttributeError: 'list' object has no attribute 'find'. The plugin wraps this as a retryable APIConnectionError; under a FallbackAdapter the failure lands mid-stream ("failed after sending chunk, skip retrying"), so the adapter silently moves the whole session to the fallback leg — a hard-to-diagnose degradation for voice agents.

Repro (no network):

import asyncio
from livekit.agents.llm.utils import strip_thinking_tokens
strip_thinking_tokens([{"type": "text", "text": "Hallo"}], asyncio.Event())
# AttributeError: 'list' object has no attribute 'find'

Suggested fix: flatten list-shaped content to its concatenated text parts before the tag scan — see the linked PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions