Refactor Code
refactor_codeApply a requested refactoring to code while preserving its external behavior. Rename, extract methods, or convert patterns through an AI review loop.
Instructions
Apply a specific refactoring to existing code.
The local model will apply the requested transformation while preserving external API and behavior. Useful for mechanical refactors like renaming, extracting methods, converting patterns, etc.
IMPORTANT: Always review the returned code before accepting it.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The existing code to refactor. | |
| language | Yes | Programming language of the code. | |
| max_tokens | No | Max tokens override. | |
| constraints | No | Rules or restrictions for the refactor. | |
| temperature | No | Temperature override. | |
| refactor_description | Yes | What refactoring to apply — e.g. 'extract method', 'rename variables to snake_case', 'convert class to dataclass', 'split into smaller functions'. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | The generated artefact (code, tests, documentation). None on failure. | |
| error | No | Human-readable error message. None on success. | |
| success | Yes | Whether the generation completed successfully. | |
| metadata | No | Auxiliary data: token usage, elapsed time, quality warnings, etc. |