Skip to content

fix(core): accept async-callable instances in Flow, Action, background models and run_in_new_span - #144

Closed
kcncb wants to merge 1 commit into
genkit-ai:mainfrom
kcncb:fix/accept-async-callable-instances
Closed

kcncb wants to merge 1 commit into
genkit-ai:mainfrom
kcncb:fix/accept-async-callable-instances

Conversation

@kcncb

@kcncb kcncb commented Nov 18, 2026

Copy link
Copy Markdown

Fixes #124.

Problem

Tool.__init__ already accepted a callable instance with async def __call__ (inspect.iscoroutinefunction(type(func).__call__)), but the other core entry points only checked inspect.iscoroutinefunction(...). The same object was therefore a valid tool and rejected everywhere else:

  • Flow.__init__
  • Action.__init__
  • _background._operation_action
  • run_in_new_span

Change

New genkit/_core/_async_call.py holds the one definition:

def is_async_callable(func: object) -> bool:
    return inspect.iscoroutinefunction(func) or inspect.iscoroutinefunction(type(func).__call__)

All four sites call it. Error messages are unchanged, so existing expectations keep matching exactly.

Flow also names an instance after its class when the handler has no __name__, instead of the generic unnamed_flow — a flow built from an Echo() instance registers as Echo. Functions are unaffected (they have __name__).

Tests

packages/genkit/tests/genkit/core/async_callable_test.py: an async def __call__ instance is built and executed through Action, Flow and run_in_new_span; a sync __call__ still raises the existing TypeErrors.

$ uv run --frozen pytest packages/genkit/tests/genkit/core/async_callable_test.py -q -o addopts=""
5 passed

# four call sites reverted, tests kept
3 failed, 2 passed      # action / flow / span instance cases

$ uv run --frozen pytest packages/genkit/tests/genkit/core -q -o addopts=""
966 passed, 2 skipped

$ uv run --frozen ruff check … && ruff format --check …
All checks passed! / 37 files already formatted

@huangjeff5

Copy link
Copy Markdown
Collaborator

Thanks for your interest in Genkit. We're closing this pull request because we can't accept it in its current form. If you'd like to contribute, please start a discussion with the maintainers on an issue first; see CONTRIBUTING.md.

@huangjeff5 huangjeff5 closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): accept async-callable instances consistently across Flow, Action, background models, and run_in_new_span

2 participants