autogen - 💡(How to fix) Fix PyAutoGen Reasoning Content [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
microsoft/autogen#7410Fetched 2026-04-08 00:49:31
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
commented ×1issue_type_added ×1labeled ×1

When using OpenAI-compatible APIs with reasoning models (gpt-5, o1), the Chat Completions API returns message.content as a list of content blocks, e.g.:

[
  {"type": "reasoning", "text": "..."},
  {"type": "text", "text": "actual response"}
]

OpenAIClient.message_retrieval returns this list unchanged. Downstream code in _generate_oai_reply_from_client uses extract_text_or_completion_object(response)[0], which yields the raw list. Callers expect a string or completion object, leading to empty or malformed responses.

Root Cause

When using OpenAI-compatible APIs with reasoning models (gpt-5, o1), the Chat Completions API returns message.content as a list of content blocks, e.g.:

[
  {"type": "reasoning", "text": "..."},
  {"type": "text", "text": "actual response"}
]

OpenAIClient.message_retrieval returns this list unchanged. Downstream code in _generate_oai_reply_from_client uses extract_text_or_completion_object(response)[0], which yields the raw list. Callers expect a string or completion object, leading to empty or malformed responses.

Code Example

[
  {"type": "reasoning", "text": "..."},
  {"type": "text", "text": "actual response"}
]
RAW_BUFFERClick to expand / collapse

What happened?

Upstream Issue: PyAutoGen Reasoning Content

Repository: https://github.com/microsoft/autogen

Title: OpenAIClient.message_retrieval does not handle list content from reasoning models (gpt-5, o1)


Body (copy below)

Description

When using OpenAI-compatible APIs with reasoning models (gpt-5, o1), the Chat Completions API returns message.content as a list of content blocks, e.g.:

[
  {"type": "reasoning", "text": "..."},
  {"type": "text", "text": "actual response"}
]

OpenAIClient.message_retrieval returns this list unchanged. Downstream code in _generate_oai_reply_from_client uses extract_text_or_completion_object(response)[0], which yields the raw list. Callers expect a string or completion object, leading to empty or malformed responses.

Environment

  • pyautogen 0.2.35
  • OpenAI API with gpt-5 deployment

Expected Behavior

message_retrieval should normalize list content to a string by extracting text from blocks with type == "text" (or "output_text").

Suggested Fix

In OpenAIClient.message_retrieval, when choice.message.content is a list, concatenate text from blocks with type in ("text", "output_text") and return that string instead of the raw list.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python dev (main branch)

Other library version.

pyautogen 0.2.35

Model used

gpt-5

Model provider

OpenAI

Other model provider

No response

Python version

3.11

.NET version

None

Operating system

None

extent analysis

Fix Plan

To fix the issue, we need to modify the OpenAIClient.message_retrieval method to handle list content from reasoning models. Here are the steps:

  • Check if choice.message.content is a list
  • If it's a list, iterate over the list and concatenate the text from blocks with type equal to "text" or "output_text"
  • Return the concatenated string instead of the raw list

Example Code

def message_retrieval(self, choice):
    content = choice.message.content
    if isinstance(content, list):
        text_content = [block["text"] for block in content if block["type"] in ("text", "output_text")]
        return "".join(text_content)
    return content

Verification

To verify the fix, you can test the OpenAIClient.message_retrieval method with a sample response from the OpenAI API that contains a list of content blocks. Check that the method returns a string with the concatenated text from the blocks with type equal to "text" or "output_text".

Extra Tips

  • Make sure to handle any potential errors that may occur when iterating over the list of content blocks, such as KeyError exceptions if a block is missing the "type" or "text" keys.
  • Consider adding a test case to ensure that the OpenAIClient.message_retrieval method handles list content correctly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING