Skip to content

Python: fix(core): accept Literal source types in the workflow edge type check - #9355

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
shanto462:fix-workflow-literal-edge-type
Oct 15, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
shanto462:fix-workflow-literal-edge-type

Conversation

@shanto462

Copy link
Copy Markdown
Contributor

Motivation & Context

is_type_compatible had no case for a Literal source type. Its origin, typing.Literal, is not a class, so the check fell through to "different container types" and returned False. Edge validation then rejected a workflow where an executor sends Literal["approve", "reject"] to an executor that handles str, even though the runtime check is_instance_of already accepts these messages (#8351).

Description & Review Guide

  • What are the major changes? A new case in is_type_compatible, before the union handling: a Literal source is compatible when every literal value fits the target, or one of its union members. A Literal member is checked by value with is_instance_of (same type and value, so True does not match Literal[1], as at runtime); any other member is checked with is_type_compatible(type(value), member), exactly how a plain str or int source is checked today. Tests cover Literal to str, int and bytes, mixed literals to a union, Literal[None] to Optional[str], a literal subset, Optional[Literal[...]], a union with a NewType member, an enum literal, list[Literal[...]], the rejected cases (including NewType and TypeVar targets), and a workflow that connects a Literal sender to a str handler.
  • What is the impact of these changes? Workflows whose executors send Literal types to executors handling the literal values' type now build. str to a Literal target is still rejected, and other type pairs are unchanged.
  • What do you want reviewers to focus on? The check runs before the union cases on purpose: checking each literal value on its own handles a mixed literal such as Literal["a", 1] against str | int, where no single union member accepts the whole literal. Non-Literal targets go through is_type_compatible rather than isinstance, so targets such as a NewType, a TypeVar or a non-runtime Protocol return False instead of raising during build(). One small change for Literal sources: Literal[True] against Literal[1] now returns False (it was True through ==), matching the runtime check.

Related Issue

Fixes #9354

No other open PR covers this issue.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: issue analysis, implementation, tests, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused implementation matches runtime semantics and is comprehensively covered by regression tests.

0 open findings

What changed in this PR

Adds Literal source-type support to workflow edge compatibility validation.

Changes:

  • Validates each literal value against target types and union members.
  • Preserves strict Literal value-type matching.
  • Adds utility and workflow regression tests.
File Description
python/​packages/​core/​agent_framework/​_workflows/​_typing_utils.py Implements Literal source compatibility.
python/​packages/​core/​tests/​workflow/​test_typing_utils.py Covers compatible and rejected type combinations.
python/​packages/​core/​tests/​workflow/​test_validation.py Verifies workflow construction with a Literal sender.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Merged via the queue into microsoft:main with commit 8396734 Oct 15, 2026
50 checks passed
@shanto462
Md. Shalah Uddin (shanto462) deleted the fix-workflow-literal-edge-type branch October 19, 2026 09:42

This branch was successfully deployed

1 active deployment
github-app-auth — b66cd368 Deployed Oct 13, 2026 by shanto462 via team_check #6712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Workflow build rejects an edge from an executor that sends a Literal type to one that handles str

3 participants