Writing agent instructions

From BuilderIO/agent-native · View interactive version

Writing agent instructions is an AI agent skill from the GitHub repository BuilderIO/agent-native. How to write great agent instructions for an agent-native app or template: AGENTS.md, skills, and tool/action descriptions. Use when authoring or reviewing AGENTS.md, writing a SKILL.md, wording action descriptions, or deciding what belongs in instructions vs skills vs memory.

How to use this skill

Skill file

Writing Agent Instructions & Skills

This is a creator-facing guide. When you build an agent-native app or template,

the agent's behavior is only as good as the instructions you give it. Three

surfaces carry that guidance: AGENTS.md (the map), skills (the deep dives),

and action/tool descriptions (how the agent picks the right tool). Write each

one for fast retrieval, not for prose.

Keep AGENTS.md small and skimmable

AGENTS.md is loaded as orientation. It should be the smallest thing that lets

the agent act correctly, with everything deep pushed into skills. Aim for these

sections and little else:

operations go through actions, AI goes through the agent chat, schema changes

are additive). Short, imperative bullets.

reads to know what the user is looking at, with their shape.

If a section is growing past a screen, it belongs in a skill. AGENTS.md

answers "what is this app and what can I do," not "how exactly do I do the hard

thing."

The 6,000-character cap is real and silent

A template AGENTS.md is injected into the runtime agent's system prompt and

hard-sliced at COMPACT_PROMPT_RESOURCE_MAX_CHARS (6,000). Past that, the agent

sees a truncation marker instead of your text, so the tail stops being

always-on guidance and becomes something it has to go fetch. `pnpm

guard:agent-chat-context` — the repository's own check — fails the build when a

first-party file overflows; generated apps do not ship that repository-only

guard. Keep files under ~5,500 so ordinary edits don't tip them over.

Two consequences worth designing around:

pointer to every deferred skill. If it lands in the truncated tail, the agent

cannot discover any of the depth you carefully moved out.

align columns, and that invisible whitespace counts against the cap — enough

padding in a wide action table to push a file back over it on its own. Both

**/AGENTS.md and **/SKILL.md are in .prettierignore for this reason;

keep them there and write table rows unpadded.

# Projects App

One workspace for projects, tasks, and notes. Agent and UI share the same SQL
data and the same actions.

## Core Rules

- Data lives in SQL via Drizzle. Use actions for all writes.
- All AI work goes through the agent chat; never call an LLM inline.
- Schema changes are additive only.

## Application State

- `navigation.view`: `home` | `project`
- `navigation.projectId`: selected project on a project page

## Actions

| Action | Purpose |
| --- | --- |
| `list-projects` | List accessible projects |
| `create-project` | Create a project |
| `update-project` | Rename or archive a project |

## Skills

- `project-imports` — read before importing legacy CSV exports.
- `sharing` — read before exposing a project to other users.

Single-source AGENTS.md (CLAUDE.md is a symlink)

Keep one canonical instructions file: AGENTS.md. If a client expects

CLAUDE.md, make it a symlink to AGENTS.md rather than a second copy. Two

hand-maintained files drift, and the agent ends up with contradictory rules.

One source of truth, linked where needed.

Keep generated guidance in sync

Framework guidance is authored once in this repo and copied outward. Treat

.agents/skills/ as the canonical source for shared skills. Generated

workspace skills in packages/core/src/templates/workspace-core/.agents/skills/

and first-party template copies of shared skills must stay byte-for-byte in

sync; run pnpm sync:workspace-skills after editing a shared skill, and

pnpm guard:workspace-skills before calling the guidance done.

Generated app and workspace instructions must teach the same action-first data

contract:

callAction; route paths are a transport detail hidden behind helpers.

streaming, webhooks, OAuth callbacks, public SEO/OG endpoints, or binary

assets.

re-export an action.

contract in the external-agents skill (Rule section); do not paraphrase

them per app.

Rules that must influence app generation or the runtime agent cannot live only

in scope: dev skills. Put the short invariant in the generated AGENTS.md

