composio-openai-agents 0.7.7__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_openai_agents.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,213 @@
1
+ import json
2
+ import types
3
+ import typing as t
4
+ from inspect import Signature
5
+ from typing import List, cast
6
+
7
+ import pydantic
8
+ import pydantic.error_wrappers
9
+ from agents import FunctionTool, Tool
10
+
11
+ from composio import ActionType, AppType, TagType
12
+ from composio.tools import ComposioToolSet as BaseComposioToolSet
13
+ from composio.tools.toolset import ProcessorsType
14
+ from composio.utils.pydantic import parse_pydantic_error
15
+ from composio.utils.shared import get_signature_format_from_schema_params
16
+
17
+
18
+ class ComposioToolSet(
19
+ BaseComposioToolSet,
20
+ runtime="openai_agents",
21
+ description_char_limit=1024,
22
+ action_name_char_limit=64,
23
+ ):
24
+ """
25
+ Composio toolset for OpenAI Agents framework.
26
+
27
+ Example:
28
+ ```python
29
+ import os
30
+ import asyncio
31
+ import dotenv
32
+ from agents import Agent, Runner
33
+
34
+ from composio_openai_agents import App, ComposioToolSet
35
+
36
+ # Load environment variables from .env
37
+ dotenv.load_dotenv()
38
+
39
+ # Initialize Composio toolset
40
+ composio_toolset = ComposioToolSet()
41
+
42
+ # Get all the tools
43
+ tools = composio_toolset.get_tools(apps=[App.GITHUB])
44
+
45
+ # Create an agent with the tools
46
+ agent = Agent(
47
+ name="GitHub Agent",
48
+ instructions="You are a helpful assistant that helps users with GitHub tasks.",
49
+ tools=tools,
50
+ )
51
+
52
+ # Run the agent
53
+ async def main():
54
+ result = await Runner.run(agent, "Star the repository composiohq/composio on GitHub")
55
+ print(result.final_output)
56
+
57
+ asyncio.run(main())
58
+ ```
59
+ """
60
+
61
+ def _wrap_action(
62
+ self,
63
+ action: str,
64
+ description: str,
65
+ schema_params: t.Dict,
66
+ entity_id: t.Optional[str] = None,
67
+ ):
68
+ def function(**kwargs: t.Any) -> t.Dict:
69
+ """Wrapper function for composio action."""
70
+ self.logger.debug(f"Executing action: {action} with params: {kwargs}")
71
+ return self.execute_action(
72
+ action=action,
73
+ params=kwargs,
74
+ entity_id=entity_id or self.entity_id,
75
+ _check_requested_actions=True,
76
+ )
77
+
78
+ action_func = types.FunctionType(
79
+ function.__code__,
80
+ globals=globals(),
81
+ name=action,
82
+ closure=function.__closure__,
83
+ )
84
+ # Using setattr to avoid type checking errors
85
+ setattr(
86
+ action_func,
87
+ "__signature__",
88
+ Signature(
89
+ parameters=get_signature_format_from_schema_params(
90
+ schema_params=schema_params
91
+ )
92
+ ),
93
+ )
94
+
95
+ # Using setattr to avoid type checking errors
96
+ setattr(action_func, "__doc__", description)
97
+
98
+ return action_func
99
+
100
+ def _wrap_tool(
101
+ self,
102
+ schema: t.Dict[str, t.Any],
103
+ entity_id: t.Optional[str] = None,
104
+ ) -> FunctionTool:
105
+ """Wraps composio tool as OpenAI Agents FunctionTool object."""
106
+ action = schema["name"]
107
+ description = schema["description"]
108
+ schema_params = schema["parameters"]
109
+
110
+ # Create a function that accepts explicit JSON string for parameters
111
+ # This avoids the issue with **kwargs in schema validation
112
+ async def execute_action_wrapper(_ctx, args_json):
113
+ """Execute Composio action with the given arguments."""
114
+ try:
115
+ kwargs = json.loads(args_json) if args_json else {}
116
+
117
+ result = self.execute_action(
118
+ action=action,
119
+ params=kwargs,
120
+ entity_id=entity_id or self.entity_id,
121
+ _check_requested_actions=True,
122
+ )
123
+
124
+ # Serialize the result to JSON string
125
+ # The OpenAI API expects strings for tool outputs
126
+ if not isinstance(result, dict):
127
+ result_dict = {"result": result}
128
+ else:
129
+ result_dict = result
130
+
131
+ # Convert to JSON string
132
+ return json.dumps(result_dict)
133
+
134
+ except pydantic.ValidationError as e:
135
+ error_msg = parse_pydantic_error(e)
136
+ return json.dumps(
137
+ {
138
+ "successful": False,
139
+ "error": error_msg,
140
+ "data": None,
141
+ }
142
+ )
143
+ except Exception as e:
144
+ return json.dumps(
145
+ {
146
+ "successful": False,
147
+ "error": str(e),
148
+ "data": None,
149
+ }
150
+ )
151
+
152
+ # Ensure the schema has additionalProperties set to false
153
+ # This is required by OpenAI's function validation
154
+ modified_schema = schema_params.copy()
155
+ modified_schema["additionalProperties"] = False
156
+
157
+ # Create a custom FunctionTool with the appropriate schema
158
+ tool = FunctionTool(
159
+ name=action,
160
+ description=description,
161
+ params_json_schema=modified_schema,
162
+ on_invoke_tool=execute_action_wrapper,
163
+ strict_json_schema=True,
164
+ )
165
+
166
+ return tool
167
+
168
+ def get_tools(
169
+ self,
170
+ actions: t.Optional[t.Sequence[ActionType]] = None,
171
+ apps: t.Optional[t.Sequence[AppType]] = None,
172
+ tags: t.Optional[t.List[TagType]] = None,
173
+ entity_id: t.Optional[str] = None,
174
+ *,
175
+ processors: t.Optional[ProcessorsType] = None,
176
+ check_connected_accounts: bool = True,
177
+ ) -> List[Tool]:
178
+ """
179
+ Get composio tools wrapped as OpenAI Agents FunctionTool objects.
180
+
181
+ :param actions: List of actions to wrap
182
+ :param apps: List of apps to wrap
183
+ :param tags: Filter the apps by given tags
184
+ :param entity_id: Entity ID for the function wrapper
185
+ :param processors: Optional request/response processors
186
+ :param check_connected_accounts: Whether to check connected accounts
187
+
188
+ :return: Composio tools wrapped as `FunctionTool` objects
189
+ """
190
+ self.validate_tools(apps=apps, actions=actions, tags=tags)
191
+ if processors is not None:
192
+ self._processor_helpers.merge_processors(processors)
193
+
194
+ # Create the tools as FunctionTools
195
+ function_tools = [
196
+ self._wrap_tool(
197
+ schema=tool.model_dump(
198
+ exclude_none=True,
199
+ ),
200
+ entity_id=entity_id or self.entity_id,
201
+ )
202
+ for tool in self.get_action_schemas(
203
+ actions=actions,
204
+ apps=apps,
205
+ tags=tags,
206
+ check_connected_accounts=check_connected_accounts,
207
+ _populate_requested=True,
208
+ )
209
+ ]
210
+
211
+ # Cast the list to List[Tool] to satisfy type checking
212
+ # Since FunctionTool is a subclass of Tool, this is type-safe
213
+ return cast(List[Tool], function_tools)
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.2
2
+ Name: composio_openai_agents
3
+ Version: 0.7.7
4
+ Summary: Use Composio to get array of strongly typed tools for OpenAI Agents
5
+ Home-page: https://github.com/ComposioHQ/composio
6
+ Author: Siddharth
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: openai-agents>=0.0.3
15
+ Requires-Dist: pydantic>=2.0.0
16
+ Requires-Dist: typing-extensions>=4.0.0
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # Composio Integration for OpenAI Agents
28
+
29
+ This package integrates the OpenAI Agents framework with Composio, allowing you to use Composio's rich set of tools with the OpenAI Agents framework.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install composio_openai_agents
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```python
40
+ import asyncio
41
+ import dotenv
42
+ from agents import Agent, Runner
43
+
44
+ from composio_openai_agents import Action, ComposioToolSet
45
+
46
+ # Load environment variables from .env
47
+ dotenv.load_dotenv()
48
+
49
+ # Initialize Composio toolset
50
+ composio_toolset = ComposioToolSet()
51
+
52
+ # Get all the tools
53
+ tools = composio_toolset.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER])
54
+
55
+ # Create an agent with the tools
56
+ agent = Agent(
57
+ name="GitHub Agent",
58
+ instructions="You are a helpful assistant that helps users with GitHub tasks.",
59
+ tools=tools,
60
+ )
61
+
62
+ # Run the agent
63
+ async def main():
64
+ result = await Runner.run(agent, "Star the repository composiohq/composio on GitHub")
65
+ print(result.final_output)
66
+
67
+ asyncio.run(main())
68
+ ```
69
+
70
+ ## Features
71
+
72
+ - Seamlessly integrate Composio's tools with OpenAI Agents
73
+ - Access hundreds of pre-built API integrations
74
+ - Maintain consistent schema formats between frameworks
75
+ - Error handling for validation issues
76
+ - Proper type annotations that work with mypy and pylance
77
+
78
+ ## Requirements
79
+
80
+ - Python 3.9+
81
+ - OpenAI Agents framework
82
+ - Composio (with valid API key)
83
+
84
+ ## License
85
+
86
+ Apache 2.0
@@ -0,0 +1,6 @@
1
+ composio_openai_agents/__init__.py,sha256=E_-3XZ6yN4oM-yHfu3rJ0gHuLnfdDujYxT2XuZAcq1U,255
2
+ composio_openai_agents/toolset.py,sha256=MYDv0uika_e7SfZCNb4FQQiCSYjEVyw5vmoRfz-PNVs,6922
3
+ composio_openai_agents-0.7.7.dist-info/METADATA,sha256=07gA4lBRAhOLxNXwkkpKMBHtx7asqaWCI6oO3MXvizk,2216
4
+ composio_openai_agents-0.7.7.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
5
+ composio_openai_agents-0.7.7.dist-info/top_level.txt,sha256=_YKpUJOoiq4jzAZX0LC2SfaYhsCOcyNcoK9lbK5uWQw,23
6
+ composio_openai_agents-0.7.7.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (76.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ composio_openai_agents