microsoft/autogen · error · RuntimeError

Reflect on tool use produced no valid text response.

Error message

Reflect on tool use produced no valid text response.

What it means

After reflect_on_tool_use runs a follow-up model call (with tool_choice="none"), AssistantAgent requires a non-empty result whose content is a plain string. This error fires when the reflection result is falsy or its content is not str (e.g., a list of FunctionCall, None, or structured output object).

Source

Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py:1458

            ):
                if isinstance(chunk, CreateResult):
                    reflection_result = chunk
                elif isinstance(chunk, str):
                    yield ModelClientStreamingChunkEvent(
                        content=chunk, source=agent_name, full_message_id=reflection_message_id
                    )
                else:
                    raise RuntimeError(f"Invalid chunk type: {type(chunk)}")
        else:
            reflection_result = await model_client.create(
                llm_messages,
                json_output=output_content_type,
                cancellation_token=cancellation_token,
                tool_choice="none",  # Do not use tools in reflection flow.
            )

        if not reflection_result or not isinstance(reflection_result.content, str):
            raise RuntimeError("Reflect on tool use produced no valid text response.")

        # --- NEW: If the reflection produced a thought, yield it ---
        if reflection_result.thought:
            thought_event = ThoughtEvent(content=reflection_result.thought, source=agent_name)
            yield thought_event
            inner_messages.append(thought_event)

        # Add to context (including thought if present)
        await model_context.add_message(
            AssistantMessage(
                content=reflection_result.content,
                source=agent_name,
                thought=getattr(reflection_result, "thought", None),
            )
        )

        if output_content_type:
            content = output_content_type.model_validate_json(reflection_result.content)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Set reflect_on_tool_use=False if you don't need the reflection step.
  2. Use a model/client that honors tool_choice="none" and returns plain text completions.
  3. If output_content_type is set, verify it is compatible with the reflection path or remove it.
  4. Upgrade autogen-ext client packages; older clients sometimes drop tool_choice.

Example fix

// before
assistant = AssistantAgent(
    name="assistant",
    model_client=client,
    reflect_on_tool_use=True,
)

// after
assistant = AssistantAgent(
    name="assistant",
    model_client=client,
    reflect_on_tool_use=False,
)
Defensive patterns

Strategy: fallback

Validate before calling

info = model_client.model_info or {}
supports_text = True  # verify client honors tool_choice='none'
if reflect_on_tool_use and not supports_text:
    reflect_on_tool_use = False

Type guard

def reflection_is_text(result) -> bool:
    return bool(result) and isinstance(result.content, str) and len(result.content) > 0

Try / catch

try:
    async for ev in assistant.on_messages_stream(msgs, ct):
        ...
except RuntimeError as e:
    if "no valid text response" in str(e):
        # rerun without reflection; tool results are already in context
        assistant._reflect_on_tool_use = False
    raise

Prevention

When it happens

Trigger: reflect_on_tool_use=True with a model/client that ignores tool_choice="none" and returns tool calls anyway; a client returning content as a list; an empty completion; output_content_type (json_output) configured so reflection content is parsed into a non-str object.

Common situations: Models that are tool-call-heavy and keep emitting tool-call content even when tools are disabled; custom clients that don't honor tool_choice; JSON/structured-output mode returning dicts.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/4a83bdafee608681. Report an issue: GitHub.