Skip to content
Back to skills

Agent Engineering

BSecurity

Design and harden AI agent runtimes, MCP servers you build, and context pipelines. Use for agent loops, tool schemas, step and token bounds, prompt-injection defense, tool guards and hooks, MCP transports, context pruning, and system prompts for Claude 5 models. Trigger on 'build an agent', 'write an MCP server', 'the agent loops forever', 'trim this system prompt'.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 21, 2026
ai-agentsrustgobashdebuggingsecuritydocumentation

Works with

  • cli
  • mcp

Security analysis

B75/100
  • criticalContains 'ignore previous instructions' pattern — found in 91% of malicious skills (Snyk ToxicSkills)

Pro scans all 8 files and shows the line behind each finding

Scanned November 21, 2026

npx -y skills add juninmd/skills --skill agent-engineering --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Agent Engineering?

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

Security grade badge for Agent Engineering
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/juninmd-agent-engineering/badge)](https://www.skillsdirectory.com/skills/juninmd-agent-engineering)

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: agent-engineering
description: |
  Design and harden AI agent runtimes, MCP servers you build, and context pipelines. Use for agent loops, tool schemas, step and token bounds, prompt-injection defense, tool guards and hooks, MCP transports, context pruning, and system prompts for Claude 5 models. Trigger on 'build an agent', 'write an MCP server', 'the agent loops forever', 'trim this system prompt'.
---

# Agent Engineering

**Not this skill:** using an existing agent to do domain work (that domain's skill), picking an LLM provider or SDK (`stack-selection`), coordinating many agents or long unattended runs (`agent-orchestration`), or writing a skill (`skill-authoring`).

## Preflight
```bash
rg -n "tool_choice|function_call|tools:" src/ | head
rg -n "max_tokens|maxSteps|timeout" src/agent* | head    # is the loop bounded at all?
```

Name the authority boundary and the human approval points before designing anything. An agent whose boundary is unstated has all of it.

## Workflow
1. Define the goal, the non-goals, the authority boundary, and the human approval points. An agent without a stated authority boundary has all of it.
2. Map each user intent to the smallest deterministic tool. Strict schemas, bounded outputs.
3. Design state transitions, retries, timeouts, idempotency, and handoff criteria **before** writing prompts. Prompt engineering cannot fix a missing state machine.
4. Treat prompts, retrieved content, tool output, and remote resources as untrusted input.
5. Trace requests, tool calls, latency, token use, failures, and outcomes — without logging secrets or chain-of-thought.
6. Test the failure matrix, not just the happy path.

## Code or Model

| Job | Use | Why |
|---|---|---|
| Routing on a known set | code | deterministic, testable, free |
| Retries, backoff, idempotency | code | a model will not be consistent about it |
| Parsing structured output | code (schema validation) | a model re-reading its own JSON is waste |
| Policy enforcement, authorization | code | a prompt is not a permission system |
| Classification, extraction, summarization | model | genuinely fuzzy input |
| Judgment with tradeoffs | model | that is what it is for |

Every decision moved from prompt to code removes a class of nondeterminism you would otherwise be debugging in production.

## Bound the Loop
An unbounded loop is the top failure mode — it burns budget, then stops silently, and the user sees a truncated answer with no error.

```ts
const limits = { steps: 12, tokens: 200_000, wallClockMs: 120_000 };
// Hitting any limit is a REPORTED failure, never a quiet return.
if (step > limits.steps) throw new AgentBudgetExceeded('step limit', { step, trace });
```

A tool's own internal retries spend the same tokens and wall clock without touching `step` — meter those independently, or a hidden retry loop burns the whole budget while the step counter still reads clean (see [real-world-cases.md](references/real-world-cases.md)).

## Prompt Injection Is an Input Problem

| Vector | Defense |
|---|---|
| Retrieved document says "ignore previous instructions" | content is data, never instructions — never concatenate it into the system prompt |
| Tool output contains a new directive | same; render it in a delimited data block |
| A web page instructs a destructive tool call | tool allowlist plus human approval on anything destructive |
| Exfiltration via a crafted URL in output | allowlist outbound domains; strip or refuse unknown ones |
| Chained agent passes a poisoned instruction along | handoffs carry structured intent, never raw transcripts |

The defense is architectural: least privilege on tools, deny destructive by default, human gate on the irreversible. No prompt wording survives a determined injection.

## Test Matrix

| Case | Expected |
|---|---|
| Valid call | correct tool, correct arguments |
| Malformed model output | schema rejects, one bounded retry |
| Prompt injection in retrieved content | instruction ignored, flagged |
| Tool denied | graceful degradation, reported |
| Tool timeout | bounded, surfaced, not retried forever |
| Partial failure mid-plan | state consistent, resumable |
| Retry exhaustion | visible failure with the trace |
| Budget exceeded | reported, never a silent stop |

## System Prompts for Claude 5 Models

| Before | Now | Why |
|---|---|---|
| Rule lists ("never write comments") | Goal plus judgment ("match the surrounding code") | a rule fires where it was never meant to |
| Worked examples in tool descriptions | Self-describing schemas: enums, required fields, one invariant | examples anchor; interfaces constrain |
| Everything up front | Progressive disclosure: deferred tools, skills, references | irrelevant context still costs attention |
| Same instruction in prompt and tool text | Say it once, where it applies | repeats drift into contradictions |

Contradictory layers (system prompt vs. CLAUDE.md vs. skill) are the costly failure: the model spends reasoning reconciling them every turn. Details: [context-engineering](references/context-engineering.md).

## Reference Routing
- Practical agent failure cases: [real-world-cases.md](references/real-world-cases.md)
- Agent loops, tool contracts, and orchestration: [agent-development.md](references/agent-development.md)
- Deterministic tool interceptors, scrubbers, and circuit breakers: [tool-guards-and-hooks.md](references/tool-guards-and-hooks.md)
- Building or wiring MCP servers, transports, tool exposure, annotations, structured output, error messages, and read-only LLM evals: delegate to [mcp-integration](references/mcp-integration.md).
- Window budgets, pruning, and summarization strategy: delegate to [context-engineering](references/context-engineering.md).

See [Reference Map](references/TOPIC_MAP.md) for specialized references and sub-domain guides.

## Stop
- The loop has no hard step, token, and wall-clock bound. Bound it before running it anywhere real.
- A destructive tool has no human gate. Add the gate; a careful prompt is not a permission system.
- Retrieved content is concatenated into the system prompt. Fix the architecture before shipping — no wording survives injection.

## Rules
- Hand off security audits to `security-ops`, CLI automation to `tooling-dev`, and prompt documentation to `documentation`.
- Give tools least privilege and deny destructive operations by default. A tool that can delete needs a human gate, not a careful prompt.
- Keep memory provenance, retention, and deletion behavior explicit. Memory that cannot be inspected or deleted is a liability.
- Never log the system prompt or chain-of-thought, and never echo unsanitized tool output back to the user.
- On handoff to another agent, pass intent, scope, current state, verification commands, and boundaries — never raw transcripts, which hand over noise and hide the contract.
- An agent evaluation needs a fixed input set and a graded rubric; "it seemed better" is not a result.
- Whether every model behind an OpenAI-compatible gateway actually emits tool calls is `test-engineering`; auditing a third-party MCP server or plugin before installing it is `security-ops`; keeping an unattended headless run alive across expiring tokens and quotas is `agent-orchestration`.

## Checklist
- [ ] Goal, non-goals, authority boundary, and approval points written down.
- [ ] Every deterministic decision implemented in code, not in the prompt.
- [ ] Tool schemas strict; outputs bounded and validated.
- [ ] Loop bounded on steps, tokens, and wall clock, with a reported failure on the limit.
- [ ] External content treated as data; destructive tools gated.
- [ ] Whole test matrix exercised, injection case included.
- [ ] Traces cover tool calls, latency, tokens, and outcomes, with no secrets.

Files in this skill

  • SKILL.md7.6 KB
  • references/TOPIC_MAP.md1.2 KB
  • references/agent-development.md3.1 KB
  • references/context-engineering.md5.9 KB
  • references/mcp-integration.md9.9 KB
  • references/real-world-cases.md4.7 KB
  • references/tool-guards-and-hooks.md4.6 KB
  • references/transport-auth-and-testing.md3.1 KB

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 ai-agents →

Comments

Loading comments…

Newsletter

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