or another runtime-visible instruction surface, then keep the implementation

details in the relevant skill.

Generated guidance must also distinguish deterministic tools from AI-shaped

workflows. Provider reads, validation, deterministic transforms, CRUD, and

persistence belong in focused actions. Research, analysis, generation,

recommendation, synthesis, and other user-steerable multi-step work should

start in the AgentSidebar and let the agent orchestrate those actions. State

that sendToAgentChat({ openSidebar: true }) is the default handoff and that

follow-ups stay in the same thread; do not add a second freeform prompt box.

Budget the first model request

Treat the initial prompt and tool catalog as a latency budget. The agent should

start with a compact map of the app, then retrieve depth only when the task

needs it.

workflows. Keep tool-search available so every other registered action and

connected MCP tool remains discoverable on demand. This list is also what

MCP instructions and the WebMCP manifest advertise as the app's key tools,

so keep it equal to the AGENTS.md action table — see the actions skill,

Key Actions.

in skills and long reference material in references/ or workspace

resources that the agent can read when relevant.

or provider catalogs through systemPrompt or extraContext. Inject a

bounded summary, stable ids/paths, and the exact action or resource lookup

that retrieves the full content.

carry schemas; uncommon actions are available through tool-search.

and ids needed for a follow-up read rather than full record bodies.

The goal is progressive disclosure, not reduced capability: a compact first

request, precise discovery, and full fidelity once the agent knows which depth

is relevant.

Say each thing once, in the layer that owns it

Current-generation models do not need a rule repeated in the system prompt, the

instructions, and the tool description. Repetition is not reinforcement — it is

three chances to disagree with each other, and the model spends effort

reconciling them before it can act. Pick the owning layer:

| Layer | Owns |

| --- | --- |

| System prompt / AGENTS.md | Which capabilities exist, and policy spanning tools: turn shape, what to do first, invariants that hold every turn |

| Tool / action description | How to call it, argument and result semantics, what to say about a result, when this tool rather than a sibling |

| Skill | Multi-step workflows, worked examples, field references, edge cases |

The common mistake is restating a tool's mechanics as a numbered core rule.

Deferred tools are loaded through tool-search, so the model always reads the

description before it can call the tool — a start/update/complete sequence or an

argument enum in the prompt buys nothing and is charged on every turn. State

that the capability exists and when it applies; let the description carry how.

New required steps are guidance until measured

A step, gate, or hold added to a workflow costs every run that follows it, and

a pile of individually reasonable ones is how workflows get slow. Default to

guidance or a non-blocking mechanism (a script that reports, grouping work

before it is handed out, review by sampling). A step that must block needs a

named number it should move, a measured trial first, and a time limit with an

owner. Run node scripts/agent-friction-report.mjs --weeks 2 before adding one

(see CLAUDE.md, Checks).

Prefer judgment over rules, and interfaces over examples

Blanket prohibitions were how older models were kept out of worst-case

behavior. They now mostly cost accuracy, because a rule stated absolutely is

wrong for some fraction of requests and the model has to guess which fraction it

is in. Write the intent and let the model apply it:

comments." Say "response length mirrors the task" rather than "2–5 sentences."

unless a surface genuinely breaks without them.

self-correcting: security, destructive operations, fabricating data or

success, and credential handling. Those stay absolute.

model to the shapes you showed. Make the tool's own interface expressive

instead — precise parameter names, enums that imply the state machine,

.describe() on every field. Keep a literal example only where it defines a

syntax the schema cannot, such as a pnpm action CLI invocation in dev mode.

When documenting version history, restore, or audit trails, use actions for

full restorable snapshots (list-<resource>-versions,

get-<resource>-version, restore-<resource>-version,

delete-<resource>-version). Do not copy legacy raw-route version panels,

such as document-version /api/* helpers, into new features. The Plans

version-history pattern is the preferred model.

SKILL.md frontmatter must say what AND when

The description is the only thing the agent sees when deciding whether to read

a skill. It must answer two questions: what the skill covers, and when to

trigger it. A description that only describes the topic will not fire.

---
name: project-imports
description: >-
  How to import projects from the legacy CSV export. Use when the user uploads
  a project CSV or asks to migrate projects from the old system.
---

Scope a skill to runtime vs dev

An optional scope field decides which agent loads the skill:

in-app runtime agent.

skill is invisible to the runtime agent everywhere (system-prompt skills block

and docs-search).

Use scope: dev for internal-only guidance that should help connected repo

agents such as Codex or Claude Code, but should not influence the deployed

production agent. Do not use metadata.internal for this: it is catalog/package

metadata and does not control runtime visibility.

---
name: release-checklist
description: >-
  Steps for cutting a release. Use when preparing or publishing a new version.
scope: dev
---

Omit scope for normal skills (the default both keeps them loading at

runtime — fully backward compatible). For a dev-only skill, mark it scope: dev

and optionally mirror it under .claude/skills/<name>/SKILL.md so Claude Code

picks it up while the runtime agent skips it.

Progressive disclosure: lean SKILL.md, depth in references/

Write the SKILL.md as the lean, must-know layer: the rule, how to do it, the

do/don't list, and pointers. Push long examples, exhaustive field references,

API quirks, and edge-case tables into references/ files the agent reads only

when it needs them.

.agents/skills/project-imports/
├── SKILL.md            # rule + happy path + do/don't
└── references/
    └── csv-format.md   # full column spec, encodings, edge cases

This keeps the always-loaded surface small and lets depth scale without bloating

context. See the create-skill skill for the full skill format.

Write action-oriented tables

The agent scans tables faster than prose. Prefer a table of name -> purpose over

paragraphs describing each operation. The same applies to state keys, field

types, and any enumerable set. Tables are skimmable, diffable, and easy to keep

in sync when you add an action.

Write clear tool/action descriptions

Action descriptions are tool descriptions — they drive tool selection. Make each

one a precise, single-purpose sentence:

agent knows they're safe to call freely.

capability ceilings. If arbitrary provider endpoints/filters may matter,

point instructions to provider-api-catalog, provider-api-docs, and

provider-api-request instead of implying the shortcut is all the agent can

do.

defineAction({
  description: "Create a project. Returns the new project id and title.",
  schema: z.object({
    title: z.string().min(1).describe("Project title shown in the sidebar"),
  }),
  // ...
});

Bake in anti-fabrication and verify-before-done

App instructions should make honesty and verification the default behavior:

— don't invent results or claim success. Read the real value via an action or

query before reporting it.

(re-query the row, re-read the screen via view-screen) instead of assuming

the write worked.

fetch), retry or fix the input rather than abandoning the task. Keep this

separate from the anti-fabrication rule — don't conflate "don't make things up"

with "stop at the first error."

Put these as core rules in AGENTS.md so they apply to every turn.

Bake in secrets hygiene

Instruction authors must make credential handling explicit anywhere an app,

skill, action, webhook, integration, or extension touches external services.

Write the rule in terms of values, not just files: never hardcode real API keys,

tokens, webhook URLs, signing secrets, OAuth refresh tokens, private

Builder/internal data, or customer data in source, docs, tests, fixtures,

prompts, screenshots, or generated content.

Examples may name credential keys such as OPENAI_API_KEY or SLACK_WEBHOOK,

but values must be placeholders (<OPENAI_API_KEY>, ${keys.SLACK_WEBHOOK}) or

clearly fake test data. Tell agents which approved channel to use instead:

deployment env vars for deploy-level secrets, app_secrets /

saveCredential / resolveCredential for scoped API keys, oauth_tokens for

OAuth, and ${keys.NAME} substitution for extension/automation outbound HTTP.

What goes where

state keys, action index, skills index.

to everyone working in the app.

authored guidance. See capture-learnings.

Do

Don't

carry those.

Builder/internal data, or customer data into examples. Use placeholders.

Related Skills

application state) every feature must satisfy.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.