fix(deep_research): resolve DeepResearchAgent returning None (fixes #1770)#2487
fix(deep_research): resolve DeepResearchAgent returning None (fixes #1770)#2487aviraldua93 wants to merge 2 commits intoag2ai:mainfrom
Conversation
|
|
d18c2e2 to
59e07f0
Compare
amabito
left a comment
There was a problem hiding this comment.
deep_research.py:83-88 — list-type content silently skipped
isinstance(content, str) skips non-string content without a trace. Multimodal content would be a quiet no-op here — maybe a logger.debug on the else branch?
deep_research.py:135-142 — silent_override=True not explained
Four silent_override=True additions aren't in the PR description. Suppressing intermediate tool output? Curious how this connects to the None fix — or is it a separate cleanup?
When DeepResearchTool's inner initiate_chat() calls terminate via tool execution (confirm_summary, generate_subquestions, confirm_answer), the default _last_msg_as_summary extracts content from the last sender->recipient message, which is a tool_call with content=None. This causes result.summary to return an empty string, making the DeepResearchAgent return None to the user. Add _extract_last_result_with_prefix() static method that walks chat_result.chat_history in reverse to find the actual answer message by its expected prefix, falling back to result.summary when no match is found. Replace all 3 bare return result.summary calls with this helper. Changes: - Add _extract_last_result_with_prefix() helper with logger.debug for list-type content (multimodal messages) - Harden fallback with 'or empty string' to match str return type - Restore original register_for_llm/register_for_execution calls (no silent_override changes) Includes 6 unit tests covering: prefix extraction, multiple matches, fallback to summary, None content handling, empty history, and None summary fallback. Fixes ag2ai#1770 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
59e07f0 to
29c563c
Compare
Thanks @amabito Thanks for the careful review — both points are valid. silent_override=True: You're right to call this out — it was unrelated to the None fix and shouldn't have been in this PR. Removed all 4 instances; the List-type content: The three tool functions (confirm_summary, confirm_answer, generate_subquestions) all explicitly return str, so list content won't Updated in 29c563c. Thanks again for the feedback! |
Fix DeepResearchAgent returning None
Fixes #1770
Problem
DeepResearchAgentreturnsNoneinstead of the researched answer. The root cause is inDeepResearchTool, which uses three nestedinitiate_chat()calls that terminate via tool execution (confirm_summary,generate_subquestions,confirm_answer).When a chat terminates via tool call, the default
_last_msg_as_summarymethod extractscontentfrom the last sender→recipient message — but that message is atool_callsmessage withcontent=None. This causesresult.summaryto return""for all three inner chats, propagating up asNone.Root Cause Trace
delegate_research_task()→critic_agent.initiate_chat(summarizer_agent, ...)— terminates whenconfirm_summarytool is called_last_msg_as_summary()(conversable_agent.py L2159) →recipient.last_message(sender)["content"]→None(tool_call message)result.summary→""→ returned up the chain →DeepResearchAgentreturnsNoneSame pattern affects all 3 inner chats:
confirm_summary,generate_subquestions, andconfirm_answer.Fix
Added
_extract_last_result_with_prefix()static method toDeepResearchToolthat:chat_result.chat_historyin reversecontentstarts with the expected prefix (e.g.,"Answer confirmed:","Subquestions answered:","Subquestions generated:")result.summaryif no match is foundReplaced all 3 bare
return result.summarycalls with this helper, passing the appropriate prefix for each chat stage.Tests
Added 5 unit tests in
TestExtractLastResultWithPrefix:Nonecontent gracefully (no crash)All tests pass without requiring API keys or optional dependencies.
Changes
autogen/tools/experimental/deep_research/deep_research.py— Added helper method + replaced 3 return statementstest/tools/experimental/deep_research/test_deep_research.py— Added 5 regression tests