Skip to content

fix(core): accept async-callable instances consistently across handlers - #268

Open
huangjeff5 wants to merge 3 commits into
mainfrom
fix/async-callable-instances
Open

huangjeff5 wants to merge 3 commits into
mainfrom
fix/async-callable-instances

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Callable instances with async def __call__ now work across Flow, Action, BackgroundModel / BackgroundAction, Evaluator / BatchEvaluator, and run_in_new_span, matching Tool.

class OrderLookup:
    async def __call__(self, order_id: str) -> str:
        return f'order:{order_id}'

# before: TypeError: Flow must be async: <OrderLookup object at ...>
# after: registers as 'OrderLookup' and runs
flow = Flow(OrderLookup())
await flow.run('A-1042')
# => ActionResponse(response='order:A-1042', ...)

Changes

  • Added is_async_callable to genkit._core._action (next to signature_of and _annotation_target) and used it across Action, Flow, Tool, _background._operation_action, and Evaluator / BatchEvaluator; inlined the same check in run_in_new_span to avoid a telemetry-to-action import.
  • Flow now defaults an unnamed callable instance's name to type(func).__name__ instead of 'unnamed_flow'.
  • Added test cases covering async-callable instances (and sync-callable rejection) in action_test.py, background_registry_test.py, and run_in_new_span_test.py.

Breaking changes

None.

Fixes #124.

@huangjeff5
huangjeff5 requested a review from cabljac December 1, 2026 20:36

@genkit-bot genkit-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Details

Run 9b2ee393-05a3-4fc4-a919-30f4b6ba7093 · Cloud Run logs · Dashboard

# Conflicts:
#	packages/genkit/src/genkit/_ai/_evaluator.py

This branch has not been deployed

No deployments
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