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

CodeExecutorAgent's reflection step requires a non-empty result with str content. This fires when the reflection CreateResult is missing or its content is not a plain string (e.g., a list of tool calls or None), meaning the model did not produce a usable text reflection.

Source

Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py:869

        """
        all_messages = system_messages + await model_context.get_messages()
        llm_messages = cls._get_compatible_context(model_client=model_client, messages=all_messages)

        reflection_result: Optional[CreateResult] = None

        if model_client_stream:
            async for chunk in model_client.create_stream(llm_messages):
                if isinstance(chunk, CreateResult):
                    reflection_result = chunk
                elif isinstance(chunk, str):
                    yield ModelClientStreamingChunkEvent(content=chunk, source=agent_name)
                else:
                    raise RuntimeError(f"Invalid chunk type: {type(chunk)}")
        else:
            reflection_result = await model_client.create(llm_messages)

        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),
            )
        )

        yield Response(
            chat_message=TextMessage(

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Turn off the reflection feature if a text reflection is not needed.
  2. Use a model/client combination that reliably returns plain text when tools are disabled.
  3. Review output_content_type / json_output settings that may force non-string content.
  4. Upgrade client packages; older builds mishandled the reflection completion.
Defensive patterns

Strategy: fallback

Validate before calling

info = getattr(model_client, "model_info", None) or {}
# reflection needs plain-text completions; verify with a no-tools probe
result = await model_client.create([UserMessage(content="say ok", source="user")], tool_choice="none")
assert isinstance(result.content, str) and result.content, "model not suited for reflection"

Type guard

def is_text_result(result) -> bool:
    return bool(result) and isinstance(result.content, str)

Try / catch

try:
    async for ev in agent.on_messages_stream(msgs, ct):
        ...
except RuntimeError as e:
    if "no valid text response" in str(e):
        # disable reflection; tool results remain in context
        ...
    raise

Prevention

When it happens

Trigger: Reflection enabled on a CodeExecutorAgent with a model that keeps returning tool-call content instead of text, a client returning list-typed content, or an empty completion; structured-output settings converting content to non-str.

Common situations: Tool-heavy models that ignore the no-tools reflection prompt; local models without a reliable plain-text completion mode; misconfigured output_content_type.

Related errors


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