diff --git a/composio/sdk/core.py b/composio/sdk/core.py index ec61dc5187..1f0c6612c8 100644 --- a/composio/sdk/core.py +++ b/composio/sdk/core.py @@ -187,8 +187,8 @@ def execute_action( tool_name = action.value[0] no_auth = action.value[2] if len(action.value) > 2 else False if no_auth: - resp = self.sdk.no_auth_execute_action(action, params) - return resp + resp = self.sdk.get_entity(entity_id) + return resp.execute_action(action, params, entity_id=entity_id) entity = self.sdk.get_entity(entity_id) account = entity.get_connection(tool_name, connection_id=connection_id) if not account: diff --git a/composio/sdk/sdk.py b/composio/sdk/sdk.py index 1a6153e2c5..b2551a9c88 100644 --- a/composio/sdk/sdk.py +++ b/composio/sdk/sdk.py @@ -124,6 +124,7 @@ class ConnectedAccount(BaseModel): model_config = ConfigDict(arbitrary_types_allowed=True) integrationId: str connectionParams: AuthConnectionParams + clientUniqueUserId: str appUniqueId: str id: str status: str @@ -142,7 +143,7 @@ def _execute_action( ): resp = self.sdk_instance.http_client.post( f"v1/actions/{action_name.value[1]}/execute", - json={"connectedAccountId": connected_account_id, "input": params}, + json={"connectedAccountId": connected_account_id, "input": params, "entityId": self.clientUniqueUserId}, ) return resp.json() @@ -461,13 +462,6 @@ def get_entity(self, entity_id: Union[list[str], str]): entity = Entity(self, entity_id) return entity - def no_auth_execute_action(self, action: Action, params: dict): - tool_name = action.value[0] - resp = self.http_client.post( - f"v1/actions/{action.value[1]}/execute", - json={"appName": tool_name, "input": params}, - ) - return resp.json() class Entity: @@ -475,6 +469,20 @@ def __init__(self, composio: Composio, entity_id: Union[list[str], str]) -> None self.client = composio entity_id = entity_id if isinstance(entity_id, str) else ",".join(entity_id) self.entity_id = entity_id + self.http_client = self.client.http_client + + def execute_action(self, action: Action, params: dict, connected_account_id: Optional[str] = None, entity_id = "default"): + no_auth = action.value[2] if len(action.value) > 2 else False + if no_auth is True: + tool_name = action.value[0] + resp = self.http_client.post( + f"v1/actions/{action.value[1]}/execute", + json={"appName": tool_name, "input": params, "entityId": entity_id}, + ) + return resp.json() + else: + connected_account = self.client.get_connected_account(connected_account_id) + return connected_account.execute_action(action, params) def get_all_actions(self, tags: list[Union[str, Tag]] = None) -> list[Action]: actions = [] diff --git a/examples/composio_crewai_demo.py b/examples/composio_crewai_demo.py new file mode 100644 index 0000000000..b8660f32ef --- /dev/null +++ b/examples/composio_crewai_demo.py @@ -0,0 +1,32 @@ +import os +import dotenv +from crewai import Agent, Task +from langchain_openai import ChatOpenAI +from plugins.crew_ai.composio_crewai import ComposioToolset, App, Action + +# Loading the variables from .env file +dotenv.load_dotenv() + +llm = ChatOpenAI(openai_api_key=os.environ["OPENAI_API_KEY"]) + + +# Get All the tools +tools = ComposioToolset(actions=[Action.COMPOSIO_CHECK_ACTIVE_CONNECTION], entity_id="soham") + + +crewai_agent = Agent( + role='User Connection Checker', + goal="""You check if the user connection is active for an app""", + backstory="""You are AI agent that is responsible for making sure that if the user connection is active for an app""", + verbose=True, + tools=tools, + llm=llm +) + +task = Task( + description="Check ifthe user connection is active for github", + agent=crewai_agent, + expected_output="Tell me if the user connection is active for github" +) + +task.execute() \ No newline at end of file diff --git a/plugins/autogen/setup.py b/plugins/autogen/setup.py index 567e0ae925..c96927b19f 100644 --- a/plugins/autogen/setup.py +++ b/plugins/autogen/setup.py @@ -24,7 +24,7 @@ python_requires=">=3.9,<4", install_requires=[ "composio_core===0.2.59", - "pyautogen>=0.2.19", + "pyautogen>=0.2.19" ], include_package_data=True, ) diff --git a/plugins/crew_ai/setup.py b/plugins/crew_ai/setup.py index ec939de191..22e7f2c548 100644 --- a/plugins/crew_ai/setup.py +++ b/plugins/crew_ai/setup.py @@ -23,7 +23,7 @@ ], python_requires=">=3.9,<4", install_requires=[ - "composio_langchain===0.2.59", + "composio_langchain===0.2.59" ], include_package_data=True, ) diff --git a/plugins/langchain/setup.py b/plugins/langchain/setup.py index 46f11a2851..69726274e8 100644 --- a/plugins/langchain/setup.py +++ b/plugins/langchain/setup.py @@ -27,7 +27,7 @@ "langchain-openai>=0.0.2.post1", "pydantic>=2.6.4", "langchainhub>=0.1.15", - "composio_core===0.2.59", + "composio_core===0.2.59" ], include_package_data=True, ) diff --git a/plugins/lyzr/setup.py b/plugins/lyzr/setup.py index d792beac0e..f2ee3170f4 100644 --- a/plugins/lyzr/setup.py +++ b/plugins/lyzr/setup.py @@ -26,7 +26,7 @@ "lyzr-automata>=0.1.3", "pydantic>=2.6.4", "composio_core===0.2.59", - "langchain>=0.1.0", + "langchain>=0.1.0" ], include_package_data=True, ) diff --git a/plugins/openai/setup.py b/plugins/openai/setup.py index 1031b41886..07e9b975ac 100644 --- a/plugins/openai/setup.py +++ b/plugins/openai/setup.py @@ -23,7 +23,7 @@ ], python_requires=">=3.9,<4", install_requires=[ - "composio_core===0.2.59", + "composio_core===0.2.59" ], include_package_data=True, ) diff --git a/tests/autogen_test.py b/tests/autogen_test.py index 08af27583e..0c95b61f82 100644 --- a/tests/autogen_test.py +++ b/tests/autogen_test.py @@ -55,6 +55,7 @@ def test_add_github(): "composio.sdk.sdk.Composio.get_connected_account", return_value=ConnectedAccount( sdk_instance=mock.Mock(), + clientUniqueUserId="default", status="ACTIVE", integrationId="integ123", connectionParams={"scope": "read", "base_url": "https://api.example.com"}, diff --git a/tests/crewai_test.py b/tests/crewai_test.py index c7452eacf1..82f6206e24 100644 --- a/tests/crewai_test.py +++ b/tests/crewai_test.py @@ -55,6 +55,7 @@ def test_add_github(): "composio.sdk.sdk.Composio.get_connected_account", return_value=ConnectedAccount( sdk_instance=mock.Mock(), + clientUniqueUserId="default", status="ACTIVE", integrationId="integ123", connectionParams={"scope": "read", "base_url": "https://api.example.com"}, diff --git a/tests/langchain_test.py b/tests/langchain_test.py index 226da92e7e..bbdc7e1544 100644 --- a/tests/langchain_test.py +++ b/tests/langchain_test.py @@ -57,6 +57,7 @@ def test_add_github(): sdk_instance=mock.Mock(), status="ACTIVE", integrationId="integ123", + clientUniqueUserId="default", connectionParams={"scope": "read", "base_url": "https://api.example.com"}, appUniqueId="app456", id="",