Repository navigation
feat: carry assistant skills into Colab notebooks via Gemini instructions #324
Description
Overview
Colab's Gemini sidebar cannot read the assistant repositories, but Colab stores per-notebook Gemini instructions in .ipynb metadata (metadata.colab.aiContexts + selectedAiContext, recovered from Google's Learn Mode example notebooks). Human tests on 2026-10-26 confirmed Colab honours hand-written entries on upload and accepts contexts up to at least 52k characters. This task writes folder-matched assistant skills into every generated workspace/HowTo notebook, so Colab's Gemini starts each notebook with the relevant assistant knowledge and rules.
Plan
- Skills stay in the assistants (single source); notebooks carry a release-time snapshot in hidden metadata. Workspace
.pyscripts and skill files are untouched. - Each assistant owns
colab/contexts.yaml: notebook path glob → skills, plus a Colab preface and core rules (stay with the notebook's API, real-data check for lens/galaxy, never claim code ran, ask one focused question, point to the assistant for bigger work). - PyAutoHands assembles that text at notebook generation and writes it as the notebook's active Gemini instruction. Cap 20k characters per notebook; over-cap or a missing mapping fails generation loudly, never truncates.
- The release workflow checks out the matching assistant read-only for the generate step.
- autolens_assistant's COSMOS-Web Ring notebook gets the cosmos greeting skill the same way.
- PyAutoHands also exposes the injector as a standalone command over any notebooks folder, used for CTI (outside the Hands release generate).
- Phase 1: PyAutoHands + autolens_assistant; human opens the cosmos notebook from the PR branch via a Colab GitHub URL to confirm the GitHub route. Phase 2: autogalaxy_assistant + autofit_assistant mappings. Phase 3: autocti_assistant mapping + autocti_workspace notebooks via the command.
- Follow-ups: full CTI-on-Colab (setup cell, arctic install, release matrix) as its own task; AI options page line after release.
Tier: glance declared, overridden by the human to human /prm (merge needs the human Colab check). Heart RED: human development-only override recorded 2026-10-26 (red reasons are release-integrate / workspace smoke autolens scripts/group/slam.py / worktree drift — none touch this change).
Detailed implementation plan
Affected Repositories
- PyAutoHands (primary)
- autolens_assistant (phase 1)
- autogalaxy_assistant, autofit_assistant (phase 2)
- autocti_assistant, autocti_workspace (phase 3)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./organs/PyAutoHands | main | clean |
| ./lens/autolens_assistant | main | 1 untracked (kept schematic PNG, not touched) |
Suggested branch: feature/colab-gemini-instructions
Implementation Steps
autolens_assistant/colab/contexts.yaml(new):preface,rules, andcontexts:list of{match: <glob over "<repo>/<notebook path>">, skills: [..]}, most-specific match wins, requireddefault. Covers autolens_workspace folders (imaging, imaging/data_preparation, interferometer, point_source, group, cluster, multi_galaxy, multi_dataset, weak, guides/*) and HowToLens chapters.- autolens_assistant check (test or
scripts/checker wired to existing CI): every mapped skill exists; every assembled context ≤ 20,000 chars. PyAutoHands/autohands/build_util.py:COLAB_ASSISTANTS(project → assistant repo name: autolens/howtolens → autolens_assistant, etc.);gemini_context_from(assistant_root, project, notebook_relpath)assembles preface + rules + "You are in of " + mapped skill text;inject_gemini_instructions(notebook_path, project, assistant_root)writesmetadata.colab.aiContexts[<uuid5(project)>]= {id, name, context} andselectedAiContext, idempotent, applied to every generated notebook (incl. prose-only and hand-written-setup ones). Over 20k → raise naming the mapping entry.
3b.autohands/gemini_context.pyCLI (andbin/autohands gemini-context <notebooks_dir> --project <p> --assistant-root <path>): walks a notebooks tree and appliesinject_gemini_instructions; used by phase 3.generate.py/generate_autofit.py: resolve assistant root from--assistant-root/PYAUTO_ASSISTANT_ROOT, else Brainagents/_repo_paths.py; fail if unresolved for a project inCOLAB_ASSISTANTS..github/workflows/release.ymlgenerate job: extra anonymous read-onlyactions/checkoutof the matching assistant atmain(matrix fieldassistant:), passed viaPYAUTO_ASSISTANT_ROOT.skills/pre_builddoc line for the local path.tests/test_inject_colab_setup.py(+ newtests/test_gemini_instructions.py): metadata present + selected, fixed uuid5, idempotent, prose-only gets it, path in text, most-specific match, default fallback, cap raises, missing mapping raises; fixture assistant tree under tests.- autolens_assistant
autoassistant/to_notebook.py: optional--gemini-context <skill/mapping key>writing the same metadata; Makefilecolabtarget passes it; one-off metadata-only patch of committeddocs/colab/cosmos_web_ring_colab.ipynb(diff must touchmetadataonly). - Validation: Hands pytest; generate one workspace into a scratch copy and inspect sizes/JSON; human Colab GitHub-URL check on the cosmos notebook at the PR branch.
- Phase 3:
autocti_assistant/colab/contexts.yaml+ checker (autocti_workspace; CTI-specific real-data rule from the assistant's safety invariants), then an autocti_workspace PR applying the CLI to its 79 notebooks (metadata-only diff). - Phase 2:
colab/contexts.yaml+ checker in autogalaxy_assistant (autogalaxy_workspace, HowToGalaxy) and autofit_assistant (autofit_workspace, HowToFit; no real-data rule).
Key Files
PyAutoHands/autohands/build_util.py—inject_colab_setup, new Gemini helpersPyAutoHands/autohands/generate.py,generate_autofit.py— callersPyAutoHands/.github/workflows/release.yml— generate job checkoutautolens_assistant/colab/contexts.yaml— mapping (new)autolens_assistant/autoassistant/to_notebook.py,Makefile,docs/colab/cosmos_web_ring_colab.ipynb
Original Prompt
Click to expand starting prompt
Carry assistant context into every Colab notebook via Gemini Custom Instructions
Type: docs
Target: pyautohands
Repos:
- PyAutoHands
- autolens_assistant
- autofit_assistant
- autogalaxy_assistant
- autocti_assistant
- autocti_workspace
Difficulty: medium
Autonomy: supervised
Priority: medium
Filed: 2026-10-23
Status: formalised
Blocked-by: none (upload + size gates passed 2026-10-26; GitHub-route gate verified on the PR branch)
Consequence: glance
@pyautohands @autolens_assistant @autogalaxy_assistant @autofit_assistant @autocti_assistant
Request (human, 2026-10-23)
i dont expect the assistant link to be agentic but if it can leverage the assistant repo to make the AI better thats the goal. [...] I am open to all workspace notebooks doing it if its easy to implement and worth it.
Context
- Colab's Gemini sidebar cannot read a repository. Today only two notebooks leverage the assistant: autofit's experimental Colab notebook clones the assistant at a pinned tag and prints an AGENTS.md excerpt + modes + eight skills for the user to paste into the sidebar (retired by feat: add live URL audit to CI (weekly cron + per-repo allowlist + tracking issue) #87); autolens's COSMOS-Web Ring notebook only adds "Ask Gemini:" questions. None of the ~600 generated workspace/HowTo notebooks mention the assistant.
- Colab added per-notebook Custom Instructions on 2026-04-08: "stored directly within your notebook", "when you share your notebook ... those instructions travel with it" (https://blog.google/innovation-and-ai/technology/developers-tools/colab-updates/). The
.ipynbmetadata key is undocumented. - Every generated notebook already passes through
PyAutoHands/autohands/build_util.py::inject_colab_setup, so a metadata write there covers all workspaces and HowTo repos at the next release.
Finding (2026-10-26): metadata key recovered without the UI
Human's first Colab attempt found no "Custom Instructions" input. Google's own Learn Mode
example notebooks (linked from the colab-updates blog post; Drive ids
1Tes-C6WNL99HKx4Ghg9ckGYSWRLxn-CA and 1Y39sN0zqWvFDY3o6EPu1J0BcTiqPUhp4) carry the key:
"metadata": {"colab": {
"selectedAiContext": "<uuid>", // or the built-in "learn_mode"
"aiContexts": {"<uuid>": {"id": "<uuid>", "name": "Pirate Mode", "context": "Talk like a pirate"}}
}}So inject_colab_setup can write the instructions directly; the UI is not needed to author them.
The gate is now: does Colab apply a hand-written aiContexts entry (a) on File > Upload and
(b) via a GitHub badge? Test notebook built in session scratch (colab_ci_test.ipynb, "zebra" probe).
The UI control is a toggle/selector in the Gemini chat box, not a settings page.
Gate (a) PASSED 2026-10-26 (human): uploaded colab_ci_test.ipynb, Gemini replied with "zebra" —
Colab honours a hand-written aiContexts entry. Remaining: (b) GitHub-badge route.
Gate (human, ~5 min)
- Open any notebook in Colab, add a Custom Instruction (e.g.
PYAUTO_TEST please mention the word zebra in every reply), save to the notebook, confirm a reply says zebra. - Download the .ipynb; run
python3 -I <scratch>/colab_diff.py <downloaded> <original>to find the metadata key and size. - Push a copy to a scratch branch and open it via a Colab badge; confirm the instruction still applies (GitHub route).
- Optional: after the setup cell runs, ask Gemini whether it can see a file in the cloned workspace.
Size gate PASSED 2026-10-26 (human): 2,254-word (18.7k chars) and 6,349-word (52.4k chars) contexts
both honoured, end-of-text probe word returned → Colab accepts large instructions.
Scope (human-approved 2026-10-26, supersedes the short-block plan)
- Skills stay in the assistants (single source). Generated
.ipynbmetadata carries a release-time
snapshot; workspace.pyscripts and skill files are untouched. - Each assistant owns
colab/contexts.yaml: workspace/HowTo path glob → ordered skill list (most specific
wins, default entry), plus a Colab preface ("written for a coding agent with the repo; in Colab ignore
repo-file/hook/terminal steps") and the core rules (stay with the notebook's API, real-data gate for
lens/galaxy, never claim code ran, one focused question, point to the assistant for heavy work).
The assistant's CI checks every mapped skill exists. - Hands
build_utilassembles preface + rules + mapped skills and writesmetadata.colab.aiContexts/
selectedAiContext(deterministic uuid5 per project, idempotent), for every generated notebook incl.
prose-only ones. Cap 20k chars per notebook (human choice): over-cap fails generation naming the
mapping entry — never truncates. Missing assistant mapping fails loudly. release.ymlgenerate job adds a read-only checkout of the matching assistant; localgenerate.py
resolves it via Brain's repo-path resolver or an explicit argument/env var.- autolens_assistant
docs/colab/cosmos_web_ring_colab.ipynbgets the cosmos greeting skill the same way
(build step + metadata-only patch of the committed notebook, no re-execution). - Human 2026-10-26: "done across PyAutoLens, galaxy, fit and CTI". CTI is outside the Hands release
generate (not in COLAB_PROJECTS / Nerves _PROJECTS, no setup cell), so Hands also exposes the injector as a
standalone CLI over any notebooks tree; CTI's 79 notebooks get it via an autocti_workspace PR. Full
CTI-on-Colab (setup cell, arctic install, release matrix) = separate follow-up. - Phase 1: Hands + autolens_assistant (gate (b) = human opens the cosmos notebook via a Colab GitHub URL
on the PR branch). Phase 2: autogalaxy_assistant + autofit_assistant mappings.
Phase 3: autocti_assistant mapping + autocti_workspace notebooks via the Hands CLI. - Merge: human /prm (declared glance overridden by the human-gate need). Heart RED: human dev-only
override 2026-10-26. - Follow-up after release: AI_OPTIONS.md "Colab notebooks and the assistant" paragraph.
Done when
- Regenerated notebooks carry folder-matched assistant skills (≤20k chars) as active Gemini instructions;
the cosmos notebook opened via a GitHub Colab URL yields a Gemini that follows them; phase 2 mappings
merged for galaxy and fit; phase 3 CTI notebooks carry autocti_assistant skills.
Activity
Jammy2211 commentedon Oct 26, 2026
Scope addition (human, 2026-10-26) — Phase 4: routine skill ↔ workspace upkeep. Each assistant gains a maintainer skill (
al_/ag_/af_/ac_refresh_colab_contexts) that AI-scans the workspace folder tree against the skill catalogue, proposescolab/contexts.yamlupdates when skills or folders change, and opens a PR; plus a deterministic coverage report (default-only folders, dead skill refs, per-notebook size vs the 20k cap). PyAutoBroca records linkage freshness as upkeep evidence and surfaces "refresh needed" (added to Minddraft/feature/pyautobroca/broca_communication_pilot.md); Broca never runs the scan.Also recorded: Heart RED development-only override granted by the human 2026-10-26 (red reasons: release integrate / workspace smoke
autolens scripts/group/slam.py/ worktree drift — unrelated to this change).Jammy2211 commentedon Oct 26, 2026
Heart RED development override — phase 1 shipped. Live human authorization 2026-10-26: "prm, I authorize shop on RED". Exact current RED reasons: release validation FAILED (stage integrate); PyAutoHeart/workflows/Release Integrate: failure; PyAutoHeart/workflows/Workspace Smoke: failure; manifest_drift/checks/workspace checkouts (manifest ↔ disk): red; Release readiness: release validation FAILED (stage integrate); autolens: red; Workspace validation: NOT ready — 1429p / 1f / 125s @ cloud#40294511523; test_run: red; Release validation: NOT release_ready — v? profile=? (2026-10-26T07:48:52+00:00); validation_report/stages/integrate: fail; PyAutoBrain: red; PyAutoLens: red; autolens_profiling: red; Worktree drift: 1 orphan / 0 missing / 3 dirty. Branch gates passed: PyAutoHands 558 tests; autolens_assistant 14 colab tests + mapping check; PyAutoBrain 64 clone tests + boundary check; independent review (no blockers, 4 findings fixed). No release; Heart remains RED for release.
PRs (merge in this order): PyAutoLabs/PyAutoBrain#541 → PyAutoLabs/autolens_assistant#165 (after the human Colab GitHub-route check) → #325.
fix: move Colab Gemini repo names into config/workspaces.yaml (tenant…
Merge pull request #325 from PyAutoLabs/feature/colab-gemini-instruct…
Jammy2211 commentedon Oct 26, 2026
Phase 1 merged (2026-10-26, human): PyAutoLabs/PyAutoBrain#541 → PyAutoLabs/autolens_assistant#165 → #325. Human verified in Colab: hand-written metadata on upload, 52k-char contexts, and the GitHub-URL route (cosmos notebook from the PR branch). autolens_workspace + HowToLens notebooks get folder-matched skills at the next release generate; the cosmos notebook has them now.
Remaining: phase 2 autogalaxy_assistant + autofit_assistant
colab/contexts.yaml, then fillassistant:for galaxy/fit/HowToGalaxy/HowToFit in release.yml (config names go inautohands/config/workspaces.yaml— tenant firewall); phase 3 CTI viaautohands gemini_context apply; phase 4*_refresh_colab_contextsupkeep skills + Broca linkage evidence.Jammy2211 commentedon Oct 26, 2026
Phase 2 shipped under Heart RED development override. Live human authorization 2026-10-26: "yeah I approve go". Exact current RED reasons: release validation FAILED (stage integrate); PyAutoHeart/workflows/Release Integrate: failure; PyAutoHeart/workflows/Workspace Smoke: failure; manifest_drift/checks/workspace checkouts (manifest ↔ disk): red; Release readiness: release validation FAILED (stage integrate); autolens: red; Workspace validation: NOT ready — 1429p / 1f / 125s @ cloud#40294511523; test_run: red; Release validation: NOT release_ready — v? profile=? (2026-10-26T07:48:52+00:00); validation_report/stages/integrate: fail; PyAutoBrain: red; PyAutoLens: red; autolens_profiling: red; Worktree drift: 1 orphan / 0 missing / 3 dirty. Branch gates passed: PyAutoHands 567 tests + tenant firewall; autofit_assistant 12 tests + check; autogalaxy_assistant 12 tests + check; independent review CLEAN (3 minors fixed). No release.
Human decision: per-assistant
cap:(default 20k, ceiling 50k); autogalaxy at 36,000 because ag_* skills are 21–32k each — trim follow-up filed in Mind.PRs (merge order): PyAutoLabs/autofit_assistant#59 + PyAutoLabs/autogalaxy_assistant#39 (either order) → #326.
Merge pull request #326 from PyAutoLabs/feature/colab-gemini-phase2
Jammy2211 commentedon Oct 26, 2026
Phase 2 merged (2026-10-26, human): PyAutoLabs/autofit_assistant#59 + PyAutoLabs/autogalaxy_assistant#39 → #326. autofit_workspace, HowToFit, autogalaxy_workspace and HowToGalaxy notebooks get folder-matched skills at the next release generate (fit 20k cap, galaxy 36k per-assistant cap; ag-skill trim follow-up in Mind). Remaining: phase 3 CTI, phase 4 upkeep skills + Broca evidence.
Jammy2211 commentedon Oct 26, 2026
Phases 3+4 shipped under Heart RED development override. Live human authorization 2026-10-26: "yes, I authorize, prm". Exact current RED reasons: release validation FAILED (stage integrate); PyAutoHeart/workflows/Release Integrate: failure; PyAutoHeart/workflows/Workspace Smoke: failure; manifest_drift/checks/workspace checkouts (manifest ↔ disk): red; Release readiness: release validation FAILED (stage integrate); autolens: red; Workspace validation: NOT ready — 1429p / 1f / 125s @ cloud#40294511523; test_run: red; Release validation: NOT release_ready — v? profile=? (2026-10-26T07:48:52+00:00); validation_report/stages/integrate: fail; PyAutoBrain: red; PyAutoLens: red; autolens_profiling: red; Worktree drift: 1 orphan / 0 missing / 3 dirty. Branch gates passed: colab_contexts check + tests in all four assistants; wiki-currency audits; autocti_workspace metadata-only (+796/−0), idempotent; independent review (no blockers, 4 findings fixed). No release.
PRs: PyAutoLabs/autocti_assistant#39 → PyAutoLabs/autocti_workspace#38 (order matters); PyAutoLabs/autolens_assistant#166, PyAutoLabs/autofit_assistant#60, PyAutoLabs/autogalaxy_assistant#40 (any order).
Out of scope, noted: autocti_assistant AGENTS.md real-data invariant has lensing wording + dead link to skills/ac_prepare_imaging_data.md; autocti_workspace AGENTS.md says notebooks regenerate at release (they don't); autofit_assistant clone boundary misses AI_OPTIONS.md (pre-existing on main).
Jammy2211 commentedon Oct 26, 2026
All four phases merged (2026-10-26, human). Phase 3: PyAutoLabs/autocti_assistant#39 → PyAutoLabs/autocti_workspace#38 (79 notebooks stamped). Phase 4: upkeep skills PyAutoLabs/autolens_assistant#166, PyAutoLabs/autofit_assistant#60, PyAutoLabs/autogalaxy_assistant#40 (+ CTI in #39). Completion record: PyAutoMind
complete/2026/10/colab-gemini-instructions.md. Workspace/HowTo notebooks pick up their instructions at the next release generate. Follow-ups listed in the record (CTI-on-Colab, CTI AGENTS.md wording, ag-skill trim, AI_OPTIONS paragraph after release).