microsoft/autogen · error · ValueError
Invalid arguments
Error message
Invalid arguments
What it means
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.
Source
Thrown at python/packages/autogen-core/src/autogen_core/_routed_agent.py:172
else:
logger.warning(f"Return type {type(return_value)} not in return types {return_types}")
return return_value
wrapper_handler = cast(MessageHandler[AgentT, ReceivesT, ProducesT], wrapper)
wrapper_handler.target_types = list(target_types)
wrapper_handler.produces_types = list(return_types)
wrapper_handler.is_message_handler = True
wrapper_handler.router = match or (lambda _message, _ctx: True)
return wrapper_handler
if func is None and not callable(func):
return decorator
elif callable(func):
return decorator(func)
else:
raise ValueError("Invalid arguments")
@overload
def event(
func: Callable[[AgentT, ReceivesT, MessageContext], Coroutine[Any, Any, None]],
) -> MessageHandler[AgentT, ReceivesT, None]: ...
@overload
def event(
func: None = None,
*,
match: None = ...,
strict: bool = ...,
) -> Callable[
[Callable[[AgentT, ReceivesT, MessageContext], Coroutine[Any, Any, None]]],
MessageHandler[AgentT, ReceivesT, None],
]: ...View on GitHub (pinned to 027ecf0a37)
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)
Example fix
# before @message_handler(True) async def handle(self, message: Msg, ctx: MessageContext) -> None: ... # after @message_handler(strict=True) async def handle(self, message: Msg, ctx: MessageContext) -> None: ...
Defensive patterns
Strategy: validation
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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 '='.
Related errors
- Message type not found
- Return type not found
- Message type not found. Please provide a type hint for the m
- Return type not found. Please use `None` as the type hint of
- SubscriptionInstantiationContext cannot be instantiated. It
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/09011383cd5ab652.
Report an issue: GitHub.