1515"""Temporal integration helpers for ADK."""
1616
1717import functools
18+ import inspect
1819from typing import Any , AsyncGenerator , Callable , Optional , List
1920
2021from temporalio import workflow , activity
@@ -39,17 +40,21 @@ def activity_as_tool(
3940
4041 # We create a wrapper that delegates to workflow.execute_activity
4142 async def tool_wrapper (* args , ** kwargs ) -> Any :
42- # Note: ADK tools usually pass args/kwargs strictly matched to signature.
43- # Activities expect positional args in a list if 'args' is used.
44- # If the tool signature matches the activity signature, we can pass args.
45- # It's safer if activity takes Pydantic models or simple types.
46-
47- # We assume strict positional argument mapping for now, or simplistic kwargs handling if supported.
48- # Temporal Python SDK typically invokes activities with `args=[...]`.
49-
43+ # Bind arguments to the activity signature to ensure correct order/mapping.
44+ try :
45+ sig = inspect .signature (activity_def )
46+ bound_args = sig .bind (* args , ** kwargs )
47+ bound_args .apply_defaults ()
48+ activity_args = [bound_args .arguments [p ] for p in sig .parameters ]
49+ except (TypeError , ValueError ):
50+ # Fallback for built-ins or other complex callables where binding may fail
51+ # or if arguments don't match signature (e.g. simpler invocation).
52+ # Temporal Python SDK typically invokes activities with `args=[...]`.
53+ activity_args = list (args ) + list (kwargs .values ()) if kwargs else list (args )
54+
5055 return await workflow .execute_activity (
5156 activity_def ,
52- args = list ( args ) + list ( kwargs . values ()) if kwargs else list ( args ) ,
57+ args = activity_args ,
5358 ** activity_options
5459 )
5560
@@ -64,7 +69,6 @@ async def tool_wrapper(*args, **kwargs) -> Any:
6469
6570 # CRITICAL: Copy signature so FunctionTool can generate correct parameters schema
6671 try :
67- import inspect
6872 tool_wrapper .__signature__ = inspect .signature (activity_def )
6973 except Exception :
7074 pass # Fallback if signature copy fails (e.g. builtins)
0 commit comments