Description
is_instance_of() in agent_framework/_workflows/_typing_utils.py has no Literal case. Executor.can_handle() / _find_handler() call it directly on every message delivery, so a handler registered with a Literal message annotation (which @handler registration and the builder type validation both accept) crashes the workflow on first message:
TypeError: typing.Literal cannot be used with isinstance()
The sibling helper _matches_annotation() in the same file already implements the intended Literal semantics, so the two validators disagree.
Reproduction
from typing import Literal
from agent_framework._workflows._typing_utils import is_instance_of
Msg = Literal["a", "b"]
is_instance_of("a", Msg)
# TypeError: typing.Literal cannot be used with isinstance()
Any @handler with Literal["a","b"] message annotation hits this at delivery time.
Expected behavior
is_instance_of("a", Msg) is True / is_instance_of("c", Msg) is False, matching _matches_annotation(), so Literal-annotated handlers work end to end.
Environment
agent-framework python main, Python 3.12
Description
is_instance_of()inagent_framework/_workflows/_typing_utils.pyhas noLiteralcase.Executor.can_handle()/_find_handler()call it directly on every message delivery, so a handler registered with aLiteralmessage annotation (which@handlerregistration and the builder type validation both accept) crashes the workflow on first message:TypeError: typing.Literal cannot be used with isinstance()The sibling helper
_matches_annotation()in the same file already implements the intended Literal semantics, so the two validators disagree.Reproduction
Any
@handlerwithLiteral["a","b"]message annotation hits this at delivery time.Expected behavior
is_instance_of("a", Msg)is True /is_instance_of("c", Msg)is False, matching_matches_annotation(), so Literal-annotated handlers work end to end.Environment
agent-framework python main, Python 3.12