Skip to content

Commit 6b5c371

Browse files
committed
Add a tool stub
1 parent b9ec7ac commit 6b5c371

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

samples-v2/openai_agents/tools.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
from agents import Tool
1+
from typing import Any, Callable
22

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+
)
317

4-
def activity_as_tool(activity_func) -> Tool:
18+
19+
def activity_as_tool(activity_func: Callable) -> Tool:
520
"""
621
Convert an Azure Durable Functions activity to an OpenAI Agents SDK Tool.
722
@@ -11,5 +26,25 @@ def activity_as_tool(activity_func) -> Tool:
1126
Returns:
1227
Tool: An OpenAI Agents SDK Tool object
1328
"""
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

Comments
 (0)