Skip to content

Python: fix(workflows): support keyword-only RunContext in functional workflows - #9397

Open
Nithin (nithin42) wants to merge 1 commit into
microsoft:mainfrom
nithin42:fix/functional-workflow-keyword-only-context
Open

Nithin (nithin42) wants to merge 1 commit into
microsoft:mainfrom
nithin42:fix/functional-workflow-keyword-only-context

Conversation

@nithin42

Copy link
Copy Markdown

Summary

Fixes #9324.

Resolves an issue where defining a @workflow with a keyword-only RunContext parameter (e.g. async def wf(text: str, *, ctx: RunContext) -> str:) succeeded at decoration time but failed during execution with:

TypeError: wf() takes 1 positional argument but 2 were given

Copilot AI balanced review requested due to automatic review settings October 14, 2026 19:11
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Oct 14, 2026
@github-actions github-actions Bot changed the title fix(workflows): support keyword-only RunContext in functional workflows Python: fix(workflows): support keyword-only RunContext in functional workflows Oct 14, 2026

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 binding fix preserves positional behavior, includes regression coverage, and has no identified blocking issues.

0 open findings

What changed in this PR

Fixes #9324 by respecting keyword-only parameters when invoking functional workflows, while preserving positional argument handling.

Changes:

  • Pass keyword-only context and input parameters by name.
  • Add regression tests for annotated and unannotated context parameters, keyword-only inputs, and streaming.
File Description
python/​packages/​core/​tests/​workflow/​test_functional_workflow.py Adds keyword-only parameter regression tests.
python/​packages/​core/​agent_framework/​_workflows/​_functional.py Injects keyword-only arguments through keyword bindings.

🧠 Review effort: Balanced


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

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.

Reviewed 8d8806dab43bbc71b13537c59533aab25a177131. I found no correctness blocker in the argument-binding change: keyword-only values are passed by name, while positional-only and ordinary positional parameters keep their existing ordering. Both streaming and non-streaming runs reach the same _execute path.

Offline validation on macOS arm64 / CPython 3.14.7:

  • All 159 tests in python/packages/core/tests/workflow/test_functional_workflow.py passed.
  • Replacing only _execute in memory with the parent commit's implementation made all four new regression tests fail with the expected positional-argument TypeError; all four pass with this head.
  • An additional 20-case harness passed: eight input/context signature arrangements in both streaming modes, plus four HITL resume cases covering response-only continuation and checkpoint restore into a newly built workflow. The resume cases used an explicit replay key and verified that a completed step ran only once.

Non-blocking coverage suggestion: keep a test for an annotated context named something other than ctx, such as async def wf(text: str, *, context: RunContext), and one keyword-only-context HITL checkpoint-resume test. These worked in the additional harness, but the committed tests currently exercise the ctx name fallback and state access only.

I checked the existing review and inline comments before this review. Validation used cached dependencies and local source; I did not run the full workspace suite, type checks, other Python versions, or service integration tests. The issue-first maintainer agreement for #9324 remains a separate prerequisite for the maintainers to resolve.

@nithin42
Nithin (nithin42) force-pushed the fix/functional-workflow-keyword-only-context branch from 8d8806d to d134b43 Compare October 19, 2026 14:47
@nithin42

Copy link
Copy Markdown
Author

Thanks for testing this so thoroughly Bicheng (Kenneth) (@BichengWang)! Really appreciate the feedback. I'll wait to hear what the maintainers think and will happily add those extra tests if they'd like them.

This branch was successfully deployed

1 active deployment
github-app-auth — d134b433 Deployed Oct 19, 2026 by nithin42 via add_label #25749
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]: Functional workflow injects a keyword-only RunContext positionally

3 participants