{"record":{"id":"654a48999aaddcc2","repo":"microsoft/autogen","slug":"no-response-was-generated","errorCode":null,"errorMessage":"No response was generated","messagePattern":"No response was generated","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_agent.py","lineNumber":535,"sourceCode":"        return api_params\n\n    async def on_messages(\n        self: \"OpenAIAgent\", messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken\n    ) -> Response:\n        response = None\n        inner_messages: List[\n            Union[AgentEvent, TextMessage, MultiModalMessage, StopMessage, ToolCallSummaryMessage, HandoffMessage]\n        ] = []\n\n        async for msg in self.on_messages_stream(messages, cancellation_token):\n            if isinstance(msg, Response):\n                response = msg\n            # ModelClientStreamingChunkEvent does not exist in this version, so skip this check\n            else:\n                inner_messages.append(msg)\n\n        if response is None:\n            raise ValueError(\"No response was generated\")\n\n        if response.inner_messages is None:\n            response.inner_messages = []\n\n        for msg in inner_messages:\n            if msg not in response.inner_messages:\n                response.inner_messages = list(response.inner_messages) + [msg]\n\n        return response\n\n    async def on_messages_stream(\n        self: \"OpenAIAgent\", messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken\n    ) -> AsyncGenerator[\n        Union[\n            AgentEvent, TextMessage, MultiModalMessage, StopMessage, ToolCallSummaryMessage, HandoffMessage, Response\n        ],\n        None,\n    ]:","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_agent.py#L517-L553","documentation":"OpenAIAgent.on_messages consumes on_messages_stream and expects exactly one Response event to emerge. It initializes response=None and iterates the stream collecting non-Response events as inner messages; if the stream completes without ever yielding a Response, it raises ValueError('No response was generated'). This is a stream-protocol/lifecycle failure, not a model error — the agent's stream ended cleanly but never emitted its final result.","triggerScenarios":"The on_messages_stream implementation exiting before yielding Response (e.g. an empty message sequence, an internal early-return, or a subclass/custom stream that only yields chunk events); consuming a stream that was cancelled or drained elsewhere.","commonSituations":"Calling on_messages([]) or with only system messages in code paths where the underlying implementation skips the completion; custom subclasses of OpenAIAgent overriding on_messages_stream incorrectly; race conditions where the stream's final Response was already consumed.","solutions":["Ensure you pass a non-empty, well-formed message sequence to on_messages.","If you subclass or wrap OpenAIAgent, make sure on_messages_stream always yields a Response as its final event.","Upgrade autogen-ext — stream lifecycle edge cases around empty message lists have been fixed across releases.","As a defensive measure in caller code, consume on_messages_stream directly and handle the no-Response case explicitly (log + retry with the message re-sent)."],"exampleFix":"# before\nresponse = await agent.on_messages([], cancellation_token)\n\n# after\nfrom autogen_core import CancellationToken\nresponse = await agent.on_messages(\n    [TextMessage(source=\"user\", content=\"Hello\")], CancellationToken()\n)","handlingStrategy":"try-catch","validationCode":"if not messages:\n    raise ValueError(\"on_messages requires at least one message\")","typeGuard":null,"tryCatchPattern":"try:\n    response = await agent.on_messages(msgs, ct)\nexcept ValueError as e:\n    if \"No response was generated\" in str(e):\n        response = await agent.on_messages(msgs, ct)  # single retry with same input\n    else:\n        raise","preventionTips":["Always send a non-empty message sequence.","If subclassing, guarantee on_messages_stream yields a Response last.","Consume on_messages_stream directly when you need custom control over missing responses."],"tags":["openai","streaming","lifecycle","agent"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}