Read, search and edit algorithm source, user-authored or built-in.
Functions
read_source(name: str, version: Optional[str]=None, builtin: bool=False) -> Dict[str, Any]
Return the full source code of a user or built-in algorithm.
For user algorithms,
name is the directory name under USER_ALGS_DIR. For built-in algorithms, set builtin=True and pass the class name or file stem (e.g. 'RandomForestClassifier' or 'random_forest').Parameters
name
str
User algorithm name (or versioned alias), or a built-in class name / file stem when
builtin=True.
version
str
Pin a specific semver version of a user algorithm. When None, the newest on-disk version is used. Ignored for built-ins.
builtin
bool
= False
Look up a built-in tuiml algorithm instead of a user algorithm.
Returns
result
Dict[str, Any]
On success: keys
status, name, version, class_name, kind, path, line_count, source, and source_with_line_numbers (built-ins return builtin and note instead of version/class/kind). On failure: keys status, error_type, error.
list_algorithm_files(builtin: bool=True, user: bool=True) -> Dict[str, Any]
List all algorithm source files, built-in and/or user-authored.
Parameters
builtin
bool
= True
Include built-in algorithm files from
tuiml/algorithms/.
user
bool
= True
Include user algorithm files from
USER_ALGS_DIR.
Returns
result
Dict[str, Any]
Keys
status, count, and files: a list of dicts with type ('builtin'/'user') and path, plus relative_path/category/file for built-ins and name/version/class_name/kind for user algorithms.
search_source(query: str, name: Optional[str]=None, builtin: bool=True, user: bool=True) -> Dict[str, Any]
Grep for query across algorithm source files.
Parameters
query
str
Regular expression to search for (matched per line).
name
str
Scope the search to one user algorithm by name.
builtin
bool
= True
Include built-in algorithm files in the search.
user
bool
= True
Include user algorithm files in the search.
Returns
result
Dict[str, Any]
On success: keys
status, query, match_count, and matches (list of dicts with path, line_number, line). On invalid regex: keys status, error_type, error.
edit_algorithm(name: str, old_string: str, new_string: str, version: Optional[str]=None, bump_version: bool=False) -> Dict[str, Any]
Apply a str_replace edit to a user algorithm source.
Replaces exactly one occurrence of old_string with new_string. Fails if old_string is not found, or if it appears more than once (ambiguous, make the search string more specific in that case).
After the edit the source is AST-validated and re-registered. Optionally bumps the patch version and saves as a new file.
Parameters
name
str
User algorithm name (or versioned alias).
old_string
str
Exact text to replace; must occur exactly once in the source.
new_string
str
Replacement text.
version
str
Pin the semver version to edit. When None, the newest on-disk version is used.
bump_version
bool
= False
Save the edited source as a new patch version instead of overwriting in place.
Returns
result
Dict[str, Any]
On success: keys
status, name, version, previous_version, class_name, path, source_hash, registered_as (list of aliases), and note. On failure: keys status, error_type, error.