001_smolAgent / tools /request_new_tool.py
jkorstad's picture
Update tools/request_new_tool.py
3bb3ea4 verified
from typing import Any
from smolagents.tools import Tool
class RequestNewTool(Tool):
name = "request_new_tool"
description = "Request a new tool when no existing tool can complete the required task. Provides a suggested implementation."
inputs = {
'task_description': {'type': 'string', 'description': 'Description of what the new tool needs to do'},
'proposed_inputs': {'type': 'string', 'description': 'Description of what inputs the tool would need'},
'proposed_output': {'type': 'string', 'description': 'Description of what the tool would return'},
'implementation_suggestion': {'type': 'string', 'description': 'Suggested Python code for implementing the tool'},
'required_packages': {
'type': 'string',
'description': 'List of required packages for this tool',
'nullable': True, # Added this line
'default': None # Added this line
}
}
output_type = "string"
def forward(self, task_description: str, proposed_inputs: str, proposed_output: str,
implementation_suggestion: str, required_packages: str = None) -> str:
packages_section = f"\n**Required Packages:**\n{required_packages}" if required_packages else ""
template = f"""
### New Tool Request
I cannot complete this task because I need a tool for: {task_description}
**Proposed Implementation:**
Copy
from typing import Any from smolagents.tools import Tool
class NewTool(Tool): name = "[appropriate_name]" description = "{task_description}" inputs = {proposed_inputs} output_type = "{proposed_output}"
def forward(self, [arguments]) -> {proposed_output}:
Copy
{implementation_suggestion}
def __init__(self, *args, **kwargs):
self.is_initialized = False
Copy
Would you like me to proceed with this implementation? Once implemented, I can complete your requested task.
"""
return template
def __init__(self, *args, **kwargs):
self.is_initialized = False