Repository navigation
Python: fix(core): accept Literal source types in the workflow edge type check - #9355
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoOct 15, 2026
Conversation
Md. Shalah Uddin (shanto462)
requested review from
SergeyMenshykh,
Tao Chen (TaoChenOSU),
Eduard van Valkenburg (eavanvalkenburg),
Giles Odigwe (giles17),
Jose Alvarez (jpalvarezl),
Evan Mattson (moonbox3),
Roger Barreto (rogerbarreto),
sophia-ramsey and
westey (westey-m)
as code owners
October 13, 2026 17:44
Md. Shalah Uddin (shanto462)
deployed
to
github-app-auth
October 13, 2026 17:44 — with
GitHub Actions
Active
Md. Shalah Uddin (shanto462)
deployed
to
github-app-auth
October 13, 2026 17:44 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟢 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
Literalvalue-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.
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Oct 15, 2026
Md. Shalah Uddin (shanto462)
deleted the
fix-workflow-literal-edge-type
branch
October 19, 2026 09:42
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
is_type_compatiblehad no case for aLiteralsource type. Its origin,typing.Literal, is not a class, so the check fell through to "different container types" and returnedFalse. Edge validation then rejected a workflow where an executor sendsLiteral["approve", "reject"]to an executor that handlesstr, even though the runtime checkis_instance_ofalready accepts these messages (#8351).Description & Review Guide
is_type_compatible, before the union handling: aLiteralsource is compatible when every literal value fits the target, or one of its union members. ALiteralmember is checked by value withis_instance_of(same type and value, soTruedoes not matchLiteral[1], as at runtime); any other member is checked withis_type_compatible(type(value), member), exactly how a plainstrorintsource is checked today. Tests coverLiteraltostr,intandbytes, mixed literals to a union,Literal[None]toOptional[str], a literal subset,Optional[Literal[...]], a union with aNewTypemember, an enum literal,list[Literal[...]], the rejected cases (includingNewTypeandTypeVartargets), and a workflow that connects aLiteralsender to astrhandler.Literaltypes to executors handling the literal values' type now build.strto aLiteraltarget is still rejected, and other type pairs are unchanged.Literal["a", 1]againststr | int, where no single union member accepts the whole literal. Non-Literaltargets go throughis_type_compatiblerather thanisinstance, so targets such as aNewType, aTypeVaror a non-runtimeProtocolreturnFalseinstead of raising duringbuild(). One small change forLiteralsources:Literal[True]againstLiteral[1]now returnsFalse(it wasTruethrough==), matching the runtime check.Related Issue
Fixes #9354
No other open PR covers this issue.
AI Assistance
AI assistance details: issue analysis, implementation, tests, and this PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.