Skip to content
Back to skills

Ape Add Ai Purpose

ASecurity

Add an AI purpose: class, instructions, prompt, output schema, check, fallback, candidate models and how one is chosen, tools, agents, research, test set and fixtures. Never call a provider directly.

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentgotesting

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add BuffApe/BuffApe --skill ape-add-ai-purpose --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ape Add Ai Purpose?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ape Add Ai Purpose
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/buffape-ape-add-ai-purpose/badge)](https://www.skillsdirectory.com/skills/buffape-ape-add-ai-purpose)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ape-add-ai-purpose
description: "Add an AI purpose: class, instructions, prompt, output schema, check, fallback, candidate models and how one is chosen, tools, agents, research, test set and fixtures. Never call a provider directly."
---

# Add an AI purpose

Call AI by purpose, never by provider. Nothing outside the `ai` module imports a provider SDK (Biome enforces it). The rules are in `docs/AI_GATEWAY.md`.

1. Declare the purpose in the module's manifest: `purposes: [{ key: 'notes.title', class: 'authoring', kind: 'call', instructions: { v1: '…' }, prompt, output, check, fallback }]`.
   - `kind: 'call'` is one request (`run`, or `stream` for text), with tools when the code passes them. `kind: 'agent'` is a multi-step run with tools that happens only in a job on the worker (step 4).
   - The class decides which providers may serve it (in the product's AI config). Child data never goes to a class that doesn't allow it. A class lists the sensitive kinds it `receives` (none by default); an agent that takes business actions gets only those whose `carries` are all in it.
   - BuffCore's own purposes need a class too, set in the product's config: `automation: { classes }` for `ops.weekly_summary` and `support.draft_reply` (replies are drafted only where the class `receives` `content`), `aiGateway: { class }` for the gateway's calls, and `generation`'s QA class for `content.qa` and `i18n.translate`. Give each a starting profile and fixtures.
   - The input is small, typed and de-identified, with names as `{name}` placeholders. Inputs with email addresses, phone numbers or `forbidden` values are rejected.
   - `research: true` gives the purpose its model's own web search (Anthropic, Vertex AI or OpenAI, on `direct` only). The model's search queries go to the provider, so use it only in a class with no personal data.
2. Add its starting profile to the product's AI config (`profiles`):
   - `runtime: 'direct'` (an agent may name `claude-agent` instead, with Anthropic candidates only) and the instructions version.
   - `candidates`: one to three `{ provider, model }`, each an exact pinned model whose provider the class clears. A call skips a candidate that can't run (not cleared, no credentials, can't call tools, write typed output or search when the call needs it); one that fails before any output hands over to the next.
   - `choose`: `listed` (your order, the default), `cheapest` or `fastest` (by price, or by the measured time of each model's ok calls). A model in BuffCore's catalog (`MODELS`) is priced already; add `prices` only for another model or another price.
   - `limits`: output tokens, time and a daily cap; `maxSteps` for tools and agents; `firstTokenMs` for streamed text.
   - Publishing is refused if any candidate isn't cleared for the class, so clear the providers in the class first.
3. Add fixtures (`fixtures: { 'notes.title': [{ output, usage }] }`); tests run with `APE_AI_MODE=fixture`. A missing fixture gives `AiUnavailable`, so fallbacks get tested. A fixture's `model` and `fails` (`error`, `timeout`, `rate_limited`) test a hand-over between candidates; `toolCalls` or `toolSteps` make the model call the product's tools, which run for real. `APE_AI_MODE=record` saves live answers to `.ape/ai-fixtures/` for you to review.
   - Add a test set (`testSets: { 'notes.title': { en: [{ input }] } }`) so a replay comparison has cases: it is the only source for a class that carries personal data, and the fallback when a purpose has no logged calls yet.
4. Call it:
   - `const { output } = await run(ctx, { purpose: 'notes.title', input })`. Every attempt is logged in `ai_calls` with its cost. Every purpose has a kill switch under its key (Operations › Kill switches): while it is off, `run` answers with the fallback (status `killed`), so give a purpose people wait on a fallback. Other work a module can stop gets its own switch in the manifest's `switches`, checked with `isOff(ctx, key)` from `@buffcore/modules/ops`.
   - To stream text, call `await stream(ctx, { purpose, input, tools, onText, signal })`; a streamed purpose returns text (no `output`), its fallback returns text (AI_GATEWAY.md, "Streamed calls").
   - Tools are plain functions: `tools: { lookup: defineTool({ description, input: z.object({…}), run }) }`, passed per call to `run`, `stream` or `agent`. A tool's result goes back to the model, so it must hold no contact details.
   - An agent runs in a job: declare it in the manifest's `jobs`, start it with `enqueue(ctx, 'notes.review', { id }, { key })`, and call `await agent(ctx, { purpose, input, tools, refs, signal })` inside (it throws in a request). Tests run the queued job with `drainJobs(app)` from `@buffcore/server/testing` (AI_GATEWAY.md, "Agents and calls with tools"). An agent takes a business action through `tools: actionTools(ctx, { purpose, actions: ['inbox.reply_to_report'] })` from `@buffcore/modules/automation`: the code names the actions, and each call meets the action's rules (it answers `{ waiting }`, `{ done }` or `{ refused }`), so a profile holds no list of actions (AUTOMATION.md).
5. A new prompt is a new instructions version in code. Choosing it, or other models, is a profile change: in AI › Profiles the Owner drafts the profile, compares it with the published one on the test set or recent calls, and publishes it. Outside production a starting profile changed in code publishes itself as the next version; a version published in the console stays until the code's profile changes.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.