Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(connected-accounts-py): address review feedback on #3412

venkat82ed3bb936d26a
diff --git a/python/composio/core/models/connected_accounts.py b/python/composio/core/models/connected_accounts.py
index 69572ecb3..99a532416 100644
--- a/python/composio/core/models/connected_accounts.py
+++ b/python/composio/core/models/connected_accounts.py
@@ -21,6 +21,7 @@ from composio.client.types import (
)
from .base import Resource
+from .experimental import ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT
logger = logging.getLogger(__name__)
@@ -647,7 +648,7 @@ class ConnectedAccounts:
# as a typed error so callers can ``except`` instead of grepping
# messages.
message = str(error)
- if "acl_config_for_shared is only valid on SHARED" in message:
+ if ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT in message:
raise exceptions.ComposioAclOnlyForSharedError(message) from error
raise
diff --git a/python/composio/core/models/experimental.py b/python/composio/core/models/experimental.py
index 0d66679e2..7cca7f3b8 100644
--- a/python/composio/core/models/experimental.py
+++ b/python/composio/core/models/experimental.py
@@ -20,6 +20,12 @@ import typing as t
from pydantic import BaseModel
+from composio.client import HttpClient
+from composio.client.types import (
+ connected_account_patch_params,
+ connected_account_patch_response,
+)
+
from .custom_tool import (
CustomTool,
ExperimentalToolkit,
@@ -27,6 +33,12 @@ from .custom_tool import (
_infer_tool_from_function,
)
+# Server-side 400 message the API uses to reject ACL writes against a
+# PRIVATE connection. Substring-matched in `update_acl` here and in the
+# sibling `link()` / `authorize()` call sites — kept as a single constant
+# so a server-side message tweak only requires one edit.
+ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT = "acl_config_for_shared is only valid on SHARED"
+
class ExperimentalAPI:
"""Experimental APIs accessed via ``composio.experimental``.
@@ -38,7 +50,7 @@ class ExperimentalAPI:
Toolkit = ExperimentalToolkit
- def __init__(self, client: t.Optional[t.Any] = None) -> None:
+ def __init__(self, client: t.Optional[HttpClient] = None) -> None:
self._client = client
def update_acl(
@@ -48,7 +60,7 @@ class ExperimentalAPI:
allow_all_users: t.Optional[bool] = None,
allowed_user_ids: t.Optional[t.List[str]] = None,
not_allowed_user_ids: t.Optional[t.List[str]] = None,
- ) -> t.Any:
+ ) -> connected_account_patch_response.ConnectedAccountPatchResponse:
"""
Update the per-user ACL on a SHARED connected account. Experimental —
shape may change in future releases.
@@ -75,7 +87,7 @@ class ExperimentalAPI:
not_allowed_user_ids=['user_bob'],
)
"""
- from composio_client import BadRequestError, omit
+ from composio_client import BadRequestError
from composio import exceptions
@@ -105,13 +117,16 @@ class ExperimentalAPI:
try:
return self._client.connected_accounts.patch(
nanoid,
- experimental={"acl_config_for_shared": acl},
- alias=omit,
- connection=omit,
+ experimental={
+ "acl_config_for_shared": t.cast(
+ connected_account_patch_params.ExperimentalACLConfigForShared,
+ acl,
+ ),
+ },
)
except BadRequestError as error:
message = str(error)
- if "acl_config_for_shared is only valid on SHARED" in message:
+ if ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT in message:
raise exceptions.ComposioAclOnlyForSharedError(message) from error
raise
diff --git a/python/composio/core/models/tool_router_session.py b/python/composio/core/models/tool_router_session.py
index 19470043a..5865bad06 100644
--- a/python/composio/core/models/tool_router_session.py
+++ b/python/composio/core/models/tool_router_session.py
@@ -36,6 +36,7 @@ from composio.client.types import Tool
from composio.core.models._modifiers import Modifiers, apply_modifier_by_type
from composio.core.models.connected_accounts import ConnectionRequest
from composio.core.models.custom_tool import find_custom_tool_map_entry_by_final_slug
+from composio.core.models.experimental import ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT
from composio.core.models.custom_tool_execution import (
execute_custom_tool,
find_custom_tool,
@@ -565,7 +566,7 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
# The server rejects ACL on PRIVATE connections — surface that
# as a typed error mirroring ``composio.connected_accounts.link()``.
message = str(error)
- if "acl_config_for_shared is only valid on SHARED" in message:
+ if ACL_ONLY_FOR_SHARED_ERROR_FRAGMENT in message:
raise exceptions.ComposioAclOnlyForSharedError(message) from error
raise
diff --git a/python/composio/exceptions.py b/python/composio/exceptions.py
index 8dfca580c..c8c124834 100644
--- a/python/composio/exceptions.py
+++ b/python/composio/exceptions.py
@@ -353,7 +353,7 @@ class ComposioSharedAccessDeniedError(ConnectedAccountError):
going through a tool-router session.
Fix: ask the connection's creator to grant access via
- ``composio.connected_accounts.update_acl()`` — set ``allow_all_users``,
+ ``composio.experimental.update_acl()`` — set ``allow_all_users``,
add the ``user_id`` to ``allowed_user_ids``, or remove it from
``not_allowed_user_ids``.
"""
@@ -368,7 +368,7 @@ class ComposioSharedConnectionNotAccessibleError(ConnectedAccountError):
that fails mid-execution.
Fix: grant the session user access via
- ``composio.connected_accounts.update_acl()`` on the pinned connection,
+ ``composio.experimental.update_acl()`` on the pinned connection,
or pin a different connection the user can use.
"""
diff --git a/python/setup.py b/python/setup.py
index 827b073ed..18e44c179 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -25,7 +25,7 @@ setup(
install_requires=[
"pysher>=1.0.8",
"pydantic>=2.6.4",
- "composio-client==1.36.0",
+ "composio-client==1.39.0",
"typing-extensions>=4.0.0",
"openai",
"json-schema-to-pydantic>=0.4.8",
diff --git a/python/tests/test_connected_accounts.py b/python/tests/test_connected_accounts.py
index 858e0a3ec..9616a8f00 100644
--- a/python/tests/test_connected_accounts.py
+++ b/python/tests/test_connected_accounts.py
@@ -687,8 +687,6 @@ class TestConnectedAccountsAcl:
"not_allowed_user_ids": ["user_bob"],
}
},
- alias=omit,
- connection=omit,
)
assert result is response
@@ -700,8 +698,6 @@ class TestConnectedAccountsAcl:
experimental={
"acl_config_for_shared": {"allowed_user_ids": ["user_alice"]}
},
- alias=omit,
- connection=omit,
)
def test_update_acl_preserves_empty_array(self, experimental, mock_client):
@@ -710,8 +706,6 @@ class TestConnectedAccountsAcl:
mock_client.connected_accounts.patch.assert_called_once_with(
"ca_abc",
experimental={"acl_config_for_shared": {"allowed_user_ids": []}},
- alias=omit,
- connection=omit,
)
def test_update_acl_rejects_all_none(self, experimental, mock_client):