Skip to content

Python: [Bug]: @response_handler fails with postponed annotations #8327

Description

@CoralGarden52

Description

The introspection mode of @response_handler reads raw values from inspect.signature(func). When a module uses from __future__ import annotations, valid request, response, and WorkflowContext[...] annotations are stored as strings, but the response-handler validation path does not resolve them before validating the context annotation.

This causes a valid executor definition to fail while the class body is being evaluated, so the executor cannot be imported or instantiated.

Reproduction

from __future__ import annotations

from agent_framework import Executor, WorkflowContext, handler, response_handler

class FutureAnnotationsExecutor(Executor):
    @handler
    async def handle(self, message: str, ctx: WorkflowContext) -> None:
        pass

    @response_handler
    async def handle_response(
        self, original_request: str, response: int, ctx: WorkflowContext[str]
    ) -> None:
        pass

On the current upstream main, defining the class raises:

ValueError: Response handler parameter 'ctx' must be annotated as WorkflowContext, WorkflowContext[T], or WorkflowContext[T, U], got WorkflowContext[str]

Expected behavior

The introspection path should resolve postponed annotations in the same way as the existing @handler path, then register the response handler with str as the request type, int as the response type, and str as the workflow output type.

Scope

This affects introspection mode only. Explicit @response_handler(request=..., response=...) parameters already resolve string references and should remain unchanged.

The corresponding @handler future-annotation behavior is covered by test_executor_future.py (issue #3898); this issue tracks the missing response-handler counterpart.

Activity

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