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

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Sep 13, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Sep 14, 2026
  3. github-actions commented on Sep 14, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    The defect reproduces in python/packages/core/agent_framework/_workflows/_typing_utils.py::is_instance_of at line 223 when target_type is Literal[...]; its origin reaches isinstance(data, Literal) and raises TypeError. Executor.can_handle() and _find_handler() trigger this during handler routing. Minimal repro: assert is_instance_of("a", Literal["a", "b"]) under Python 3.12.

    • Failing test: python/packages/core/tests/workflow/test_typing_utils.py::test_literal_types
    • Files examined: python/packages/core/agent_framework/_workflows/_typing_utils.py, python/packages/core/agent_framework/_workflows/_executor.py, python/packages/core/tests/workflow/test_typing_utils.py, python/packages/core/pyproject.toml
    • Tests run: test_typing_utils.py (65 passed baseline), test_literal_types on Python 3.12.3 and 3.13.15 (failed)
    • Current version: 1.18.0
  4. added
    workflowsUsage: [Issues, PRs], Target: Workflows
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Sep 14, 2026
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