blob: d29b9778b6cabb6dade4f1b5d250b38c1fa65927 [file] [view] [edit]
# Contributing to the Perfetto AI skill
`ai/skills/perfetto/` is the skill; [README.md](README.md) covers what it
does and how users install it. This file is for people changing it.
## Design choices, and the evidence behind them
The skill was measured with the harness in [`ai/evals/`](../evals/):
the same prompts run with and without it, several times, on two models.
The findings that shaped it:
- **Capable models already write correct PerfettoSQL.** With only the
binary on `PATH`, Opus answered nearly every test question correctly.
The skill's job is therefore not to teach SQL from scratch but to make
the agent efficient (load once, query many), honest (report numbers
from the trace, say when the trace does not contain what was asked),
and reliable on the guided workflows, where a weaker model without the
skill did invent a memory leak.
- **Every extra instruction has a price.** An earlier version with a
mandatory setup document, a smoke test, a schema-check checklist and
an always-on report file made simple questions three times slower for
the same answer. Keep the router lean, keep references short, and say
why rather than shouting MUST; agents follow reasons better than
rules.
- **Warm sessions are the single biggest efficiency win.** Without
guidance agents re-parse the trace for every query, dozens of times
per investigation. `querying.md` makes `server unix` plus
`query --remote` the default.
- **Workflows carry their own scripts.** A workflow that says "run this
SQL file, then interpret these columns" is repeatable and cheap to
verify; a workflow that says "explore the heap" is neither.
- **Reports for multi-step work.** Anything that took more than a few
queries writes `perfetto_analysis_report.md` so a person can follow
what was done and re-run the validated queries. One-off questions stay
in chat.
When you change the skill, run the evals. A change that reads well but
costs more or scores lower is not an improvement.
## Layout
```
ai/skills/perfetto/
├── SKILL-template.md the router (becomes SKILL.md when bundled)
├── infra-references/
│ ├── querying.md trace_processor sessions, discovery, PerfettoSQL
│ ├── recording_android_traces.md
│ ├── recording_linux_traces.md
│ ├── trace_config_reference.md
│ └── example-configs/
├── environment-references/
│ └── setup.md $SKILL_ROOT and the bundled trace_processor
└── workflows/
├── android_memory/ heap dumps, native heap, allocations + scripts/
└── gpu/ occupancy, frequency, compute kernels + scripts/
```
Paths inside the skill are written as `$SKILL_ROOT/<path>`, where
`$SKILL_ROOT` is the directory holding `SKILL.md`. The skill is loaded
from a plugin directory, not from the user's workspace, so relative
paths would resolve against the wrong place; the router tells the agent
to set `$SKILL_ROOT` once.
## Authoring
- Write for an agent that has only `trace_processor` and a trace: no
repo paths, no `tools/` scripts. Link to <https://perfetto.dev/docs>.
- Adding a workflow: `workflows/<domain>/<name>.md` in the imperative,
scripts in a sibling `scripts/`, one new line in the router. Point at
`querying.md` for how to query rather than repeating it.
- Run every query in a new or changed file against a real trace first.
Files that were never run ship with wrong column names.
- Add an eval case for any workflow, with ground truth computed by
`trace_processor_shell`, and check the with/without numbers before
sending the change.
## How it ships
The tree here is a build input, not a drop-in: `SKILL-template.md` is
named so that skill loaders scanning for `SKILL.md` do not pick up the
unassembled source, and the `trace_processor` wrapper is not checked in
alongside it. `tools/release/build_ai_agents.py` renames the router,
copies in `tools/trace_processor` as `bin/trace_processor`, adds the
per-agent manifests from [`ai/extensions/`](../extensions/README.md) and
writes the result to the `ai-agents` branch at each release. Users
install from that branch; see
[`docs/getting-started/using-ai.md`](../../docs/getting-started/using-ai.md).
To try the local tree, `ai/evals/setup_assets.py` bundles it the same way.