Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make older functions compatible with tool calling #1605

Merged
merged 13 commits into from
Dec 20, 2024
1 change: 0 additions & 1 deletion cookbook/tools/composio_tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from phi.agent import Agent
from composio_phidata import Action, ComposioToolSet # type: ignore


toolset = ComposioToolSet()
composio_tools = toolset.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER])

Expand Down
13 changes: 10 additions & 3 deletions phi/tools/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Function(BaseModel):
# The parameters the functions accepts, described as a JSON Schema object.
# To describe a function that accepts no parameters, provide the value {"type": "object", "properties": {}}.
parameters: Dict[str, Any] = Field(
default_factory=lambda: {"type": "object", "properties": {}},
default_factory=lambda: {"type": "object", "properties": {}, "required": []},
description="JSON Schema object describing function parameters",
)
strict: Optional[bool] = None
Expand Down Expand Up @@ -139,6 +139,12 @@ def process_entrypoint(self, strict: bool = False):
return

parameters = {"type": "object", "properties": {}, "required": []}

params_set_by_user = False
# If the user set the parameters (i.e. they are different from the default), we should keep them
if self.parameters != parameters:
params_set_by_user = True

try:
sig = signature(self.entrypoint)
type_hints = get_type_hints(self.entrypoint)
Expand Down Expand Up @@ -174,8 +180,9 @@ def process_entrypoint(self, strict: bool = False):
except Exception as e:
logger.warning(f"Could not parse args for {self.name}: {e}", exc_info=True)

self.description = getdoc(self.entrypoint) or self.description
self.parameters = parameters
self.description = self.description or getdoc(self.entrypoint)
if not params_set_by_user:
self.parameters = parameters
self.entrypoint = validate_call(self.entrypoint)

def get_type_name(self, t: Type[T]):
Expand Down
Loading