@devries-cameron20 / composio Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
sh 540 lines 15.8 KB
Raw
1 #!/bin/bash
2
3 # Check if provider name is provided
4 if [ -z "$1" ]; then
5 echo "Please provide a provider name"
6 echo "Usage: ./scripts/create-provider.sh <provider-name> [--agentic] [--output-dir <directory>]"
7 exit 1
8 fi
9
10 PROVIDER_NAME=$1
11 shift
12
13 # Default output directory
14 OUTPUT_DIR="python/providers"
15 IS_AGENTIC=false
16
17 # Parse optional arguments
18 while [[ $# -gt 0 ]]; do
19 case $1 in
20 --agentic)
21 IS_AGENTIC=true
22 shift
23 ;;
24 --output-dir)
25 OUTPUT_DIR="$2"
26 shift 2
27 ;;
28 *)
29 echo "Unknown option: $1"
30 echo "Usage: ./scripts/create-provider.sh <provider-name> [--agentic] [--output-dir <directory>]"
31 exit 1
32 ;;
33 esac
34 done
35
36 PROVIDER_PATH="$OUTPUT_DIR/$PROVIDER_NAME"
37 # Convert to title case (e.g., myai -> Myai)
38 TITLE_CASE_PROVIDER_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${PROVIDER_NAME:0:1})${PROVIDER_NAME:1}"
39 PACKAGE_NAME="composio_$PROVIDER_NAME"
40
41 # Check if provider directory already exists
42 if [ -d "$PROVIDER_PATH" ]; then
43 echo "❌ Provider '$PROVIDER_NAME' already exists in $PROVIDER_PATH"
44 exit 1
45 fi
46
47 # Create directory structure
48 mkdir -p "$PROVIDER_PATH/$PACKAGE_NAME"
49
50 # Create pyproject.toml
51 cat > "$PROVIDER_PATH/pyproject.toml" << EOL
52 [project]
53 name = "$PACKAGE_NAME"
54 version = "0.1.0"
55 description = "${IS_AGENTIC:+Agentic }Provider for ${TITLE_CASE_PROVIDER_NAME} in the Composio SDK"
56 readme = "README.md"
57 requires-python = ">=3.11,<3.16"
58 authors = [
59 { name = "Composio", email = "tech@composio.dev" }
60 ]
61 classifiers = [
62 "Programming Language :: Python :: 3",
63 "License :: OSI Approved :: Apache Software License",
64 "Operating System :: OS Independent",
65 ]
66 dependencies = [
67 "composio",
68 ]
69
70 [project.urls]
71 Homepage = "https://github.com/ComposioHQ/composio"
72 EOL
73
74 # Create setup.py for backwards compatibility
75 cat > "$PROVIDER_PATH/setup.py" << EOL
76 from setuptools import setup, find_packages
77
78 setup(
79 name="$PACKAGE_NAME",
80 version="0.1.0",
81 packages=find_packages(exclude=["tests", "tests.*"]),
82 install_requires=[
83 "composio>=0.1.0",
84 ],
85 python_requires=">=3.11,<3.16",
86 author="Your Name",
87 author_email="you@example.com",
88 description="${IS_AGENTIC:+Agentic }Provider for ${TITLE_CASE_PROVIDER_NAME} in the Composio SDK",
89 long_description=open("README.md").read(),
90 long_description_content_type="text/markdown",
91 url="https://github.com/composio/composio",
92 classifiers=[
93 "Development Status :: 3 - Alpha",
94 "Intended Audience :: Developers",
95 "License :: OSI Approved :: Apache Software License",
96 "Programming Language :: Python :: 3",
97 "Programming Language :: Python :: 3.11",
98 "Programming Language :: Python :: 3.12",
99 "Programming Language :: Python :: 3.13",
100 "Programming Language :: Python :: 3.14",
101 "Programming Language :: Python :: 3.15",
102 ],
103 )
104 EOL
105
106 # Create __init__.py
107 cat > "$PROVIDER_PATH/$PACKAGE_NAME/__init__.py" << EOL
108 """
109 ${TITLE_CASE_PROVIDER_NAME} Provider for composio SDK.
110 """
111
112 from .provider import ${TITLE_CASE_PROVIDER_NAME}Provider
113
114 __all__ = ["${TITLE_CASE_PROVIDER_NAME}Provider"]
115 EOL
116
117 # Create provider.py
118 if [ "$IS_AGENTIC" = true ]; then
119 cat > "$PROVIDER_PATH/$PACKAGE_NAME/provider.py" << EOL
120 """
121 ${TITLE_CASE_PROVIDER_NAME} Provider implementation.
122 """
123
124 from __future__ import annotations
125
126 import typing as t
127
128 from composio.core.provider import AgenticProvider
129 from composio.core.provider.agentic import AgenticProviderExecuteFn
130 from composio.types import Tool
131
132
133 # Define your tool format
134 class ${TITLE_CASE_PROVIDER_NAME}Tool:
135 """${TITLE_CASE_PROVIDER_NAME} tool format"""
136 def __init__(self, name: str, description: str, execute: t.Callable, schema: dict):
137 self.name = name
138 self.description = description
139 self.execute = execute
140 self.schema = schema
141
142
143 class ${TITLE_CASE_PROVIDER_NAME}Provider(
144 AgenticProvider[${TITLE_CASE_PROVIDER_NAME}Tool, t.List[${TITLE_CASE_PROVIDER_NAME}Tool]],
145 name="${PROVIDER_NAME}"
146 ):
147 """
148 Composio toolset for ${TITLE_CASE_PROVIDER_NAME} framework.
149 """
150
151 def wrap_tool(
152 self,
153 tool: Tool,
154 execute_tool: AgenticProviderExecuteFn
155 ) -> ${TITLE_CASE_PROVIDER_NAME}Tool:
156 """Wrap a tool in the ${PROVIDER_NAME} format."""
157 def execute_wrapper(**kwargs) -> t.Dict:
158 result = execute_tool(tool.slug, kwargs)
159 if not result.get("successful", False):
160 raise Exception(result.get("error", "Tool execution failed"))
161 return result.get("data", {})
162
163 return ${TITLE_CASE_PROVIDER_NAME}Tool(
164 name=tool.slug,
165 description=tool.description or "",
166 execute=execute_wrapper,
167 schema=tool.input_parameters
168 )
169
170 def wrap_tools(
171 self,
172 tools: t.Sequence[Tool],
173 execute_tool: AgenticProviderExecuteFn
174 ) -> t.List[${TITLE_CASE_PROVIDER_NAME}Tool]:
175 """
176 Get composio tools wrapped as a list of ${TITLE_CASE_PROVIDER_NAME} tools.
177 """
178 return [self.wrap_tool(tool, execute_tool) for tool in tools]
179 EOL
180 else
181 cat > "$PROVIDER_PATH/$PACKAGE_NAME/provider.py" << EOL
182 """
183 ${TITLE_CASE_PROVIDER_NAME} Provider implementation.
184 """
185
186 from __future__ import annotations
187
188 import typing as t
189
190 from composio.core.provider import NonAgenticProvider
191 from composio.types import Tool, Modifiers, ToolExecutionResponse
192
193
194 # Define your tool format
195 class ${TITLE_CASE_PROVIDER_NAME}Tool:
196 """${TITLE_CASE_PROVIDER_NAME} tool format"""
197 def __init__(self, name: str, description: str, parameters: dict):
198 self.name = name
199 self.description = description
200 self.parameters = parameters
201
202
203 # Define your tool collection format
204 ${TITLE_CASE_PROVIDER_NAME}ToolCollection: t.TypeAlias = t.List[${TITLE_CASE_PROVIDER_NAME}Tool]
205
206
207 class ${TITLE_CASE_PROVIDER_NAME}Provider(
208 NonAgenticProvider[${TITLE_CASE_PROVIDER_NAME}Tool, ${TITLE_CASE_PROVIDER_NAME}ToolCollection],
209 name="${PROVIDER_NAME}"
210 ):
211 """
212 Composio toolset for ${TITLE_CASE_PROVIDER_NAME} platform.
213 """
214
215 def wrap_tool(self, tool: Tool) -> ${TITLE_CASE_PROVIDER_NAME}Tool:
216 """Transform a single tool to platform format"""
217 return ${TITLE_CASE_PROVIDER_NAME}Tool(
218 name=tool.slug,
219 description=tool.description or "",
220 parameters={
221 "type": "object",
222 "properties": tool.input_parameters.get("properties", {}),
223 "required": tool.input_parameters.get("required", [])
224 }
225 )
226
227 def wrap_tools(self, tools: t.Sequence[Tool]) -> ${TITLE_CASE_PROVIDER_NAME}ToolCollection:
228 """Transform a collection of tools"""
229 return [self.wrap_tool(tool) for tool in tools]
230
231 def execute_tool_call(
232 self,
233 user_id: str,
234 tool_call: dict,
235 modifiers: t.Optional[Modifiers] = None
236 ) -> ToolExecutionResponse:
237 """
238 Execute a tool call.
239
240 :param user_id: User ID to use for executing function calls.
241 :param tool_call: Tool call metadata containing 'name' and 'arguments'.
242 :param modifiers: Modifiers to use for executing function calls.
243 :return: Object containing output data from the tool call.
244 """
245 return self.execute_tool(
246 slug=tool_call["name"],
247 arguments=tool_call["arguments"],
248 modifiers=modifiers,
249 user_id=user_id
250 )
251
252 def handle_tool_calls(
253 self,
254 user_id: str,
255 response: t.Union[dict, t.Any],
256 modifiers: t.Optional[Modifiers] = None
257 ) -> t.List[ToolExecutionResponse]:
258 """
259 Handle tool calls from ${TITLE_CASE_PROVIDER_NAME} response.
260
261 :param response: Response object from ${TITLE_CASE_PROVIDER_NAME}
262 :param user_id: User ID to use for executing function calls.
263 :param modifiers: Modifiers to use for executing function calls.
264 :return: A list of output objects from the tool calls.
265 """
266 # TODO: Implement based on ${TITLE_CASE_PROVIDER_NAME}'s response format
267 # Example:
268 # outputs = []
269 # for tool_call in response.tool_calls:
270 # outputs.append(
271 # self.execute_tool_call(
272 # user_id=user_id,
273 # tool_call=tool_call,
274 # modifiers=modifiers,
275 # )
276 # )
277 # return outputs
278 raise NotImplementedError("Tool call handling not implemented yet")
279 EOL
280 fi
281
282 # Create py.typed marker for PEP 561
283 touch "$PROVIDER_PATH/$PACKAGE_NAME/py.typed"
284
285 # Create demo script
286 if [ "$IS_AGENTIC" = true ]; then
287 cat > "$PROVIDER_PATH/${PROVIDER_NAME}_demo.py" << EOL
288 """
289 ${TITLE_CASE_PROVIDER_NAME} demo.
290 """
291
292 import asyncio
293
294 # from ${PROVIDER_NAME}_framework import Agent, Runner # Import your agent framework
295 from composio_${PROVIDER_NAME} import ${TITLE_CASE_PROVIDER_NAME}Provider
296
297 from composio import Composio
298
299 # Initialize Composio toolset
300 composio = Composio(provider=${TITLE_CASE_PROVIDER_NAME}Provider())
301
302 # Get all the tools
303 tools = composio.tools.get(
304 user_id="default",
305 tools=["GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER"],
306 )
307
308 # TODO: Create an agent with the tools
309 # agent = Agent(
310 # name="GitHub Agent",
311 # instructions="You are a helpful assistant that helps users with GitHub tasks.",
312 # tools=tools,
313 # )
314
315
316 # Run the agent
317 async def main():
318 # TODO: Implement your agent execution logic
319 # result = await Runner.run(
320 # starting_agent=agent,
321 # input=(
322 # "Star the repository composiohq/composio on GitHub. If done "
323 # "successfully, respond with 'Action executed successfully'"
324 # ),
325 # )
326 # print(result.final_output)
327
328 print("Implement your ${TITLE_CASE_PROVIDER_NAME} agent logic here!")
329 print(f"Got {len(tools)} tools:")
330 for tool in tools:
331 print(f" - {tool.name}: {tool.description}")
332
333
334 asyncio.run(main())
335 EOL
336 else
337 cat > "$PROVIDER_PATH/${PROVIDER_NAME}_demo.py" << EOL
338 """
339 ${TITLE_CASE_PROVIDER_NAME} demo.
340 """
341
342 from composio_${PROVIDER_NAME} import ${TITLE_CASE_PROVIDER_NAME}Provider
343 # from ${PROVIDER_NAME} import ${TITLE_CASE_PROVIDER_NAME} # Import your AI client
344
345 from composio import Composio
346
347 # Initialize tools.
348 # ${PROVIDER_NAME}_client = ${TITLE_CASE_PROVIDER_NAME}() # Initialize your AI client
349 composio = Composio(provider=${TITLE_CASE_PROVIDER_NAME}Provider())
350
351 # Define task.
352 task = "Star a repo composiohq/composio on GitHub"
353
354 # Get GitHub tools that are pre-configured
355 tools = composio.tools.get(user_id="default", toolkits=["GITHUB"])
356
357 # TODO: Get response from the LLM
358 # response = ${PROVIDER_NAME}_client.chat.completions.create(
359 # model="your-model",
360 # tools=tools,
361 # messages=[
362 # {"role": "system", "content": "You are a helpful assistant."},
363 # {"role": "user", "content": task},
364 # ],
365 # )
366 # print(response)
367
368 # TODO: Execute the function calls.
369 # result = composio.provider.handle_tool_calls(response=response, user_id="default")
370 # print(result)
371
372 print(f"Got {len(tools)} tools for the task: {task}")
373 for tool in tools:
374 print(f" - {tool.name}: {tool.description}")
375 print("\nImplement your ${TITLE_CASE_PROVIDER_NAME} integration here!")
376 EOL
377 fi
378
379 # Create README.md
380 cat > "$PROVIDER_PATH/README.md" << EOL
381 # $PACKAGE_NAME
382
383 ${IS_AGENTIC:+Agentic }Provider for ${TITLE_CASE_PROVIDER_NAME} in the Composio SDK.
384
385 ## Features
386
387 ${IS_AGENTIC:+- **Full Tool Execution**: Execute tools with proper parameter handling
388 - **Agent Support**: Create agents with wrapped tools
389 - **Type Safety**: Full type annotations for better IDE support}${!IS_AGENTIC:+- **Tool Transformation**: Convert Composio tools to ${TITLE_CASE_PROVIDER_NAME} format
390 - **Tool Execution**: Execute tools with proper parameter handling
391 - **Type Safety**: Full type annotations for better IDE support}
392
393 ## Installation
394
395 \`\`\`bash
396 pip install $PACKAGE_NAME
397 # or
398 uv add $PACKAGE_NAME
399 \`\`\`
400
401 ## Quick Start
402
403 \`\`\`python
404 from composio import Composio
405 from composio_${PROVIDER_NAME} import ${TITLE_CASE_PROVIDER_NAME}Provider
406
407 # Initialize Composio with ${TITLE_CASE_PROVIDER_NAME} provider
408 composio = Composio(
409 api_key="your-composio-api-key",
410 provider=${TITLE_CASE_PROVIDER_NAME}Provider()
411 )
412
413 # Get available tools
414 tools = composio.tools.get(
415 user_id="default",
416 toolkits=["github", "gmail"]
417 )
418
419 # Use tools with ${TITLE_CASE_PROVIDER_NAME}
420 # TODO: Add your usage example here
421 \`\`\`
422
423 ## Usage Examples
424
425 ### Basic Example
426
427 \`\`\`python
428 from composio import Composio
429 from composio_${PROVIDER_NAME} import ${TITLE_CASE_PROVIDER_NAME}Provider
430
431 # Initialize provider
432 provider = ${TITLE_CASE_PROVIDER_NAME}Provider()
433
434 # Initialize Composio
435 composio = Composio(
436 api_key="your-api-key",
437 provider=provider
438 )
439
440 # Get tools
441 tools = composio.tools.get(
442 user_id="default",
443 toolkits=["github"]
444 )
445
446 ${IS_AGENTIC:+# Use the tools with your agent framework
447 # TODO: Implement your agent logic here
448 for tool in tools:
449 print(f"Tool: {tool.name} - {tool.description}")}${!IS_AGENTIC:+# TODO: Get response from your AI platform (example)
450 # response = ${PROVIDER_NAME}_client.chat.completions.create(
451 # model="your-model",
452 # tools=tools,
453 # messages=[
454 # {"role": "system", "content": "You are a helpful assistant."},
455 # {"role": "user", "content": "Star the composiohq/composio repository"},
456 # ],
457 # )
458 #
459 # # Execute the function calls
460 # result = composio.provider.handle_tool_calls(response=response, user_id="default")
461 # print(result)}
462 \`\`\`
463
464 ## API Reference
465
466 ### ${TITLE_CASE_PROVIDER_NAME}Provider Class
467
468 The \`${TITLE_CASE_PROVIDER_NAME}Provider\` class extends \`${IS_AGENTIC:+AgenticProvider}${!IS_AGENTIC:+NonAgenticProvider}\` and provides ${PROVIDER_NAME}-specific functionality.
469
470 #### Methods
471
472 ##### \`wrap_tool(tool: Tool${IS_AGENTIC:+, execute_tool: AgenticProviderExecuteFn}) -> ${TITLE_CASE_PROVIDER_NAME}Tool\`
473
474 Wraps a tool in the ${PROVIDER_NAME} format.
475
476 \`\`\`python
477 tool = provider.wrap_tool(composio_tool${IS_AGENTIC:+, execute_tool})
478 \`\`\`
479
480 ##### \`wrap_tools(tools: Sequence[Tool]${IS_AGENTIC:+, execute_tool: AgenticProviderExecuteFn}) -> ${IS_AGENTIC:+${TITLE_CASE_PROVIDER_NAME}Toolkit}${!IS_AGENTIC:+${TITLE_CASE_PROVIDER_NAME}ToolCollection}\`
481
482 Wraps multiple tools in the ${PROVIDER_NAME} format.
483
484 \`\`\`python
485 tools = provider.wrap_tools(composio_tools${IS_AGENTIC:+, execute_tool})
486 \`\`\`
487
488 ${!IS_AGENTIC:+##### \`execute_tool_call(user_id: str, tool_call: dict, modifiers: Optional[Modifiers] = None) -> ToolExecutionResponse\`
489
490 Executes a tool call.
491
492 \`\`\`python
493 result = provider.execute_tool_call(
494 user_id="default",
495 tool_call={"name": "TOOL_NAME", "arguments": {...}}
496 )
497 \`\`\`}
498
499 ## Development
500
501 1. Clone the repository
502 2. Install dependencies: \`uv sync\`
503 3. Make your changes
504 4. Run tests: \`pytest\`
505 5. Format code: \`ruff format\`
506 6. Lint code: \`ruff check\`
507
508 ## Contributing
509
510 We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
511
512 ## License
513
514 Apache License 2.0
515
516 ## Support
517
518 For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
519 EOL
520
521 # Make the script executable
522 chmod +x "$PROVIDER_PATH/${PROVIDER_NAME}_demo.py"
523
524 echo "✨ Created new ${IS_AGENTIC:+agentic }provider at $PROVIDER_PATH"
525 echo "✨ Provider structure:"
526 echo " 📁 $PROVIDER_PATH/"
527 echo " ├── 📄 README.md"
528 echo " ├── 📄 pyproject.toml"
529 echo " ├── 📄 setup.py"
530 echo " ├── 📄 ${PROVIDER_NAME}_demo.py"
531 echo " └── 📁 $PACKAGE_NAME/"
532 echo " ├── 📄 __init__.py"
533 echo " ├── 📄 provider.py"
534 echo " └── 📄 py.typed"
535 echo ""
536 echo "🚀 Next steps:"
537 echo " 1. cd $PROVIDER_PATH"
538 echo " 2. Update provider.py with your implementation"
539 echo " 3. Install in development mode: uv pip install -e ."
540 echo " 4. Test your provider: python ${PROVIDER_NAME}_demo.py"