Skip to content

Python: Literal handler annotations crash workflows at delivery (is_instance_of has no Literal case) #8350

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

pythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowworkflowsUsage: [Issues, PRs], Target: Workflows

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions