Production-grade AI agent patterns with MCP integration, agentic RAG, handoff orchestration, multi-layer guardrails, observability, token economics, ROI frameworks, and build-vs-not decision guidance...
Use this skill to decide whether a workflow should be an agent, which agent shape fits, which protocol boundary to use, and what production controls must exist before rollout.
Default posture: explicit control flow, bounded tools, typed contracts, auditable state, human approval for high-risk actions, and telemetry from day one.
Keep this file lean. Load detail from references/index.md, assets/, and sibling skills only when needed.
Use this skill when the user asks for:
../ai-prompt-engineering/SKILL.md../ai-rag/SKILL.md../ai-vector-brain/SKILL.mdai-bot-builder../ai-voice-bots/SKILL.md../agents-mcp/SKILL.mdagents-subagents../software-devtools/SKILL.md../qa-agent-testing/SKILL.md../ai-mlops/SKILL.md../software-security-appsec/SKILL.md../ai-llm/SKILL.md, ../ai-llm-inference/SKILL.mdai-context-layer, ../ai-rag/SKILL.md, ../ai-vector-brain/SKILL.mdAgent-system request
-> Build-vs-not gate
+-- simpler workflow/form/tool fits -> do not build an agent
+-- autonomy justified -> continue
-> Define task environment and performance measure
-> Choose control flow: workflow, FSM, DAG, or agent loop
-> Set boundaries: MCP for tools/data, A2A for handoffs
-> Define state, schemas, success criteria, and approvals
-> Add evals, telemetry, rollback, and kill switches
-> Route implementation depth to specialized skills
ai-context-layer/patterns-catalog.md to pick a named pattern and ai-context-layer/anti-patterns-catalog.md for the sweep| Question | Default |
|---|---|
| Should this be an agent? | Start with references/build-vs-not-decision.md; default answer is "no" until volume, ambiguity, and value justify autonomy. |
| What is the task environment? | State the performance measure, environment, percepts/sensors, actions/tools, observability, determinism, horizon, and other agents before choosing a framework. |
| Which control flow fits? | Prefer workflow/FSM/DAG; use planner/executor only when branching cannot be modeled explicitly. |
| MCP or A2A? | MCP for external tools/data, A2A for agent-to-agent coordination, both when a multi-agent system also needs tools. |
| When to use multi-agent? | Only when roles, handoff contracts, and verifier responsibilities are explicit. |
| When to add long-term memory? | Only with provenance, retention rules, user consent, and clear value. Pick a named pattern from ai-context-layer/patterns-catalog.md (P2 for app-orchestrated, P3 for self-editing, P4 for temporal, P6 for conversational). Run the anti-pattern sweep β A1 (no raw transcripts), A11 (forget path required), A13 (provenance mandatory). |
| What must exist before rollout? | Eval suite, telemetry, action limits, human escalation, rollback path, and kill switch. |
| Is this "graph engineering" or "loop engineering"? | Start with references/graph-and-loop-engineering.md; identify the graph's purpose before selecting a runtime or datastore. |
Three deployment shapes for running agents continuously. Pick by the trigger model, not by the framework.
| Shape | Trigger | When to use | Primary guide |
|---|---|---|---|
| A β Triggered / hosted run | Webhook, queue, schedule, /fire |
Per-event agent work, scheduled jobs, fan-out from external sources | ../ai-coding-agents-tasks/references/webhook-and-queue-triggers.md + ../ai-coding-agents-tasks/references/durable-trigger-integration.md |
| B β Always-on bot / voice server | Sessions, WebSocket, SIP call | Support / sales / voice bots with conversational state | ../ai-bot-builder/references/production-deployment.md + ../ai-bot-builder/references/stateful-rollout-and-blue-green.md + ../ai-voice-bots/references/production-deployment.md |
| C β Autonomous loop | PRD + loop driver until acceptance met | Long-horizon work: refactors, migrations, research, Ralph-Loop class | references/autonomous-loop-patterns.md |
Cross-shape requirements:
../agents-hooks/references/budget-and-loop-hooks.mdreferences/24-7-operating-model.md../ai-bot-builder/references/secret-rotation-and-model-fallback.md../software-paas-hosting/SKILL.md and ../software-paas-hosting/references/agent-hosting-matrix.md| Need | Default Agent Shape | Notes |
|---|---|---|
| Deterministic business process | Workflow agent | Best default for auditable production behavior. |
| Bounded external actions | Tool-using agent | Keep tools narrow, typed, and permission-scoped. |
| Knowledge-grounded answers | RAG agent | Require citations, ACL-aware retrieval, and refusal on missing evidence. |
| Long multi-step work with branching | Planner/executor | Use strict step budgets, checkpoints, and replanning limits. |
| Specialized roles with explicit ownership | Multi-agent orchestrator | Handoffs are APIs; add verifier/evaluator roles early. Score the design against the MAST failure taxonomy β do not re-derive it: ../agents-subagents/references/mast-failure-taxonomy.md (14 modes; original Cemri et al. distribution β Specification/System Design 41.8% / Inter-Agent Misalignment 36.9% / Task Verification 21.3% β figures vary across secondary write-ups, verify against the primary paper before quoting; NeurIPS 2025 Datasets & Benchmarks track β arXiv:2503.13657). |
| Desktop or browser control | OS agent | Require sandboxing, UI verification, and action gating. |
| Code changes and CI feedback | SWE agent | Require repo isolation, tests, review gates, and rollback. |
| Autonomous improvement of code, prompts, or artifacts | Research / experiment agent | Fixed eval metric, bounded modification surface, keep/revert loop |
A research/experiment agent iterates autonomously: suggest a change β apply it β evaluate β keep or revert β repeat. The pattern works on anything with a measurable evaluation function.
| Component | Purpose | Example |
|---|---|---|
| Modification surface | What the agent can change | One file (train.py), one prompt, one config |
| Eval function | How to score the result | val_bpb, yes/no checklist (3-6 questions), latency measurement |
| Keep/revert rule | When to keep a change | Score improves; revert if it regresses |
| Termination | When to stop | N rounds, target score reached, or manual stop |
| Ledger | Experiment history | Git commits, results.tsv, changelog with reasoning |
Design constraints:
See: autoresearch (ML training), Lehmann's skill-optimization adaptation (prompt/skill improvement).
| If the system needs... | Use |
|---|---|
| tool calls, database access, file access, prompts, resources | MCP |
| task handoffs, agent cards, multi-agent routing | A2A |
| both tools and collaborating agents | MCP + A2A |
Protocol defaults:
trace_id propagation.stdio or Streamable HTTP for MCP transports; treat older SSE-only guidance as compatibility material, not the default.stdio interface has a by-design configβOS-command execution path (CVE-2026-30623; ~7k public servers exposed; Anthropic confirmed by-design and declined a protocol-level fix β input sanitization is the integrator's responsibility). Never pass untrusted server config into an stdio MCP launch; sandbox the MCP host process. Verified multi-source, April 2026.Define agent personas as structured, versioned artifacts with explicit expertise, constraints, and expected outputs. This pattern treats agent definitions as reviewable code rather than ad-hoc prompt strings.
A well-defined agent spec includes:
| Field | Purpose |
|---|---|
| Role | What the agent is responsible for (e.g., "Architect", "QA reviewer") |
| Expertise | Domain knowledge and capabilities |
| Constraints | What it must not do, boundaries of authority |
| Expected outputs | Artifacts it produces (specs, reviews, plans, code) |
| Interaction rules | How it communicates with other agents or the human |
Benefits: agents can be reviewed in PRs, diffed between versions, and composed into teams with explicit role boundaries.
For current delivery methods and when to borrow from GSD, BMAD, Spec Kit, OpenSpec, MADD, or AI-SDLC, see references/agent-delivery-methods.md.
Match agent sophistication to task complexity. Do not use a full multi-agent orchestration for a bug fix, and do not use a single prompt for a platform migration.
| Task Complexity | Agent Approach |
|---|---|
| Config change, typo | Direct prompt, no agent infrastructure |
| Bug fix, small feature | Single agent with bounded tools |
| Multi-module feature | Lead + 2-3 specialized workers |
| Cross-service migration | Full orchestration with persona definitions, debate, and verification |
The decision to scale up should be driven by observed ambiguity, not assumed complexity.
For fresh-context workers, durable state, and session-vs-project boundaries, see references/context-rotation-and-state.md.
assets/core/agent-template-standard.mdassets/core/agent-template-quick.mdassets/core/agent-template-specialized.mdassets/agent-template-ainative-sdlc.mdassets/checklists/agent-safety-checklist.mdassets/tools/tool-definition.mdassets/tools/tool-validation-checklist.mdassets/multi-agent/manager-worker-template.md, assets/multi-agent/evaluator-router-template.mdassets/rag/rag-basic.md, assets/rag/rag-advanced.md, assets/rag/hybrid-retrieval.md| Script | Purpose |
|---|---|
scripts/agent_eval_runner.py |
Read JSONL task/expected/actual triples and report pass rates (offline). For adversarial suites and multi-turn harnesses, delegate to ../qa-agent-testing/SKILL.md. |
scripts/claude-usage.py |
Parse Claude Code usage logs |
scripts/codex-usage.py |
Parse Codex usage logs |
references/index.mdreferences/build-vs-not-decision.mdreferences/protocol-decision-tree.mdreferences/modern-best-practices.mdreferences/agent-delivery-methods.mdreferences/evaluation-and-observability.mdreferences/coding-agent-usage-tracking.mdreferences/context-rotation-and-state.mdreferences/deployment-ci-cd-and-safety.mdreferences/autonomous-loop-patterns.mdreferences/graph-and-loop-engineering.mdreferences/24-7-operating-model.mdreferences/tool-design-specs.md, references/api-contracts-for-agents.mddata/sources.json../ai-architecture-advisor/SKILL.md../ai-llm/SKILL.mdai-bot-builder../ai-rag/SKILL.md../ai-vector-brain/SKILL.md../agents-mcp/SKILL.mdagents-subagents../agents-swarm-orchestration/SKILL.md../agents-hooks/SKILL.md../agents-skills/SKILL.md../agents-memory/SKILL.md../qa-agent-testing/SKILL.md../qa-observability/SKILL.md../software-security-appsec/SKILL.mdWhen users ask for:
verify with web search and primary sources before answering.
Volatile areas to re-check every time:
If browsing is unavailable, use data/sources.json, say what is assumed, and avoid strong ranking claims.
Before applying this skill on a non-trivial task, read learnings.consolidated.md in this directory (and learnings.md if present).
After applying it, if you encountered a pattern worth remembering, a mistake worth preventing, or a domain fact that surprised you, append one dated bullet to learnings.md via agents-skills-feedback-loop/scripts/append_learning.py. Do not modify SKILL.md itself.