add_top_level
Insert top-level code such as functions, classes, or constants into a file. Place content at the top or bottom to avoid reverse-order issues when adding multiple declarations.
Instructions
Insert top-level content into the file: a function, class, constant, type
alias, or any other top-level statement. position controls placement:
"bottom" (default): append to end of file.
"top": insert after the preamble (package/imports/includes/leading comments, plus the Python module docstring if present) and before the first real declaration.
Use this when: You're adding any kind of top-level code. Use position="top"
when inserting multiple declarations at the top of a file without the
insert_before <target> reverse-order problem.
Don't use this when: You need placement relative to a specific symbol ->
use insert_before / insert_after. You're adding to a class body -> use
add_method / add_field. You're adding a line inside an existing
function body -> use prepend_to_body / append_to_body.
Example: content="def parse_version(text):\n return tuple(int(x) for x in text.split('.'))" content="class Logger:\n pass", position="top" content="MAX_CONNECTIONS = 10", position="top"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| content | Yes | ||
| position | No | bottom |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |