Skip to content

Commit cc6f52a

Browse files
committed
feat: implement OpenAI Agents SDK tool conversion
Add to_openai_agents() method to StackOneTool class for converting tools to OpenAI Agents SDK format Add to_openai_agents() method to Tools class for batch conversion Implements async wrapper with function_tool decorator for compatibility Include documentation links to https://openai.github.io/openai-agents-python/
1 parent 3231bb0 commit cc6f52a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

stackone_ai/models.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Annotated, Any, TypeAlias, cast
88

99
import requests
10+
from agents import function_tool
1011
from langchain_core.tools import BaseTool
1112
from pydantic import BaseModel, BeforeValidator, Field, PrivateAttr
1213
from requests.exceptions import RequestException
@@ -397,6 +398,28 @@ async def _arun(self, **kwargs: Any) -> Any:
397398

398399
return StackOneLangChainTool()
399400

401+
def to_openai_agents(self) -> Any:
402+
"""Convert this tool to OpenAI Agents SDK format
403+
404+
The OpenAI Agents SDK enables building agentic AI apps with lightweight abstractions.
405+
See: https://openai.github.io/openai-agents-python/
406+
407+
Returns:
408+
Function tool compatible with OpenAI Agents SDK
409+
"""
410+
parent_tool = self
411+
412+
async def openai_agents_wrapper(**kwargs: Any) -> JsonDict:
413+
"""Async wrapper for the tool execution compatible with OpenAI Agents SDK"""
414+
return await parent_tool.acall(kwargs)
415+
416+
# Use the function_tool decorator to create an OpenAI Agents compatible tool
417+
return function_tool(
418+
openai_agents_wrapper,
419+
name_override=self.name,
420+
description_override=self.description,
421+
)
422+
400423
def set_account_id(self, account_id: str | None) -> None:
401424
"""Set the account ID for this tool
402425
@@ -480,6 +503,17 @@ def to_langchain(self) -> Sequence[BaseTool]:
480503
"""
481504
return [tool.to_langchain() for tool in self.tools]
482505

506+
def to_openai_agents(self) -> list[Any]:
507+
"""Convert all tools to OpenAI Agents SDK format
508+
509+
The OpenAI Agents SDK enables building agentic AI apps with lightweight abstractions.
510+
See: https://openai.github.io/openai-agents-python/
511+
512+
Returns:
513+
List of function tools compatible with OpenAI Agents SDK
514+
"""
515+
return [tool.to_openai_agents() for tool in self.tools]
516+
483517
def meta_tools(self) -> "Tools":
484518
"""Return meta tools for tool discovery and execution
485519

0 commit comments

Comments
 (0)