Skip to content

Commit c8badd8

Browse files
committed
add option to fetch actions
1 parent 21ae506 commit c8badd8

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

docs/src/tools/composio_example.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ composio = ComposioAdapter(api_key="YOUR_KEY")
1515
### Usage
1616

1717
#### Connecting to Composio apps
18-
Creating a [Composio connection](https://docs.composio.dev/concepts/auth#connection) which connects your user to a [Contosio intergation](https://docs.composio.dev/concepts/auth#integration).
19-
The connection_id will be used by Contosio to identify the authenticated user.
18+
Creating a [Composio connection](https://docs.composio.dev/concepts/auth#connection) which connects your user to a [Composio intergation](https://docs.composio.dev/concepts/auth#integration).
19+
The connection_id will be used by Composio to identify the authenticated user.
2020
```python
2121
from composio import App
2222
connection_id, redirect_url = composio.connect(APP.SLACK)
@@ -25,10 +25,15 @@ connection_id, redirect_url = composio.connect(APP.SLACK)
2525
#### Getting tools
2626

2727
```python
28-
slack_tools = composio.get_tools(App.SLACK, connection_id=connection_id)
28+
slack_tools = composio.get_tools_by_app(App.SLACK, connection_id=connection_id)
2929

3030
# if no connection id is provided, defaut user will be used
31-
google_doc_tools = composio.get_tools(App.GOOGLEDOCS)
31+
google_doc_tools = composio.get_tools_by_app(App.GOOGLEDOCS)
32+
```
33+
34+
You can also fetch only a subset of actions from an app
35+
```python
36+
slack_tools = composio.get_tools_by_actions([Action.SLACK_SENDS_A_MESSAGE_TO_A_SLACK_CHANNEL])
3237
```
3338

3439
#### Creating agents

examples/python/composio_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from composio import App
1+
from composio import App, Action
22
from mainframe_orchestra import Task, Agent, OpenaiModels, Conduct, set_verbosity
33
from mainframe_orchestra.adapters.composio_adapter import ComposioAdapter
44

@@ -18,7 +18,7 @@
1818
goal="Control the Slack app to send and receive messages",
1919
attributes="You have access to the API provided by Slack. You can help users send and receive messages to a channel and to a single person.",
2020
llm=OpenaiModels.gpt_4o,
21-
tools=composio.get_tools(App.SLACK)
21+
tools=composio.get_tools_by_actions([Action.SLACK_SENDS_A_MESSAGE_TO_A_SLACK_CHANNEL])
2222
)
2323

2424
google_doc = Agent(
@@ -27,7 +27,7 @@
2727
goal="Control the Google Doc app to create and edit documents",
2828
attributes="You have access to the API provided by Google Doc. You can help users create and edit documents.",
2929
llm=OpenaiModels.gpt_4o,
30-
tools=composio.get_tools(App.GOOGLEDOCS)
30+
tools=composio.get_tools_by_app(App.GOOGLEDOCS)
3131
)
3232

3333
conductor_agent = Agent(

packages/python/src/mainframe_orchestra/adapters/composio_adapter.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from composio import LogLevel, ComposioToolSet, App
1+
from composio import LogLevel, ComposioToolSet, App, Action, Tag
22
from typing import Optional, Set, Callable, Any, Tuple
33
from composio.client.collections import ActionModel
44
class ComposioAdapter:
@@ -37,9 +37,9 @@ def connect(self, app: App) -> Tuple[str, str]:
3737

3838
return connection_request.connectedAccountId, connection_request.redirectUrl
3939

40-
def get_tools(self, app: App, connection_id: Optional[str] = None) -> Set[Callable]:
40+
def get_tools_by_app(self, app: App, connection_id: Optional[str] = None) -> Set[Callable]:
4141
"""
42-
Get the tools for an app
42+
Get the tools for an Composio apps
4343
4444
Args:
4545
app: The app to get the tools for
@@ -53,6 +53,23 @@ def get_tools(self, app: App, connection_id: Optional[str] = None) -> Set[Callab
5353
# Convert app names to App enum values if needed
5454
tool_schemas = self.composio_toolset.get_action_schemas(apps=[app])
5555
return [self._wrap(tool_schema, connection_id, entity_id) for tool_schema in tool_schemas]
56+
57+
def get_tools_by_actions(self, actions: list[Action], connection_id: Optional[str] = None) -> Set[Callable]:
58+
"""
59+
Get the tools for a list of Composio actions
60+
61+
Args:
62+
actions: List of actions to get the tools for
63+
connection_id: The connection id to use. If not provided, the default connection id will be used.
64+
65+
Returns:
66+
A set of tools
67+
"""
68+
entity_id = "default" if not connection_id else None
69+
70+
# Convert app names to App enum values if needed
71+
tool_schemas = self.composio_toolset.get_action_schemas(actions=actions)
72+
return [self._wrap(tool_schema, connection_id, entity_id) for tool_schema in tool_schemas]
5673

5774
def _wrap(
5875
self,

0 commit comments

Comments
 (0)