Skip to content
Agent Orchestration
Skill

/saving-codeacts

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.

BOOST
From plugin
freeact
1303 skills
Install
$ npx -y skills add gradion-ai/freeact --skill saving-codeacts --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.
  • Slash command/saving-codeacts

Context preview

The summary Claude sees to decide when to auto-load this skill.

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.

SKILL.md

saving-codeacts.SKILL.md
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

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`)

from __future__ import annotations

from pydantic import BaseModel, Field


class OutputModel(BaseModel):
    """Description of output."""
    field: type = Field(..., title="Description")


def run(param1: type, param2: type = default) -> OutputModel:
    """Tool description.

    Args:
        param1: Description
        param2: Description (default: value)

    Returns:
        OutputModel with structured data
    """
    from .impl import implementation_function
    return implementation_function(param1, param2)

Requirements:

  • Define Pydantic models for structured output
  • Create `run()` function with typed parameters
  • Use lazy import from `impl.py` inside `run()`
  • Include comprehensive docstring
  • Export `OutputModel` and `run` in `{generated_rel_dir}/gentools/<category>/<tool>/__init__.py`:
from .api import OutputModel, run

__all__ = ["OutputModel", "run"]

3. Implement Details (`impl.py`)

from __future__ import annotations

from mcptools.<category>.<tool> import Params, run_parsed
from .api import OutputModel


def implementation_function(param1: type, param2: type) -> OutputModel:
    """Implementation description."""
    # Use tools from mcptools or gentools packages
    result = run_parsed(Params(...))

    # Transform and return structured output
    return OutputModel(field=result.data)

Requirements:

  • Import tools from `mcptools` or `gentools` packages
  • Import models from `api.py`
  • Return structured models defined in `api.py`

4. Test the Tool

from gentools.<category>.<tool>.api import run

result = 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
Read more
Ships withfreeact

General-purpose AI agent that acts via code actions through a unified execution interface.

Get the whole plugin
Stats
130
Stars
10
Forks
Maintained
Maintenance
Python
Language
Apache-2.0
License
3mo ago
Last commit
1y ago
Created
19h ago
Added

Repo: gradion-ai/freeact

Other skills on freeact.