Skip to content

Commit 4ae25bc

Browse files
lorenzejaymplachta
authored andcommitted
Enhance EnterpriseActionKitToolAdapter to support custom project IDs (crewAIInc#297)
* Enhance EnterpriseActionKitToolAdapter to support custom project IDs - Updated the EnterpriseActionKitToolAdapter and EnterpriseActionTool classes to accept an optional project_id parameter, allowing for greater flexibility in API interactions. - Modified API URL construction to utilize the provided project_id instead of a hardcoded default. - Updated the CrewaiEnterpriseTools factory function to accept and pass the project_id to the adapter. * for factory in mind
1 parent 3037207 commit 4ae25bc

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

crewai_tools/adapters/enterprise_adapter.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import json
55
from crewai.tools import BaseTool
66

7-
7+
# DEFAULTS
88
ENTERPRISE_ACTION_KIT_PROJECT_ID = "dd525517-df22-49d2-a69e-6a0eed211166"
9+
ENTERPRISE_ACTION_KIT_PROJECT_URL = "https://worker-actionkit.tools.crewai.com/projects"
910

1011

1112
class EnterpriseActionTool(BaseTool):
@@ -18,6 +19,12 @@ class EnterpriseActionTool(BaseTool):
1819
action_schema: Dict[str, Any] = Field(
1920
default={}, description="The schema of the action"
2021
)
22+
enterprise_action_kit_project_id: str = Field(
23+
default=ENTERPRISE_ACTION_KIT_PROJECT_ID, description="The project id"
24+
)
25+
enterprise_action_kit_project_url: str = Field(
26+
default=ENTERPRISE_ACTION_KIT_PROJECT_URL, description="The project url"
27+
)
2128

2229
def __init__(
2330
self,
@@ -26,6 +33,8 @@ def __init__(
2633
enterprise_action_token: str,
2734
action_name: str,
2835
action_schema: Dict[str, Any],
36+
enterprise_action_kit_project_url: str = ENTERPRISE_ACTION_KIT_PROJECT_URL,
37+
enterprise_action_kit_project_id: str = ENTERPRISE_ACTION_KIT_PROJECT_ID,
2938
):
3039
schema_props = (
3140
action_schema.get("function", {})
@@ -74,12 +83,17 @@ def __init__(
7483
self.action_name = action_name
7584
self.action_schema = action_schema
7685

86+
if enterprise_action_kit_project_id is not None:
87+
self.enterprise_action_kit_project_id = enterprise_action_kit_project_id
88+
if enterprise_action_kit_project_url is not None:
89+
self.enterprise_action_kit_project_url = enterprise_action_kit_project_url
90+
7791
def _run(self, **kwargs) -> str:
7892
"""Execute the specific enterprise action with validated parameters."""
7993
try:
8094
params = {k: v for k, v in kwargs.items() if v is not None}
8195

82-
api_url = f"https://worker-actionkit.tools.crewai.com/projects/{ENTERPRISE_ACTION_KIT_PROJECT_ID}/actions"
96+
api_url = f"{self.enterprise_action_kit_project_url}/{self.enterprise_action_kit_project_id}/actions"
8397
headers = {
8498
"Authorization": f"Bearer {self.enterprise_action_token}",
8599
"Content-Type": "application/json",
@@ -104,14 +118,21 @@ def _run(self, **kwargs) -> str:
104118
class EnterpriseActionKitToolAdapter:
105119
"""Adapter that creates BaseTool instances for enterprise actions."""
106120

107-
def __init__(self, enterprise_action_token: str):
121+
def __init__(
122+
self,
123+
enterprise_action_token: str,
124+
enterprise_action_kit_project_url: str = ENTERPRISE_ACTION_KIT_PROJECT_URL,
125+
enterprise_action_kit_project_id: str = ENTERPRISE_ACTION_KIT_PROJECT_ID,
126+
):
108127
"""Initialize the adapter with an enterprise action token."""
109128
if not enterprise_action_token:
110129
raise ValueError("enterprise_action_token is required")
111130

112131
self.enterprise_action_token = enterprise_action_token
113132
self._actions_schema = {}
114133
self._tools = None
134+
self.enterprise_action_kit_project_id = enterprise_action_kit_project_id
135+
self.enterprise_action_kit_project_url = enterprise_action_kit_project_url
115136

116137
def tools(self) -> List[BaseTool]:
117138
"""Get the list of tools created from enterprise actions.
@@ -127,7 +148,7 @@ def tools(self) -> List[BaseTool]:
127148
def _fetch_actions(self):
128149
"""Fetch available actions from the API."""
129150
try:
130-
actions_url = f"https://worker-actionkit.tools.crewai.com/projects/{ENTERPRISE_ACTION_KIT_PROJECT_ID}/actions"
151+
actions_url = f"{self.enterprise_action_kit_project_url}/{self.enterprise_action_kit_project_id}/actions"
131152
headers = {"Authorization": f"Bearer {self.enterprise_action_token}"}
132153
params = {"format": "json_schema"}
133154

@@ -189,6 +210,8 @@ def _create_tools(self):
189210
action_name=action_name,
190211
action_schema=action_schema,
191212
enterprise_action_token=self.enterprise_action_token,
213+
enterprise_action_kit_project_id=self.enterprise_action_kit_project_id,
214+
enterprise_action_kit_project_url=self.enterprise_action_kit_project_url,
192215
)
193216

194217
tools.append(tool)

crewai_tools/tools/crewai_enterprise_tools/crewai_enterprise_tools.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
def CrewaiEnterpriseTools(
1212
enterprise_token: t.Optional[str] = None,
13-
actions_list: t.Optional[t.List[str]] = None
13+
actions_list: t.Optional[t.List[str]] = None,
14+
enterprise_action_kit_project_id: t.Optional[str] = None,
15+
enterprise_action_kit_project_url: t.Optional[str] = None,
1416
) -> t.List[BaseTool]:
1517
"""Factory function that returns crewai enterprise tools.
1618
@@ -30,7 +32,18 @@ def CrewaiEnterpriseTools(
3032
"No enterprise token provided. Please provide a token or set the CREWAI_ENTEPRISE_TOOLS_TOKEN environment variable."
3133
)
3234

33-
adapter = EnterpriseActionKitToolAdapter(enterprise_token)
35+
adapter_kwargs = {"enterprise_action_token": enterprise_token}
36+
37+
if enterprise_action_kit_project_id is not None:
38+
adapter_kwargs["enterprise_action_kit_project_id"] = (
39+
enterprise_action_kit_project_id
40+
)
41+
if enterprise_action_kit_project_url is not None:
42+
adapter_kwargs["enterprise_action_kit_project_url"] = (
43+
enterprise_action_kit_project_url
44+
)
45+
46+
adapter = EnterpriseActionKitToolAdapter(**adapter_kwargs)
3447
all_tools = adapter.tools()
3548

3649
if actions_list is None:

0 commit comments

Comments
 (0)