API Reference / agent / tools / notebook /

translate.py

Translate recorded MCP calls into notebook cells.

Functions

Func

user_algorithm_prelude

Line 374
user_algorithm_prelude(calls: List[Dict]) -> List[tuple]

Build definition cells for user algorithms the session only used.

_SESSION_CALLS holds one MCP session, but a user algorithm outlives it: authored in an earlier conversation, it lives in ~/.tuiml/user_algorithms/ and is re-registered at server startup, so a later session can train on it without ever calling tuiml_create_algorithm. Nothing in that session's calls carries the source, so the exported notebook would name an algorithm it never defines and fail with "not found in hub". Reading the source off disk at export time closes that gap.

Parameters

calls
list of dict
The session's recorded calls.

Returns

cells
list of tuple
(markdown_lines, code_lines) pairs, one per algorithm, in first use order. Empty when every referenced algorithm is built in or is already defined by an authoring cell.