fix: use functools.wraps in activity_tool to preserve __annotations__ and __module__#1636
Conversation
|
Thanks for the PR, happy to merge it in! Can you fix the lint and add a test? |
On it. ALso -- it'd be great if we can get some sort of default linter in some sort of precommit hook [ i tend to like lefthook ] at least to be able to easily opt into. Otherwise, I imagine this will continue to happen [ I forget things, but not if the machines make sure I do ]. I tend to make those things rather automatic for people. But, at least if there is an easy and persistent opt-in/enablement, that'd also be sufficient. |
5153958 to
982c26b
Compare
|
Thanks @brianstrauch! Done — force-pushed with both fixes:
|
|
Looks like changes to |
982c26b to
0f9ec2c
Compare
|
Fixed — force-pushed with the
|
Replace manual metadata copying with @functools.wraps(activity_def) to preserve __annotations__, __module__, __qualname__, and __dict__ on the wrapper function. These are needed by ADK's tool schema generation (specifically _handle_params_as_deferred_annotations) to resolve type hints from the original activity function. Also adds test_activity_tool_preserves_metadata verifying that __name__, __doc__, __annotations__, __module__, and __signature__ are all correctly preserved on the wrapper. Fixes temporalio#1635
6b8abb0 to
ce7e9b2
Compare
Summary
Replace manual metadata copying in
activity_tool()with@functools.wraps(activity_def)to fix missing__annotations__and__module__on the wrapper function.Problem
The
activity_tool()wrapper copies__name__,__doc__, and__signature__but misses__annotations__and__module__. ADK'sbuild_function_declaration()→_handle_params_as_deferred_annotations()reads the wrapper's__annotations__to resolve parameter types, but finds{'args': Any, 'kw': Any}instead of the original function's typed parameters, causing aKeyError.Fix
functools.wrapscopies__name__,__qualname__,__module__,__annotations__,__doc__,__dict__, and sets__wrapped__. The explicit__signature__override remains because the wrapper uses*args/**kw.Testing
Verified locally: wrapping a typed activity with
activity_tool()and using it as aLlmAgenttool now produces correct function declarations withoutKeyError.Fixes #1635