microsoft/autogen · error · RuntimeError

The agent did not produce a final response. Check the agent'

Error message

The agent did not produce a final response. Check the agent's on_messages_stream method.

What it means

Raised inside ChatAgentContainer when a participant agent's on_messages_stream completed without ever producing a final Response object. The ChatAgent streaming contract requires the stream to end with a Response carrying the chat message; an empty stream (early return, exception swallowed, or a broken custom agent) leaves the container with no result to publish to the group chat.

Source

Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_chat_agent_container.py:140

                raise
        else:
            # If the agent is not a team, handle it as a single agent.
            with trace_invoke_agent_span(
                agent_name=self._agent.name,
                agent_description=self._agent.description,
                agent_id=str(self.id),
            ):
                try:
                    # Pass the messages in the buffer to the delegate agent.
                    response: Response | None = None
                    async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token):
                        if isinstance(msg, Response):
                            await self._log_message(msg.chat_message)
                            response = msg
                        else:
                            await self._log_message(msg)
                    if response is None:
                        raise RuntimeError(
                            "The agent did not produce a final response. Check the agent's on_messages_stream method."
                        )
                    # Publish the response to the group chat.
                    self._message_buffer.clear()
                    await self.publish_message(
                        GroupChatAgentResponse(response=response, name=self._agent.name),
                        topic_id=DefaultTopicId(type=self._parent_topic_type),
                        cancellation_token=ctx.cancellation_token,
                    )
                except Exception as e:
                    # Publish the error to the group chat.
                    error_message = SerializableException.from_exception(e)
                    await self.publish_message(
                        GroupChatError(error=error_message),
                        topic_id=DefaultTopicId(type=self._parent_topic_type),
                        cancellation_token=ctx.cancellation_token,
                    )
                    # Raise the error to the runtime.

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Make your custom agent's on_messages_stream always end with yield Response(chat_message=...) on every path.
  2. Wrap the body in try/finally and emit a fallback Response in finally if none was produced.
  3. Use the built-in agents (AssistantAgent, etc.) or carefully follow their streaming pattern when implementing custom ones.

Example fix

// before
class MyAgent(ChatAgent):
    async def on_messages_stream(self, messages, cancellation_token):
        for ev in self._steps(messages):
            yield ev  # no final Response

// after
class MyAgent(ChatAgent):
    async def on_messages_stream(self, messages, cancellation_token):
        for ev in self._steps(messages):
            yield ev
        yield Response(chat_message=TextMessage(content=self._final_text, source=self.name))
Defensive patterns

Strategy: validation

Validate before calling

async def stream_ends_with_response(agent: ChatAgent, msgs: list[BaseChatMessage]) -> bool:
    saw_response = False
    async for ev in agent.on_messages_stream(msgs, CancellationToken()):
        if isinstance(ev, Response):
            saw_response = True
    return saw_response
# unit-test this for each custom agent

Try / catch

try:
    async for ev in team.run_stream(task):
        ...
except RuntimeError as e:
    if "did not produce a final response" in str(e):
        # fix the offending agent's on_messages_stream to end with yield Response(...)
        ...

Prevention

When it happens

Trigger: A custom ChatAgent whose on_messages_stream yields only intermediate events (e.g. tool calls) and returns; an inner agent whose stream is cancelled or short-circuited before the final Response; subclass overrides that forget to yield the closing Response.

Common situations: Writing custom agents to use inside RoundRobinGroupChat/SelectorGroupChat; upgrading autogen versions where the on_messages_stream contract was tightened; wrapping third-party agents that end streams abruptly.

Related errors


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