1212# limitations under the License.
1313# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414
15+ import asyncio
1516import os
1617from typing import TYPE_CHECKING , Dict , List , Optional , Union
1718
@@ -408,6 +409,38 @@ def execute_function(
408409 )
409410 return result
410411
412+ async def aexecute_function (
413+ self ,
414+ function_name : str ,
415+ function_arguments : Dict ,
416+ linked_account_owner_id : str ,
417+ allowed_apps_only : bool = False ,
418+ ) -> Dict :
419+ r"""Execute a function call asynchronously.
420+
421+ Args:
422+ function_name (str): Name of the function to execute.
423+ function_arguments (Dict): Arguments to pass to the function.
424+ linked_account_owner_id (str): To specify the end-user (account
425+ owner) on behalf of whom you want to execute functions
426+ You need to first link corresponding account with the same
427+ owner id in the ACI dashboard (https://platform.aci.dev).
428+ allowed_apps_only (bool): If true, only returns functions/apps
429+ that are allowed to be used by the agent/accessor, identified
430+ by the api key. (default: :obj:`False`)
431+
432+ Returns:
433+ Dict: Result of the function execution
434+ """
435+ result = await asyncio .to_thread (
436+ self .client .handle_function_call ,
437+ function_name ,
438+ function_arguments ,
439+ linked_account_owner_id ,
440+ allowed_apps_only ,
441+ )
442+ return result
443+
411444 def get_tools (self ) -> List [FunctionTool ]:
412445 r"""Get a list of tools (functions) available in the configured apps.
413446
@@ -434,6 +467,8 @@ def get_tools(self) -> List[FunctionTool]:
434467 FunctionTool (self .delete_linked_account ),
435468 FunctionTool (self .function_definition ),
436469 FunctionTool (self .search_function ),
470+ FunctionTool (self .execute_function ),
471+ FunctionTool (self .aexecute_function ),
437472 ]
438473
439474 for function in _all_function :
@@ -448,6 +483,16 @@ def dummy_func(*, schema=schema, **kwargs):
448483 linked_account_owner_id = self .linked_account_owner_id ,
449484 )
450485
486+ async def async_dummy_func (* , schema = schema , ** kwargs ):
487+ return await self .aexecute_function (
488+ function_name = schema ['function' ]['name' ],
489+ function_arguments = kwargs ,
490+ linked_account_owner_id = self .linked_account_owner_id ,
491+ )
492+
493+ # Add async_call method to the sync function for compatibility
494+ dummy_func .async_call = async_dummy_func # type: ignore[attr-defined]
495+
451496 tool = FunctionTool (
452497 func = dummy_func ,
453498 openai_tool_schema = schema ,
0 commit comments