1
- from agents import Tool
1
+ from typing import Any , Callable
2
2
3
+ from agents import (
4
+ Agent ,
5
+ RunContextWrapper ,
6
+ Tool ,
7
+ )
8
+ from agents .function_schema import DocstringStyle , function_schema
9
+ from agents .tool import (
10
+ FunctionTool ,
11
+ ToolErrorFunction ,
12
+ ToolFunction ,
13
+ ToolParams ,
14
+ default_tool_error_function ,
15
+ function_tool ,
16
+ )
3
17
4
- def activity_as_tool (activity_func ) -> Tool :
18
+
19
+ def activity_as_tool (activity_func : Callable ) -> Tool :
5
20
"""
6
21
Convert an Azure Durable Functions activity to an OpenAI Agents SDK Tool.
7
22
@@ -11,5 +26,25 @@ def activity_as_tool(activity_func) -> Tool:
11
26
Returns:
12
27
Tool: An OpenAI Agents SDK Tool object
13
28
"""
14
- # TODO: Implement the conversion logic
15
- raise NotImplementedError ("activity_as_tool is not yet implemented" )
29
+
30
+ async def run_activity (ctx : RunContextWrapper [Any ], input : str ) -> Any :
31
+ return "Weather in Tokyo: 14-20C, sunny with wind."
32
+
33
+ activity_name = activity_func ._function ._name
34
+
35
+ schema = function_schema (
36
+ func = run_activity ,
37
+ name_override = activity_name ,
38
+ docstring_style = None ,
39
+ description_override = None ,
40
+ use_docstring_info = False ,
41
+ strict_json_schema = False ,
42
+ )
43
+
44
+ return FunctionTool (
45
+ name = activity_name ,
46
+ description = "" ,
47
+ params_json_schema = schema .params_json_schema ,
48
+ on_invoke_tool = run_activity ,
49
+ strict_json_schema = False ,
50
+ )
0 commit comments