A powerful framework for providing tools to AI agents with Docker/local deployment support
Project description
aicodetools
A powerful framework for providing tools to AI agents with Docker/local deployment support.
CodeInstance is a class that wraps deployment environments (Docker/local) and provides various code tools to AI agents including file operations, bash sessions, search capabilities, and more.
Installation
You can install the package using pip:
pip install aicodetools
Or for development:
pip install -e .
Quick Start
from aicodetools import CodeInstance
# Create instance with Docker environment
config = {
'docker': {
'image': 'python:3.12',
},
'tool_config': {}
}
# ~~
class DockerDeploymentConfig(BaseModel):
"""Configuration for running locally in a Docker container."""
image: str = "python:3.11"
"""The name of the docker image to use."""
port: int | None = None
"""The port that the docker container connects to. If None, a free port is found."""
docker_args: list[str] = []
"""Additional arguments to pass to the docker run command. If --platform is specified here, it will be moved to the platform field."""
startup_timeout: float = 180.0
"""The time to wait for the runtime to start."""
pull: Literal["never", "always", "missing"] = "missing"
"""When to pull docker images."""
remove_images: bool = False
"""Whether to remove the image after it has stopped."""
python_standalone_dir: str | None = None
"""The directory to use for the python standalone."""
platform: str | None = None
"""The platform to use for the docker image."""
remove_container: bool = True
"""Whether to remove the container after it has stopped."""
type: Literal["docker"] = "docker"
"""Discriminator for (de)serialization/CLI. Do not change."""
model_config = ConfigDict(extra="forbid")
# Create and start the instance
instance = CodeInstance('docker', config, auto_start=True)
# Get specific tools for your agent
tools = instance.get_tools(include=['read_file', 'write_file', 'run_command'])
# Use with your AI agent framework (e.g., Swarms)
from swarms import Agent
agent = Agent(
agent_name="CodingAgent",
system_prompt="You are a helpful coding assistant with file and command tools.",
tools=tools
)
# Clean up when done
instance.stop_sync()
Available Tools
The CodeInstance provides access to these tools:
- File Operations:
read_file,write_file,edit_file - Directory Operations:
list_directory - Command Execution:
run_command,run_bash_session,create_bash_session - Code Analysis:
format_code,analyze_project_structure,get_file_dependencies - Search Operations:
glob_files,grep_files,find_references
Usage Examples
Basic Usage (Async)
import asyncio
from aicodetools import CodeInstance
async def example_usage():
config = {
'docker': {'image': 'python:3.12'},
'tool_config': {}
}
# Using async context manager (recommended)
async with CodeInstance('docker', config) as instance:
print(f"Started CodeInstance with {instance.get_deployment_type()} deployment")
# Get available tools
tools = instance.get_available_tools()
print(f"Available tools: {len(tools)}")
# Get wrapped tools for your agent
wrapped_tools = instance.get_tools(include=['read_file', 'write_file', 'list_directory'])
print(f"Wrapped tools: {len(wrapped_tools)}")
asyncio.run(example_usage())
Agent Integration Example
from dotenv import load_dotenv
from swarms import Agent
from swarms.structs import Conversation
from aicodetools import CodeInstance
load_dotenv()
def create_coding_agent_with_tools():
"""Create a coding agent with read, write, and run_command tools using Docker"""
config = {
'docker': {
'image': 'python:3.12',
},
'tool_config': {}
}
# Create CodeInstance with auto_start=True to immediately get tools
instance = CodeInstance('docker', config, auto_start=True)
# Get the three main tools: read, write, run_command
tools = instance.get_tools(include=['read_file', 'write_file', 'run_command'])
# Create the coding agent with tools
coding_agent = Agent(
agent_name="CodingAgent",
system_prompt="""You are a helpful coding agent with access to file operations and command execution in a Docker container.
You can:
1. Read files to understand code structure
2. Write/modify files to implement features
3. Run commands to test and execute code
You are running in a Python 3.12 Docker container environment.
Always be careful with file operations and command execution.""",
model_name="gemini/gemini-2.0-flash",
max_loops=3,
max_tokens=4096,
temperature=0.3,
output_type="str",
tools=tools
)
return coding_agent, instance
# Create and use the agent
agent, instance = create_coding_agent_with_tools()
# Run a task
response = agent.run("Create a simple Python script called 'hello_world.py' that prints 'Hello, World!' and then run it")
print(response)
# Clean up
instance.stop_sync()
Features
- Docker & Local Deployment: Run tools in isolated Docker containers or local environment
- Tool Statistics: Track tool usage and performance metrics
- Async Support: Full async/await support with context managers
- Safety Features: Read-before-write protection for file operations
- Agent Integration: Works seamlessly with AI agent frameworks like Swarms
- Comprehensive Tools: 14+ built-in tools for file operations, command execution, and code analysis
Requirements
- Python 3.10+
- Docker (for Docker deployment)
- Dependencies: swarms, swerex
Development
Code Quality 🧹
make styleto format the codemake check_code_qualityto check code quality (PEP8 basically)black .ruff . --fix
Tests 🧪
pytests is used to run our tests.
Publishing 🚀
poetry build
poetry publish
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aicodetools-0.1.5.tar.gz.
File metadata
- Download URL: aicodetools-0.1.5.tar.gz
- Upload date:
- Size: 40.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.0 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21567ea79a77f5b0b8beaa14d24db0cee8a68c9c92e3c8ee86c7244580f50a19
|
|
| MD5 |
c2f6b5eee5012c66a3d0e959a2e7003f
|
|
| BLAKE2b-256 |
e4c52ebb0cc041bd96dfdc11797ea6ae2297d9949b6c7bc4e2cb93f8156fc2be
|
File details
Details for the file aicodetools-0.1.5-py3-none-any.whl.
File metadata
- Download URL: aicodetools-0.1.5-py3-none-any.whl
- Upload date:
- Size: 44.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.0 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37135f8bc80947935e1a6239fb2cc36274e0e2b287dee341bc00d9929f015a0d
|
|
| MD5 |
66504f834eca1afa9a371ba29ee0388a
|
|
| BLAKE2b-256 |
23ff4d48afa6aad4c4f8a6d96400fc28eff7822761582bcb855ab01d0a3e32d5
|