microsoft/autogen · error · InvalidOperationException
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
ChatAgentRouter drains an agent's chat stream (StreamAsync) and requires at least one ChatStreamFrame of FrameType.Response; each Response frame sets the local 'response' variable. If the stream ends with only Text/Output/InternalMessage frames (response stays null), HandleAsync throws InvalidOperationException after forwarding the partial messages, so the parent never receives a GroupChatAgentResponse.
Source
Thrown at dotnet/src/Microsoft.AutoGen/AgentChat/GroupChat/ChatAgentRouter.cs:86
// the lack of real type unions in C#, which is why we need to create the StreamingFrame type in the first
// place.
await foreach (ChatStreamFrame frame in this.agent.StreamAsync(this.MessageBuffer, messageContext.CancellationToken))
{
switch (frame.Type)
{
case ChatStreamFrame.FrameType.Response:
await this.PublishMessageAsync(new GroupChatMessage { Message = frame.Response!.Message }, this.outputTopic);
response = frame.Response;
break;
case ChatStreamFrame.FrameType.InternalMessage:
await this.PublishMessageAsync(new GroupChatMessage { Message = frame.InternalMessage! }, this.outputTopic);
break;
}
}
if (response == null)
{
throw new InvalidOperationException("The agent did not produce a final response. Check the agent's on_messages_stream method.");
}
this.MessageBuffer.Clear();
await this.PublishMessageAsync(new GroupChatAgentResponse { AgentResponse = response }, this.parentTopic);
}
public ValueTask HandleAsync(GroupChatReset item, MessageContext messageContext)
{
this.MessageBuffer.Clear();
return this.agent.ResetAsync(messageContext.CancellationToken);
}
async ValueTask<JsonElement> ISaveState.SaveStateAsync()
{
ChatAgentContainerState state = new ChatAgentContainerState
{
AgentState = new SerializedState(await this.agent.SaveStateAsync()),View on GitHub (pinned to 027ecf0a37)
Solutions
- Fix the agent so its HandleAsync stream always ends with a ChatStreamFrame(FrameType.Response, response) before completion
- Check middleware around the agent for dropped frames, especially filters on frame type
- If early termination is intentional, still synthesize and emit a final Response frame (e.g. from the last partial message) before ending the stream
Example fix
// before (IChatAgent.HandleAsync stream) await foreach (var chunk in source) yield return ChunkFrame(chunk); // no Response frame // after await foreach (var chunk in source) yield return ChunkFrame(chunk); yield return ResponseFrame(new ChatMessageResponse(finalMessage, innerMessages));
Defensive patterns
Strategy: try-catch
Try / catch
try { await team.RunAsync(task, ct); }
catch (InvalidOperationException ex) when (ex.Message.Contains("did not produce a final response"))
{
// inspect the agent's HandleAsync stream: it ended without a Response frame; fix the agent or its middleware
} Prevention
- Every IChatAgent's HandleAsync stream must end with a Response frame, including on early termination
- Test each agent standalone (stream it directly) before adding it to a team
- Audit frame-filtering middleware so it never drops FrameType.Response
When it happens
Trigger: Running a group chat where the selected agent's streaming implementation completes without a Response frame — e.g. an agent that streams only text chunks and returns, max-turn/early-exit logic that skips the final frame, or a custom IChatAgent adapter that forgets to yield the response frame.
Common situations: Plugging third-party or hand-rolled IChatAgent implementations into a team; agents whose HandleAsync stream finishes on a termination keyword before emitting the final response; middleware that filters the response frame out of the stream.
Related errors
- The stream should have returned the final result.
- The recent update is not a TextMessage
- Only one choice is supported in streaming response
- unsupported message type, only support TextMessage, ImageMes
- MultiModalMessage is not supported in the semantic kernel if
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/acab0f295953a1b7.
Report an issue: GitHub.