<< All versions
2. Define Tool API (
3. Implement Details (
Skill v1.0.0
currentAutomated scan100/100gradion-ai/freeact/saving-codeacts
──Details
PublishedApril 27, 2026 at 10:25 PM
Content Hashsha256:0940a92f788d48cb...
Git SHA288a537271a0
──Files
Files (1 file, 2.8 KB)
SKILL.md2.8 KBactive
SKILL.md · 108 lines · 2.8 KB
version: "1.0.0" name: saving-codeacts description: Save executed Python code as reusable tools in the gentools package. Use when preserving successful code executions for later reuse. Covers creating package structure (api.py, impl.py), defining Pydantic output models, and implementing the run() interface.
Saving Code Actions as Reusable Tools
Save executed Python code as a tool for later reuse.
Package Structure
{generated_rel_dir}/gentools/<category>/<tool>/├── __init__.py # Empty file├── api.py # Public interface with structured models└── impl.py # Implementation details
Procedure
1. Create Package Directory
bash
mkdir -p {generated_rel_dir}/gentools/<category>/<tool>
Create empty __init__.py files in both <category> and <tool> directories.
2. Define Tool API (api.py)
python
from __future__ import annotationsfrom pydantic import BaseModel, Fieldclass OutputModel(BaseModel):"""Description of output."""field: type = Field(..., title="Description")def run(param1: type, param2: type = default) -> OutputModel:"""Tool description.Args:param1: Descriptionparam2: Description (default: value)Returns:OutputModel with structured data"""from .impl import implementation_functionreturn implementation_function(param1, param2)
Requirements:
- Define Pydantic models for structured output
- Create
run()function with typed parameters - Use lazy import from
impl.pyinsiderun() - Include comprehensive docstring
- Export
OutputModelandrunin{generated_rel_dir}/gentools/<category>/<tool>/__init__.py:
python
from .api import OutputModel, run__all__ = ["OutputModel", "run"]
3. Implement Details (impl.py)
python
from __future__ import annotationsfrom mcptools.<category>.<tool> import Params, run_parsedfrom .api import OutputModeldef implementation_function(param1: type, param2: type) -> OutputModel:"""Implementation description."""# Use tools from mcptools or gentools packagesresult = run_parsed(Params(...))# Transform and return structured outputreturn OutputModel(field=result.data)
Requirements:
- Import tools from
mcptoolsorgentoolspackages - Import models from
api.py - Return structured models defined in
api.py
4. Test the Tool
python
from gentools.<category>.<tool>.api import runresult = run(param1=value1, param2=value2)print(result)
Best Practices
- Separation: Keep API clean; hide complexity in implementation
- Type Safety: Use Pydantic models for all outputs
- Modularity: Break complex logic into smaller functions
- Defaults: Provide sensible defaults for optional parameters