Skip to content

Python: [Bug]: Executor type checking fails when using __future__ annotations in Python 3.12 #1

Open

Description

@moonbox3

Description

When using from __future__ import annotations, type annotations are stored as strings. Type checking in _executor.py will get a str not a class object. This is passed to _workflow_context.py, which uses typing.get_origin and returns None.

This was mentioned in microsoft#1808 and fixed in microsoft#2308 for FunctionExecutor not the regular Executor. That fix uses typing.get_type_hints before the call to validate_workflow_context_annotation.

Code Sample

from __future__ import annotations

from pydantic import BaseModel

from agent_framework import Executor, WorkflowContext, handler

class MyTypeA(BaseModel):
    pass
class MyTypeB(BaseModel):
    pass

class MyExecutor(Executor):
    @handler
    async def example(self, input: str, ctx: WorkflowContext[MyTypeA, MyTypeB]) -> None:
        pass

Error Messages / Stack Traces

/usr/bin/python3.12 /IdeaProjects/problem.py 
Traceback (most recent call last):
  File "/IdeaProjects/problem.py", line 12, in <module>
    class MyExecutor(Executor):
  File "/IdeaProjects/problem.py", line 13, in MyExecutor
    @handler
     ^^^^^^^
  File "/home/ubuntu/.local/lib/python3.12/site-packages/agent_framework/_workflows/_executor.py", line 584, in handler
    return decorator(func)
           ^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/lib/python3.12/site-packages/agent_framework/_workflows/_executor.py", line 558, in decorator
    _validate_handler_signature(func)
  File "/home/ubuntu/.local/lib/python3.12/site-packages/agent_framework/_workflows/_executor.py", line 619, in _validate_handler_signature
    output_types, workflow_output_types = validate_workflow_context_annotation(
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/.local/lib/python3.12/site-packages/agent_framework/_workflows/_workflow_context.py", line 154, in validate_workflow_context_annotation
    raise ValueError(
ValueError: Handler parameter 'ctx' must be annotated as WorkflowContext, WorkflowContext[T], or WorkflowContext[T, U], got WorkflowContext[MyTypeA, MyTypeB]

Process finished with exit code 1

Package Versions

agent-framework: 1.0.0b260128

Python Version

Python 3.12

Additional Context

No response

Activity

  1. added 14 commits that reference this issue on Feb 15, 2026
    290db40
    918a87c
    3bce9d0
    e14044f
    b16ed0b
    55a8ad5
    84d93b8
    7843f0d
    299f3d8
    707b14f
    2f1f1e1
    f2daff1
    7d6f6f9
    f017d14
  2. 40 remaining items

  3. added 10 commits that reference this issue on Feb 23, 2026
    4777248
    659c4d3
    9b31c2e
    f29056f
    9cc20ac
    aa284f1
    79b4339
    5827645
    66d8d3f
    d38bcc6
  4. added a commit that references this issue on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions