Designing Reusable Agent Skills with Staged Context Loading
System DesignModel answerLast updated
Describe what a reusable skill package is in an agent system, how it differs from a plain prompt, and how loading its content in stages keeps context small while limiting risk.
You are designing part of an LLM-based agent platform. The team wants to package repeatable know-how, such as "produce a quarterly report" or "triage a failing CI job", as skills that the agent can pick up when needed.
Treat a skill generically: a reusable task package made of written instructions, plus optional reference documents, templates, scripts or tool definitions. Do not rely on any specific product's file layout or loader.
Explain your design and cover the following:
- What a skill is, and how it differs from an ordinary prompt typed into a single interaction.
- How progressive disclosure can structure what the agent sees, and what is loaded at each stage.
- How skills are discovered and selected, and what metadata supports that choice.
- How referenced resources (documents, templates, code) are pulled in.
- Who owns permissions and validation, and what a skill can and cannot guarantee.
- What you do when a referenced document is untrusted or out of date.
Aim for an answer you could give in about ten minutes on a whiteboard, including trade-offs and failure modes.
Hints
Hint 1
Think about the context window as a budget: what must always be visible, what is needed only after a skill is chosen, and what is needed only for a particular step?
Hint 2
Selection quality depends on short, accurate descriptions of when to use a skill. Consider what happens when you have 10 skills versus 500.
Hint 3
Instructions inside a skill are text the model reads, not enforcement. Ask which layer actually has the authority to block an action or check an output.
Hint 4
Referenced files are an input channel. Consider provenance, versioning, and prompt injection.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
What a skill is
A skill is a versioned, reusable package for a class of tasks: a procedure written in natural language, plus optional supporting assets such as reference docs, templates, example outputs, helper scripts or tool definitions. It carries a short description of when it applies.
Versus an ordinary prompt:
| Aspect | Ordinary prompt | Skill |
|---|---|---|
| Lifetime | One interaction | Reused across many sessions |
| Authoring | Written ad hoc by the user | Written once, reviewed, versioned |
| Loading | Always fully in context | Loaded on demand, in stages |
| Contents | Instruction only | Instructions + resources + optional tools |
| Testability | Hard to evaluate | Can be regression-tested against fixed tasks |
The point is not that a skill is "a bigger prompt". It is that the know-how is separated from the conversation, so it can be shared, improved, audited and loaded only when relevant.
Progressive disclosure
The context window is a limited budget, and irrelevant text both costs tokens and degrades behaviour. So disclose information in layers, each loaded only when the previous layer shows it is needed.
- Level 0, catalog (always loaded). For every available skill: name, one or two sentences on what it does and when to use it, and maybe tags. Roughly 50 to 100 tokens each, so 100 skills cost about 5 to 10k tokens. This is the only thing used for selection.
- Level 1, skill body (loaded on selection). The main instructions: steps, conventions, output format, pitfalls. Keep it compact (a few thousand tokens at most) and have it point to deeper material rather than inline it.
- Level 2, referenced resources (loaded on demand). Detailed docs, schemas, long examples, templates. The body says "for the refund policy, read
policies/refunds" and the agent fetches it only when it reaches that step. - Level 3, executable assets. Scripts or tools the agent invokes. Their output enters context, not their source, which is both cheaper and more deterministic.
Benefits: lower cost and latency, less distraction, a catalog that scales to hundreds of skills, and easy independent updates to each layer.
Discovery and selection
- Discovery: a registry or directory scanned at session start builds the catalog. Scope it per user, team or task type so the model only sees skills it may use.
- Selection: usually the model itself picks from the catalog based on descriptions. At larger scale add a retrieval step (embedding or keyword search over descriptions) to shortlist 5 to 10 candidates, then let the model choose. Explicit user invocation should always override.
- Metadata that helps: a precise "use when / do not use when" description, required tools, required permissions, version, owner, and example triggers.
- Common failure: vague or overlapping descriptions cause wrong or missed activation. Evaluate selection separately, with a labelled set of requests and expected skills, and track precision and recall.
Referenced resources
Resources are fetched through ordinary tools (file read, retrieval, HTTP) at the point of need. Good practice:
- Reference by stable ID plus version or content hash, not by free-form location.
- Keep each file focused so a single read answers a single question.
- Prefer scripts for deterministic work (parsing, calculations, format conversion) and docs for judgment guidance.
- Put "when to read this" notes in the skill body so the model does not read everything speculatively.
Permissions and validation: what a skill cannot guarantee
A skill is text the model reads. It can steer behaviour but cannot enforce it. Therefore:
- Permissions belong to the runtime/platform, not the skill. Tool access, file scopes, network egress, spending limits and approval gates are enforced outside the model, under the identity of the user or agent. A skill may declare what it needs; the platform decides whether to grant it.
- Validation belongs to code and process. Schema checks on outputs, tests, linters, policy checks and human review for high-risk steps should run independently of the model's claim that it followed the procedure.
- Skill installation is itself a trust decision. Skills with scripts are effectively code, so require review, signing or an allowlist, and run scripts in a sandbox.
- A skill improves the likelihood of correct behaviour. Never rely on it as the security boundary.
Untrusted or outdated references
Untrusted content (user uploads, web pages, third-party docs) is a prompt-injection vector, since the model may treat embedded instructions as commands. Mitigations:
- Mark such content as data, not instructions, in the prompt structure.
- Limit what tools the agent can call while it is processing untrusted text, and require confirmation for sensitive actions.
- Restrict skills to trusted sources; log which resource versions were read.
Outdated content:
- Version resources and record owner and last-reviewed date; surface a warning or refuse when a document exceeds an age threshold.
- Prefer fetching the authoritative live source (a tool or API) over a pasted snapshot for fast-changing facts such as prices or policies.
- Add tests that run the skill against current data, so drift is caught in CI rather than by users.
- When two sources conflict, the skill should say which one wins and tell the user about the conflict.
Trade-offs
- More staging saves tokens but adds round trips and a risk the model never loads a needed resource. Mitigate by keeping the body explicit about when to load each file.
- Large catalogs hurt selection accuracy; use retrieval and namespacing.
- Fat skills are simple but wasteful; thin skills with many references are efficient but fragile if links break.
- Skill scripts give determinism but widen the attack surface.
Common mistakes
- Treating a skill as a permission grant or a guarantee of correct output.
- Putting everything into the always-loaded layer, defeating the purpose.
- Writing descriptions that say what the skill is rather than when to use it.
- Letting retrieved documents carry instructions with the same authority as the skill itself.
- No evaluation or versioning, so skills silently rot.
Summary line for the interview
"A skill is a versioned, reusable task package loaded in layers: a tiny catalog for selection, a compact body once chosen, and detailed resources only when a step needs them. It shapes behaviour but does not enforce it, so permissions and validation stay in the runtime, and any referenced content is versioned and treated as untrusted data unless proven otherwise."