Skip to content

Add Agent Skills for Magpylib users and contributors - #984

Closed
Alexboiboi wants to merge 4 commits into
mainfrom
feat/agent-skill
Closed

Alexboiboi wants to merge 4 commits into
mainfrom
feat/agent-skill

Conversation

@Alexboiboi

@Alexboiboi Alexboiboi commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR adds Agent Skills for both Magpylib users and repository contributors.

  • Ships a versioned magpylib user skill inside the package at src/magpylib/.agents/skills/magpylib/, installed as magpylib/.agents/skills/magpylib/ in wheels and sdists.
  • Adds 16 repository development skills under .agents/skills/ for implementation, review, testing, documentation, research, design, maintenance, and contributor workflows.
  • Adds a dedicated Array API development skill grounded in the public Array API specification, official SciPy, NumPy, scikit-learn, and data-apis guidance, plus a dated audit of related Magpylib issues and pull requests.

Why

Assistants can otherwise generate plausible Magpylib code from pre-v5 assumptions: millimetres instead of metres, millitesla instead of tesla, or magnetization where v5 expects polarization. These mistakes often execute successfully while producing results wrong by factors of 1e3 to 1e9.

The packaged user skill is version-pinned to the installed Magpylib release. The repository skills separately encode contributor workflows and project-specific validation without shipping that development-only context to end users.

Packaged user skill

The 309-line SKILL.md covers units, sources, field computation and output shapes, sensors, paths, path-varying properties, collections, force and torque, visualization, and common silent failure modes.

Four progressively disclosed references cover:

  • field computation;
  • position and property paths;
  • force and torque;
  • visualization.

Three package tests verify that the skill is included, its frontmatter meets the Agent Skills specification, and all relative references resolve.

Users can discover and install it with uvx library-skills from library-skills.io.

Repository contributor skills

The repository-local suite covers:

  • Magpylib development and code review;
  • test-driven development;
  • Diataxis documentation;
  • primary-source research;
  • codebase design and domain modeling;
  • merge-conflict resolution and Scientific Python Copier updates;
  • package-skill maintenance and Agent Skill authoring;
  • handoff, clarification, and grilling workflows.

These files remain under .agents/skills/ and are not package data.

Array API development skill

The dedicated workflow defines:

  • Array API 2024.12 as the initial implementation target supported by array-api-compat at the audit date;
  • dependency or vendoring, rollout, mixed-input, and capability-matrix decisions required before parallel kernel ports;
  • namespace, dtype, device, promotion, mutation, control-flow, and compiled-code boundaries;
  • independent evidence requirements for backend execution, GPU preservation, JAX JIT, lazy evaluation, autodiff, precision, and NumPy performance;
  • automated CI coverage as a prerequisite for advertising support;
  • a public-source inventory of every direct and adjacent Magpylib Array API issue and pull request checked on 2026-08-27.

The inventory records that all 13 open direct Array API PRs were conflicted and had zero checks at the audit date. They are treated as design evidence rather than merge-ready implementations.

Verification

  • Every packaged API claim was checked against the current source, docstrings, documentation examples, or executable behavior.
  • skills-ref validate: valid packaged skill.
  • Wheel and sdist inspection: all packaged skill files are present.
  • Scratch installation: uvx library-skills scan discovers the installed skill and install links it correctly.
  • Package work: full suite passed with 1388 passed and 1 skipped.
  • Repository skills: YAML/frontmatter parsing, relative-link checks, contamination scans, editor diagnostics, and repository hooks passed.
  • uvx nox -s lint: passed.

Repository-root installation caveat

Do not run library-skills install at the repository root. Its generated symlink points back into src/magpylib; Hatch can then record the skill under the symlink in the sdist while omitting the real package path. Install from a separate consumer project when testing discovery.

Alexboiboi and others added 2 commits August 26, 2026 17:31
AI coding assistants write Magpylib code from pre-v5 memory: millimetres and
millitesla, `magnetization` where v5 wants `polarization`. Nothing raises — the
answer is simply wrong by a factor of 1e3 to 1e9.

