microsoft/autogen · error · ValueError
No response was generated
Error message
No response was generated
What it means
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.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_agent.py:535
return api_params
async def on_messages(
self: "OpenAIAgent", messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken
) -> Response:
response = None
inner_messages: List[
Union[AgentEvent, TextMessage, MultiModalMessage, StopMessage, ToolCallSummaryMessage, HandoffMessage]
] = []
async for msg in self.on_messages_stream(messages, cancellation_token):
if isinstance(msg, Response):
response = msg
# ModelClientStreamingChunkEvent does not exist in this version, so skip this check
else:
inner_messages.append(msg)
if response is None:
raise ValueError("No response was generated")
if response.inner_messages is None:
response.inner_messages = []
for msg in inner_messages:
if msg not in response.inner_messages:
response.inner_messages = list(response.inner_messages) + [msg]
return response
async def on_messages_stream(
self: "OpenAIAgent", messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken
) -> AsyncGenerator[
Union[
AgentEvent, TextMessage, MultiModalMessage, StopMessage, ToolCallSummaryMessage, HandoffMessage, Response
],
None,
]:View on GitHub (pinned to 027ecf0a37)
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).
Example fix
# before
response = await agent.on_messages([], cancellation_token)
# after
from autogen_core import CancellationToken
response = await agent.on_messages(
[TextMessage(source="user", content="Hello")], CancellationToken()
) Defensive patterns
Strategy: try-catch
Validate before calling
if not messages:
raise ValueError("on_messages requires at least one message") Try / catch
try:
response = await agent.on_messages(msgs, ct)
except ValueError as e:
if "No response was generated" in str(e):
response = await agent.on_messages(msgs, ct) # single retry with same input
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Please set OPENAI_API_KEY environment variable.
- Only one choice is supported in streaming response
- Invalid streaming message type {reply.GetType().Name}
- Only one choice is supported in streaming response
- Invalid streaming message type {reply.GetType().Name}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/654a48999aaddcc2.
Report an issue: GitHub.