Python SDK Integration
This guide walks you through the process of integrating third-party Python frameworks with Composio. By creating these integrations, you enable Composio’s tools to work seamlessly with popular AI/ML frameworks.
Understanding the integration pattern
When integrating a Python SDK with Composio, you’re essentially creating a bridge between:
- Composio’s tool schema and execution model - How Composio represents and calls tools
- The target framework’s tool representation - How the framework defines and calls tools
An integration primarily handles the transformation of tool schemas and execution flows between the two systems, while preserving all the capabilities and data.
Prerequisites
Before you begin, make sure you have:
- Basic understanding of Python and object-oriented programming
- Familiarity with the Composio platform
- Knowledge of the target framework you want to integrate
- Python 3.9+ installed on your development machine
Step-by-step integration process
Setup your environment
First, fork and clone the Composio repository:
Then navigate to the plugins directory:
Create a new directory for your integration:
Create the basic structure
Every integration requires at least these files:
__init__.py
- Exports your module’s componentstoolset.py
- Contains the core integration logicsetup.py
- Package configuration for installationREADME.md
- Documentation for your integration
Implement the toolset.py
File
This is the heart of your integration. Here’s a template to follow:
Code Standards and Quality
For comprehensive guidance on code formatting, linting, testing, and development practices, please refer to the Development.md
file in the Python project’s docs directory. This file contains detailed instructions on environment setup, code conventions, and all the commands needed for maintaining code quality.
Common challenges and solutions
When creating an integration, you might encounter these challenges:
Pay special attention to data type conversions between systems. This is the most common source of bugs in integrations.
Type compatibility issues
Problem: The framework expects different data types than what Composio provides.
Solution:
Schema format differences
Problem: The framework has a different JSON schema format than Composio.
Solution: Add required properties to match the framework’s expectations. For example:
String vs. object returns
Problem: Many frameworks expect string outputs from tool calls, while you want to preserve structured data.
Solution: Use JSON serialization to preserve structure:
Tool naming restrictions
Problem: The framework has restrictions on tool names or descriptions.
Solution: Implement transformation logic:
Real-world example: OpenAI Agents Integration
Below is a concrete example of integrating the OpenAI Agents framework with Composio:
The OpenAI Agents framework expects strings for tool outputs, has specific JSON schema requirements, and needs custom wrapping of tool functions.
Here’s the key implementation for _wrap_tool
in this integration:
Testing your integration
Always test your integration thoroughly:
- Unit Tests: Test individual components like parameter transformation
- Integration Tests: Test the full flow from Composio to framework and back
- End-to-End Testing: Run a complete scenario with a real API call
Example test structure:
Best practices for SDK integration
- Preserve Data Fidelity: Ensure data structures are properly converted between systems
- Handle Errors Gracefully: Provide clear error messages and follow both systems’ error patterns
- Document Edge Cases: Note any limitations or special considerations in your README
- Type Safety: Use proper type annotations and handle type conversions carefully
- Minimal Dependencies: Don’t add unnecessary dependencies to your integration
- Comprehensive Examples: Include examples for all common use cases
The best integrations are those that feel native to both systems, requiring minimal special handling by users.
Contribution and maintenance
After creating your integration:
- Documentation: Write clear documentation with examples
- Tests: Ensure comprehensive test coverage
- Pull Request: Submit a PR to the Composio repository
- Maintenance: Monitor compatibility with new versions of both Composio and the target framework
Conclusion
Creating a Python SDK integration for Composio allows users to leverage Composio’s rich tool ecosystem within their preferred frameworks. By following this guide, you can create robust, type-safe, and user-friendly integrations that enhance the power of both systems.
Remember that a good integration should feel natural to users of both Composio and the target framework, requiring minimal adaptation of their existing code.