Adds an Agent Skill (https://agentskills.io) at
`src/magpylib/.agents/skills/magpylib/`, so it travels inside the wheel and
stays in sync with the installed version. Users pick it up with
`uvx library-skills` (https://library-skills.io), which symlinks it into their
project's `.agents/skills/`. FastAPI, Streamlit, Typer and SQLModel already ship
skills at exactly this path; no scientific Python package does yet.

SKILL.md covers units, sources, field computation and output shapes, sensors,
paths, collections, `getFT()` and `show()`, then closes with the gotchas that
cost the most: silent v4 unit errors, `squeeze` changing the output rank,
`rotate()` appending to a path rather than transforming it, and `meshing` being
mandatory for force targets. Four files under `references/` hold the detail and
are loaded on demand, per the spec's progressive disclosure.

Every API claim was executed against this tree rather than recalled, and the
skill validates against the reference implementation from the agentskills repo.
The new tests assert the skill is packaged, that its frontmatter meets the spec,
and that its relative links resolve.

Note for contributors: do not run `library-skills install` at the repo root. The
symlink it creates points back into `src/magpylib`, and hatchling then records
the skill under that symlink in the sdist while dropping it from
`src/magpylib` — an sdist install would ship no skill at all. The wheel is
unaffected, and these tests would not catch it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Reviewed every claim against the 494 docstring examples and the 145 code cells
in docs/_pages, and ran the skill's own code blocks.

Fixes:

- The backend section claimed matplotlib cannot animate. It can — all three
  built-in backends declare `supports_animation` and `supports_subplots`. What
  actually differs is `supports_colorgradient` (not matplotlib),
  `supports_animation_output` (pyvista only) and `supports_native_traces` (not
  pyvista), now given as the capability table from the registry.
- "Datasheet remanence B_r is a polarization" skipped the part that matters: a
  real magnet demagnetises itself, so the value to use sits a few percent below
  B_r — the J at the working point.

Additions, all of them things the docs use and the skill did not mention:

- Path-varying properties are now a section of their own rather than a closing
  sentence, with the three rules that govern them — what you set is what is
  stored, lengths reconcile at computation time by edge-padding on a temporary
  copy, derived properties gain the path axis — plus end-slicing and mismatched
  lengths in the reference. This is the newest part of the library and the least
  represented in the docs, so it is the part an agent is least likely to know.
- The `rotate_from_angax/rotvec/euler/quat/matrix/mrp` family, which the docs use
  throughout and which is far more ergonomic than building a scipy Rotation.
- `getJ()`/`getM()` return the material's own polarization/magnetization inside
  the body and zero outside; inside a magnet, H opposes J.
- A `Collection` passed as `sources` counts as one source and superposes its
  children, while a list of the same children keeps the source axis.
- `TriangularMesh.from_pyvista/from_ConvexHull/from_triangles/from_mesh` for CAD
  and STL geometry, `CustomSource(field_func=...)` for measured or interpolated
  data, `copy(**kwargs)`, subclassing `Collection` for compounds, and the
  `graphics.model3d.make_*` helpers for custom 3D representations.

Every example was executed against this tree: `path_properties` output, the
(3, 3) result of a 3-step current against a 2-step position with the position
attribute left at length 2, `dipole_moment` gaining the path axis, and the
J/M/B/H values inside and outside a magnet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Alexboiboi
Alexboiboi marked this pull request as draft August 27, 2026 20:30
@Alexboiboi Alexboiboi changed the title Ship an official Agent Skill inside the package Add Agent Skills for Magpylib users and contributors Aug 27, 2026
@Alexboiboi Alexboiboi added new feature docs testing AI AI assistant tooling and integrations labels Aug 27, 2026
@Alexboiboi

Copy link
Copy Markdown
Member Author

Superseded — split into four PRs so each part can be reviewed against its own risk profile rather than as one 1873-line diff.

PR Contents Ships to users?
#989 Array API development skill + the two skills it references no
#990 Magpylib-specific contributor skills no
#991 General engineering and workflow skills no
#992 The packaged user skill, test_package.py, CHANGELOG yes — package data

The split matters because the array-API skill is a prerequisite for reorganising #792, and it was gated here behind review of a document that ships inside the wheel. Those need very different scrutiny.

All content is carried over byte-identically, with one deliberate change in #989: items 1 and 2 of "Establish the contract" asserted a target version and a dependency stance while items 3–5 posed them as questions. All five now pose the decision with a recommended default, so merging the skill ratifies nothing — the answers belong in #792.

Closing this and deleting feat/agent-skill. History remains at refs/pull/984/head.

@Alexboiboi Alexboiboi closed this Aug 29, 2026
@Alexboiboi
Alexboiboi deleted the feat/agent-skill branch August 29, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI AI assistant tooling and integrations docs new feature testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant