Skip to content

Commit

Permalink
Raise for missing return type on runtime action (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade authored Oct 15, 2024
1 parent 6f41d67 commit 457565f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/composio/tools/base/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _get_auth_params(app: str, entity_id: str) -> t.Optional[t.Dict]:
return None


def _build_executable_from_args(
def _build_executable_from_args( # pylint: disable=too-many-statements
f: t.Callable,
app: str,
) -> t.Tuple[t.Callable, t.Type[BaseModel], t.Type[BaseModel], bool,]:
Expand Down Expand Up @@ -291,6 +291,11 @@ def _build_executable_from_args(
}
shell_argument = None
auth_params = False
if "return" not in argspec.annotations:
raise InvalidRuntimeAction(
f"Please add return type on runtime action `{f.__name__}`"
)

for arg, annot in argspec.annotations.items():
if annot is Shell:
shell_argument = arg
Expand Down Expand Up @@ -323,7 +328,6 @@ def _build_executable_from_args(
description = paramdesc[arg]

default = defaults.get(arg, ...)

if arg == "return":
if returns is not None:
arg, _ = returns
Expand Down
16 changes: 16 additions & 0 deletions python/tests/test_tools/test_base/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ def square(number: int) -> int:
return number**2


def test_missing_return_type() -> None:
with pytest.raises(
InvalidRuntimeAction,
match="Please add return type on runtime action `square`",
):

@action(toolname="math")
def square(number: int):
"""
Calculate square of a number
:return result: Square of number
"""
return number**2


def test_tool_namespace() -> None:
"""Test to make sure two runtime actions can be defined using one tool name."""

Expand Down

0 comments on commit 457565f

Please sign in to comment.