{"record":{"id":"09011383cd5ab652","repo":"microsoft/autogen","slug":"invalid-arguments","errorCode":null,"errorMessage":"Invalid arguments","messagePattern":"Invalid arguments","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_routed_agent.py","lineNumber":172,"sourceCode":"                else:\n                    logger.warning(f\"Return type {type(return_value)} not in return types {return_types}\")\n\n            return return_value\n\n        wrapper_handler = cast(MessageHandler[AgentT, ReceivesT, ProducesT], wrapper)\n        wrapper_handler.target_types = list(target_types)\n        wrapper_handler.produces_types = list(return_types)\n        wrapper_handler.is_message_handler = True\n        wrapper_handler.router = match or (lambda _message, _ctx: True)\n\n        return wrapper_handler\n\n    if func is None and not callable(func):\n        return decorator\n    elif callable(func):\n        return decorator(func)\n    else:\n        raise ValueError(\"Invalid arguments\")\n\n\n@overload\ndef event(\n    func: Callable[[AgentT, ReceivesT, MessageContext], Coroutine[Any, Any, None]],\n) -> MessageHandler[AgentT, ReceivesT, None]: ...\n\n\n@overload\ndef event(\n    func: None = None,\n    *,\n    match: None = ...,\n    strict: bool = ...,\n) -> Callable[\n    [Callable[[AgentT, ReceivesT, MessageContext], Coroutine[Any, Any, None]]],\n    MessageHandler[AgentT, ReceivesT, None],\n]: ...","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_routed_agent.py#L154-L190","documentation":"The @message_handler entry function dispatches on how it was invoked: bare decorator usage (callable func), parenthesized usage with keyword options (func is None), or something else. If a non-callable, non-None value is passed (or a malformed combination), ValueError('Invalid arguments') is raised. This is a usage error in decorator application, not in handler logic.","triggerScenarios":"Calling message_handler(some_object) where some_object is not callable, e.g. message_handler(True), message_handler('handler'), or accidentally passing the result of calling the handler; also reachable via exotic double-application like @message_handler()(func) patterns with wrong arity.","commonSituations":"Typo such as @message_handler(strict) passing the boolean as a positional argument instead of strict=True; programmatically applying decorators via functools.partial or loops and passing the wrong value; copy-paste from a parenthesized example dropping the '='.","solutions":["Use the decorator correctly: @message_handler above the method, or @message_handler(strict=False, match=...) with keyword arguments","Never pass positional arguments other than the decorated function itself","If applying decorators dynamically, pass the function object: handler = message_handler(strict=True)(func)"],"exampleFix":"# before\n@message_handler(True)\nasync def handle(self, message: Msg, ctx: MessageContext) -> None: ...\n\n# after\n@message_handler(strict=True)\nasync def handle(self, message: Msg, ctx: MessageContext) -> None: ...","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the two sanctioned forms only: @message_handler or @message_handler(keyword=...)","Never pass positional arguments to these decorators besides the implicit function","Smoke-test agent modules in CI so decorator misuse fails the build, not production"],"tags":["python","decorator","api-misuse","autogen-core"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}