QuantLink AI · AI Agents

An AI notebook agent that checks its own work.

Kanav Mehta built a grounded, self-checking AI agent that writes and edits research notebook cells against a live Python kernel. Before an edit can be applied, the agent parses the code, validates every SQL query and grounds it to the real datasets, and checks its numbers against cited evidence. He also built the runtime underneath: isolated kernels, signed and renewable access grants, live recovery, and a digest-pinned production executor.

No edit lands unchecked.

The model proposes code; deterministic checks decide whether it can be applied.

  • Every proposal and edit is parsed as Python, held to the notebook cell contract, and each static SQL query is validated with the data layer's own guard and grounded to the dataset that publishes it. Failures return to the model with the exact problems so it repairs and retries: a JOIN on an unpublished table is refused, never guessed at.
  • Grounded in what actually exists: token-scored search over a hash-sealed manifest of 725 analytics operators, warehouse discovery that reads catalog metadata without fetching data, and numeric grounding that matches reported figures to cited evidence by exact Decimal comparison.
  • Context engineering under a hard five-tool budget: a code-first notebook index capped at 3,072 bytes and 20 cells per turn, plus a read tool that returns complete cell source.

A runtime built for untrusted code.

Agent-written code runs in real Jupyter kernels, so every run is isolated and every credential is short-lived.

  • Isolated runs: each gets a fresh kernel and a private workspace with its own home and cache directories, under a signed grant bound to the run, the notebook and its exact revision. The service authenticates before reading any request body and caps envelopes at 33 MiB.
  • Renewable access without leaks: data grants live 20 minutes and refresh at 15, delivered into a running kernel through a silent, history-free execution and masked in all output, so credentials never surface in a notebook.
  • Recovery without surprises: live kernels survive reconnects with state intact and no cell ever replayed, while dead kernels are caught by a bounded liveness check and replaced. Streamed agent events persist with idempotent retries and replay with their original boundaries; provider rate limits retry within a strict budget (two extra requests, 10 s added wait, tools never retried).

Shipped to production, verified live.

  • Prototyped end to end, then shipped into the main product as seven scoped, independently reviewed PRs, with 477 focused tests on checked authoring alone. Over the period Kanav merged 23 PRs across the web, API, agent and database layers and reviewed 92 from teammates.
  • The production executor runs as a private, digest-pinned Docker image, built and tested in CI (including an offline real-kernel chart-rendering check) behind a release gate tested across 540 repository, ref and event combinations. Verified live: Python, Markdown, DataFrames, interactive Plotly, an authenticated data fetch, and save and reopen.
  • Notebooks reach 115 warehouse datasets, including 52 bulk datasets, through the authorized catalog, with access and plan checks first. In the flagship demo the agent builds a sector-rotation study stage by stage (universe, signal, backtest with 10 bps costs, evaluation) with six interactive Plotly charts. Executed outputs like these also power Notebook Dashboards.