Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: issubclass checking error in dependency_injection #1265

@qingyun-wu

Description

@qingyun-wu

Describe the bug

Got the following error when testing the deepresearch agent,

Traceback (most recent call last):
  File "/Users/qingyunwu/Documents/github/ag2ai/ag2/research.py", line 52, in <module>
    agent = DeepResearchAgent(
  File "/Users/qingyunwu/Documents/github/ag2ai/ag2/autogen/agents/experimental/deep_research/deep_research.py", line 44, in __init__
    self.tool = DeepResearchTool(
  File "/Users/qingyunwu/Documents/github/ag2ai/ag2/autogen/tools/experimental/deep_research/deep_research.py", line 157, in __init__
    super().__init__(
  File "/Users/qingyunwu/Documents/github/ag2ai/ag2/autogen/tools/tool.py", line 51, in __init__
    self._chat_context_param_names = get_context_params(func_or_tool, subclass=ChatContext)
  File "/Users/qingyunwu/Documents/github/ag2ai/ag2/autogen/tools/dependency_injection.py", line 116, in get_context_params
    return [p.name for p in sig.parameters.values() if _is_context_param(p, subclass=subclass)]
  File "/Users/qingyunwu/Documents/github/ag2ai/ag2/autogen/tools/dependency_injection.py", line 116, in <listcomp>
    return [p.name for p in sig.parameters.values() if _is_context_param(p, subclass=subclass)]
  File "/Users/qingyunwu/Documents/github/ag2ai/ag2/autogen/tools/dependency_injection.py", line 137, in _is_context_param
    return isinstance(param_annotation, type) and issubclass(param_annotation, subclass)
  File "/Users/qingyunwu/miniconda3/envs/ag2/lib/python3.10/abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

I hacked a workaround by replacing this line of code with the following, but not sure if this is the right approach.

if not isinstance(param.annotation, type):
        return False
        
try:
    result = issubclass(param, subclass)
    return result
except Exception as e:
    return False

Steps to reproduce

No response

Model Used

No response

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions