feat: allow async functions as tools#1041
Merged
ajbozarth merged 1 commit intoMay 8, 2026
Merged
Conversation
Detect coroutine functions in MelleaTool.from_callable and wrap them through mellea's shared event loop so sync .run() callers receive the resolved value rather than an un-awaited coroutine. Add overloads on both from_callable and the @tool decorator so Callable[P, Awaitable[R]] narrows to MelleaTool[P, R]. Closes part of generative-computing#1032. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
This was referenced May 8, 2026
Contributor
Author
|
@jakelorocco When moving the MCP tool support over I tried moving it's asynchronous handling into MelleaTool, but realized that it didn't make sense to have I also opened #1043 as a follow up issue to replace this implementation with actual async tool calling |
9 tasks
jakelorocco
approved these changes
May 8, 2026
Merged
via the queue into
generative-computing:main
with commit May 8, 2026
e522fc7
11 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Misc PR
Type of PR
Description
Add async support to
MelleaTool.from_callable(and by extension the@tooldecorator) so any developer can register an async function as a tool.
from_callabledetectsinspect.iscoroutinefunction(func)and wraps thecoroutine through mellea's shared event loop (
_run_async_in_thread), sosync callers of
.run()receive the resolved value rather than anun-awaited coroutine.
@tooldecorator gets the same support for free (it delegates tofrom_callable).from_callableand@toolsoCallable[P, Awaitable[R]]narrows toMelleaTool[P, R], keepingstatic return types correct whether the wrapped function is sync or async.
Split out from a broader plan that also adds MCP tool support.
Testing
Added:
test/backends/test_mellea_tool.py— async wrap, schema parity with sync, exception propagation.test/backends/test_tool_decorator.py—@toolon async (edge case class).test/typing/check_tools.py— mypyassert_typeverification that the async overload narrows through.run().Attribution