Mantis Coding
Mantis Coding is a notebook that runs inside the space. Its Python kernel starts with the space’s points and clusters already loaded, and its code can drive the workspace: create bags, open panels, and render custom React widgets into the app. It is the escape hatch for anything the analysis panels do not cover.
Where to find it
View → Quantitative → Mantis Coding. It is in the default panel set, and the Quantitative Analysis and Coding layout presets both include it. The panel header reads “Coding Notebooks”.
Cell types
| Cell | Language | What it is for |
|---|---|---|
| Code | Python 3.10 | Data work. Everything that manipulates points, bags, and the UI runs here. |
| UI/TSX | TypeScript + React | One exported React functional component, which becomes a Python class you can instantiate. |
| Markdown | Markdown | Notes. Toggle between editing and preview from the cell toolbar. |
Add Code, Add UI/TSX, and Add Markdown at the bottom append a cell; the same three buttons appear between cells to insert in place. Code and UI cells have a run button; markdown cells do not.
The Python environment ships with numpy, pandas, scikit-learn, matplotlib, seaborn, scipy, xgboost, and dill. Importing anything else from PyPI installs it on demand.
What the kernel already knows
Two variables are preloaded in every Code cell:
points, a list-likePointscollection. Index and slice it like a list, calllen(points),points.ids(),points.to_dict(). EachPointcarriesid,title,date,metadata,links,embedding,summary,keywords,cluster_id, andlayer_id.clusters, aClusterscollection whose members carryid,parent,depth,label,color,summary, andkeywords.
Heads up
point.metadata is not always the flat column map. Newer spaces wrap it in an envelope with field_types, semantic_fields, and values, and the columns live under metadata["values"]. Read it defensively:
def point_values(metadata):
if isinstance(metadata, dict) and "values" in metadata:
return metadata["values"]
return metadata
vals = point_values(points[0].metadata)Driving the workspace from a cell
Two helper classes are available in Code cells:
UI.openPanel(name)andUI.closePanel(name)take a name from thePanelsclass.UI.addWidget(instance)renders a component defined in a UI cell.Map.addBag(name, points)creates a bag and shows it on the map.Map.selectBagsByName(names)highlights existing bags.Map.searchPoints(points, **kwargs)filters aPointsobject by attribute or metadata field.printv(points)is shorthand forMap.addBag("Python Variable View", points).
A UI cell must export exactly one React.FC. Its props become the positional arguments of the generated Python class, keyword arguments are not supported, and you instantiate it in a Code cell and pass the instance to UI.addWidget.
Notebook management
The sidebar lists your notebooks and a Public Notebooks section you can open read-only copies from. The header carries the rest:
- Restart Kernel, New Notebook, and Import Vertical Bundle (
.mantisxor.zip). - Export Session and Load Session serialize the live kernel state to and from an
.mbsfile, so variables survive a move between machines. - Share opens Share a Copy: enter a recipient’s email, tick which checkpoints to include, and send them their own copy.
- Remote Agent opens Remote Compute Setup, which hands you a broker token, a user id, and a ready-made broker command to run on your own machine, then Connect. While it is attached, a green Remote badge sits next to the notebook title.
- Checkpoints opens the Checkpoint Manager: name and create a checkpoint of the current session, then load or delete it later.
Beside the notebook title:
- Add as Vertical publishes the notebook as a Vertical, launchable from the Verticals menu. It requires exactly one UI/TSX cell and refuses otherwise; while a notebook is a Vertical, you cannot add a second UI cell. Press it again to remove Vertical status.
- The download button exports the Vertical as a
.mantisxbundle. - The GitHub button opens a strip that creates a public repository for the notebook and commits to a branch you name. The notebook has to be renamed away from “Untitled” first. When a notebook came from someone else’s repository, a banner links back to the original.
- Open in VSCode fetches an auth token and hands the session to the
mantisai.mantis-notebooksextension. While VS Code is attached, cells in the browser go read-only and say so. - Help opens the built-in guide, which links out to a Mantis Coder GPT for drafting notebook code. The link pins
?model=gpt-4oeven though the text beside it recommends a newer model, so change the model once ChatGPT opens.
Agents and notebooks
The notebook does not call agents. It works the other way around: the Composer and installed extensions add, update, run, and delete notebook cells and read the notebook’s status through the Mantis SDK, and an agent’s work in the Composer shows up here when you press Open in Notebooks in the Analysis Report panel.
Limits
- Python only for execution. UI cells are React, not a second data language.
- One notebook is active at a time, and the kernel belongs to that notebook.
- There is no macro recording here. Macros are their own panels; see Macro Editor.
- Cells reach the current selection, bags, and points. There is no accessor for the map’s filter state.
- Vertical publishing is gated on exactly one UI cell; export refuses for the same reason.