composio-smol 0.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ from composio_smol.toolset import ComposioToolSet
2
+
3
+ from composio import Action, App, Tag, Trigger, WorkspaceType, action
4
+
5
+
6
+ __all__ = (
7
+ "Action",
8
+ "App",
9
+ "Tag",
10
+ "Trigger",
11
+ "WorkspaceType",
12
+ "action",
13
+ "ComposioToolSet",
14
+ )
@@ -0,0 +1,171 @@
1
+ import types
2
+ import typing as t
3
+ from inspect import Signature
4
+ from typing import Callable, Dict
5
+
6
+ import pydantic
7
+ import pydantic.error_wrappers
8
+ from smolagents.tools import Tool
9
+
10
+ from composio import ActionType, AppType, TagType
11
+ from composio.tools import ComposioToolSet as BaseComposioToolSet
12
+ from composio.tools.toolset import ProcessorsType
13
+ from composio.utils.pydantic import parse_pydantic_error
14
+ from composio.utils.shared import get_signature_format_from_schema_params
15
+
16
+
17
+ class StructuredTool(Tool):
18
+ def __init__(
19
+ self,
20
+ name: str,
21
+ description: str,
22
+ params: Dict[str, Dict[str, str | type | bool]],
23
+ output_type: str,
24
+ function: Callable,
25
+ ):
26
+ self.name = name
27
+ self.description = description
28
+ self.inputs = params
29
+ self.output_type = output_type
30
+ self.forward = function
31
+ self.is_initialized = True
32
+
33
+ def run(self, *args, **kwargs):
34
+ try:
35
+ return self.forward(*args, **kwargs)
36
+ except pydantic.ValidationError as e:
37
+ return {"successful": False, "error": parse_pydantic_error(e), "data": None}
38
+
39
+
40
+ class ComposioToolSet(
41
+ BaseComposioToolSet,
42
+ runtime="smol",
43
+ description_char_limit=1024,
44
+ action_name_char_limit=64,
45
+ ):
46
+ """
47
+ Composio toolset for Smolagents framework.
48
+
49
+ Example:
50
+ ```python
51
+ from dotenv import load_dotenv
52
+ from composio import Action
53
+ from composio_smol import ComposioToolSet
54
+ from smolagents import HfApiModel, CodeAgent
55
+
56
+ load_dotenv()
57
+ # Initialize toolset
58
+ composio_toolset = ComposioToolSet()
59
+
60
+ tools = composio_toolset.get_tools(
61
+ actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER],
62
+ )
63
+ # Create agent with Composio tools
64
+ agent = CodeAgent(
65
+ tools=list(tools),
66
+ model=HfApiModel()
67
+ )
68
+
69
+ agent.run("Star the composiohq/composio repo")
70
+
71
+ ```
72
+ """
73
+
74
+ def _wrap_action(
75
+ self,
76
+ action: str,
77
+ description: str,
78
+ schema_params: t.Dict,
79
+ entity_id: t.Optional[str] = None,
80
+ ):
81
+ def function(**kwargs: t.Any) -> t.Dict:
82
+ """Wrapper function for composio action."""
83
+ self.logger.debug(f"Executing action: {action} with params: {kwargs}")
84
+ return self.execute_action(
85
+ action=action,
86
+ params=kwargs,
87
+ entity_id=entity_id or self.entity_id,
88
+ _check_requested_actions=True,
89
+ )
90
+
91
+ action_func = types.FunctionType(
92
+ function.__code__,
93
+ globals=globals(),
94
+ name=action,
95
+ closure=function.__closure__,
96
+ )
97
+ action_func.__signature__ = Signature( # type: ignore
98
+ parameters=get_signature_format_from_schema_params(
99
+ schema_params=schema_params
100
+ )
101
+ )
102
+
103
+ action_func.__doc__ = description
104
+
105
+ return action_func
106
+
107
+ def _wrap_tool(
108
+ self,
109
+ schema: t.Dict[str, t.Any],
110
+ entity_id: t.Optional[str] = None,
111
+ ) -> StructuredTool:
112
+ """Wraps composio tool as StructuredTool object."""
113
+ action = schema["name"]
114
+ description = schema["description"]
115
+ schema_params = schema["parameters"]
116
+ action_func = self._wrap_action(
117
+ action=action,
118
+ description=description,
119
+ schema_params=schema_params,
120
+ entity_id=entity_id,
121
+ )
122
+ # Flatten and format the parameters structure
123
+ params = schema_params["properties"]
124
+ tool = StructuredTool(
125
+ name=action,
126
+ description=description,
127
+ params=params,
128
+ output_type="object",
129
+ function=action_func,
130
+ )
131
+ return tool
132
+
133
+ def get_tools(
134
+ self,
135
+ actions: t.Optional[t.Sequence[ActionType]] = None,
136
+ apps: t.Optional[t.Sequence[AppType]] = None,
137
+ tags: t.Optional[t.List[TagType]] = None,
138
+ entity_id: t.Optional[str] = None,
139
+ *,
140
+ processors: t.Optional[ProcessorsType] = None,
141
+ check_connected_accounts: bool = True,
142
+ ) -> t.Sequence[StructuredTool]:
143
+ """
144
+ Get composio tools wrapped as StructuredTool objects.
145
+
146
+ :param actions: List of actions to wrap
147
+ :param apps: List of apps to wrap
148
+ :param tags: Filter the apps by given tags
149
+ :param entity_id: Entity ID for the function wrapper
150
+ :param processors: Optional processors to apply to the tools
151
+ :param check_connected_accounts: Whether to check for connected accounts
152
+ :return: Composio tools wrapped as `StructuredTool` objects
153
+ """
154
+ self.validate_tools(apps=apps, actions=actions, tags=tags)
155
+ if processors is not None:
156
+ self._processor_helpers.merge_processors(processors)
157
+ return [
158
+ self._wrap_tool(
159
+ schema=tool.model_dump(
160
+ exclude_none=True,
161
+ ),
162
+ entity_id=entity_id or self.entity_id,
163
+ )
164
+ for tool in self.get_action_schemas(
165
+ actions=actions,
166
+ apps=apps,
167
+ tags=tags,
168
+ check_connected_accounts=check_connected_accounts,
169
+ _populate_requested=True,
170
+ )
171
+ ]
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.2
2
+ Name: composio_smol
3
+ Version: 0.7.1
4
+ Summary: Use Composio to get array of strongly typed tools for Smol Agents
5
+ Home-page: https://github.com/ComposioHQ/composio
6
+ Author: Composio
7
+ Author-email: tech@composio.dev
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9,<4
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: composio_core<0.8.0,>=0.7.0
14
+ Requires-Dist: smolagents
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ ## 🚀🔗 Leveraging Smol Agents with Composio
26
+
27
+ Integrate Smol Agents with Composio to enable direct interaction with external applications, enhancing their capabilities through strongly-typed, validated tools.
28
+
29
+ ### Objective
30
+
31
+ - **Automate GitHub operations** using type-safe instructions via Smol Agent's Tool system.
32
+ - Demonstrate how to use Composio's tools with Smol Agent's CodeAgent.
33
+
34
+ ### Installation and Setup
35
+
36
+ Install the necessary packages and connect your GitHub account to enable agent interactions with GitHub:
37
+
38
+ ```bash
39
+ # Install Composio Smol Agents package
40
+ pip install composio-smol
41
+
42
+ # Connect your GitHub account
43
+ composio add github
44
+
45
+ # View available applications you can connect with
46
+ composio apps
47
+ ```
48
+
49
+ ### Usage Steps
50
+
51
+ #### 1. Import Required Packages
52
+
53
+ Set up your environment by importing the necessary components from Composio & Smol Agents:
54
+
55
+ ```python
56
+ from dotenv import load_dotenv
57
+ import os
58
+
59
+ from composio import Action
60
+ from composio_smol import ComposioToolSet
61
+ from smolagents import HfApiModel, CodeAgent
62
+ ```
63
+
64
+ #### 2. Initialize Tools with Composio
65
+
66
+ Configure and fetch GitHub tools provided by Composio:
67
+
68
+ ```python
69
+ # Initialize toolset
70
+ composio_toolset = ComposioToolSet()
71
+
72
+ # Get GitHub tools with retry configuration
73
+ tools = composio_toolset.get_tools(
74
+ actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER],
75
+ )
76
+ ```
77
+
78
+ #### 3. Set Up the Smol Agent
79
+
80
+ Create and configure a Smol agent with the Composio tools:
81
+
82
+ ```python
83
+ # Create an agent with the tools
84
+ agent = CodeAgent(
85
+ tools=tools,
86
+ model=HfApiModel()
87
+ )
88
+ ```
89
+
90
+ #### 4. Execute Tasks
91
+
92
+ Run your agent with specific tasks:
93
+
94
+ ```python
95
+ # Define task
96
+ agent.run("Star the composiohq/composio repo")
97
+ ```
98
+
99
+ ### Advanced Usage
100
+
101
+ The integration supports more complex scenarios:
102
+
103
+ ```python
104
+ # Using multiple tools
105
+ tools = composio_toolset.get_tools(
106
+ actions=[
107
+ Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER,
108
+ Action.GITHUB_CREATE_REPOSITORY
109
+ ],
110
+ )
111
+
112
+ # Using app-specific tools
113
+ tools = composio_toolset.get_tools(
114
+ apps=[App.GITHUB],
115
+ )
116
+ ```
117
+
118
+ ### Best Practices
119
+
120
+ 1. Always use proper type hints in your code
121
+ 2. Handle validation errors appropriately
122
+ 3. Use the latest version of both Smol Agent and Composio
123
+ 4. Leverage async operations for better performance
124
+ 5. Keep your API keys secure using environment variables
125
+ 6. Configure retries based on the specific needs of each tool
@@ -0,0 +1,6 @@
1
+ composio_smol/__init__.py,sha256=vhykKuh6fZ6F21wGUvm3A6NTaeCnPwOMBwq4u5opBKE,246
2
+ composio_smol/toolset.py,sha256=Q5aBVlLX9A4euB9RRuWt4lpvDbNdPlsOTFxFevBx890,5309
3
+ composio_smol-0.7.1.dist-info/METADATA,sha256=rt7QClLbYeZV6Sq9mcbPt4w9RUFIynnhIoO1Xckf7XI,3121
4
+ composio_smol-0.7.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
5
+ composio_smol-0.7.1.dist-info/top_level.txt,sha256=QWxT62bXOYLbM34nE31Y8_cdXufUB-ZFgcjnxMd5tLc,14
6
+ composio_smol-0.7.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ composio_smol