Refactor CodeInterpreterTool to Support Pluggable Container Managers and Add Podman Support #104
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
All these changes were made by o1-preview model from OpenAI.
https://chatgpt.com/share/66e8e625-942c-800d-aec3-ea363441fd5c
Overview
This PR refactors the
CodeInterpreterTool
to make it more flexible and extensible by:DockerContainer
andPodmanContainer
) that implement a commonContainerManager
interface.CodeInterpreterTool
.These changes enable the
CodeInterpreterTool
to work with different container technologies and allow users to implement custom container management strategies if needed.Changes
1. Introduced
ContainerManager
InterfaceCreated an abstract base class
ContainerManager
that defines the interface for container managers:2. Extracted Docker Logic into
DockerContainer
Moved all Docker-related operations into a separate class
DockerContainer
that implementsContainerManager
:3. Added
PodmanContainer
for Podman SupportImplemented a
PodmanContainer
class to support Podman, following the same interface:4. Updated
CodeInterpreterTool
to UseContainerManager
Modified
CodeInterpreterTool
to accept acontainer_manager
parameter, allowing users to specify which container strategy to use:5. Updated README
Revised the README to explain how to use the new container strategy mechanism, including examples for using Docker, Podman, and custom container managers.
6. Adjusted Import Statements
Modified import statements to reflect the correct package structure and directory hierarchy, ensuring that modules are imported correctly within the
crewai_tools
package.Benefits
ContainerManager
interface, it's easy to add support for other container technologies in the future.Usage Examples
Using Docker (Default)
Using Podman
Using a Custom Container Manager
Testing and Compatibility
CodeInterpreterTool
with both Docker and Podman container managers.Notes
docker
Python library is installed (pip install docker
).podman
Python library is installed (pip install podman
).__init__.py
files.crewai_tools/tools/code_interpreter_tool/
.Conclusion
This PR enhances the
CodeInterpreterTool
by making it more flexible and extensible. Users can now choose their preferred container technology or implement custom container managers, improving adaptability to different environments and use cases.