agentleFS
jamestorrevillasjamestorrevillas/dev-skills/.github/skills/ai-agent-design/SKILL.md

ai-agent-design

Skill4 starsChanged 9 months agoMITView on GitHub

Use this skill when building AI agents, designing multi-agent systems, integrating LLMs into applications, building RAG pipelines, working with vector databases, implementing MCP servers, or designing agent communication and orchestration patterns. Trigger on keywords like: agent, LLM, RAG, embeddings, vector DB, orchestration, tool use, memory, intent clarification, MCP, LangChain, LangGraph, CrewAI, AutoGen, Microsoft Agent Framework.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. 0 are common, 13 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 13

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Before writing agent logic, generate a spec or task list file:

    line 21
  2. Distinctive:

    Use semantic chunking — break on meaning, not character count

    line 73
  3. Distinctive:

    Always include metadata: source, page, section, timestamp

    line 75
  4. Distinctive:

    Always validate tool outputs before passing to the next step

    line 123
  5. Distinctive:

    When an agent receives an ambiguous request:

    line 132
  6. Distinctive:

    Use MCP when the tool needs to be reusable across multiple agents/platforms

    line 169
  7. Distinctive:

    Use direct integration for project-specific, one-off tool implementations

    line 170
  8. Distinctive:

    Validate and sanitize: all inputs before passing to tools

    line 180
  9. Distinctive:

    Use system prompt injection protection — separate user input from system instructions with clear delimiters

    line 183
  10. Distinctive:

    Run tests/lint on generated code before presenting

    line 214
  11. Distinctive:

    Verify output format matches requirements

    line 215
  12. Distinctive:

    Use a separate validator step (different model or prompt) to check generator output

    line 216
  13. Distinctive:

    Never present unverified output as done

    line 217

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

AI Agent Design

Core Philosophy

Agents are not magic — they are systems with inputs, outputs, memory, tools, and decision logic. Design them with the same rigor as any production software. Every agent should have a clear purpose, defined boundaries, and explicit failure modes.

Agent Design Principles

1. Clarify Intent Before Acting

An agent must ask clarifying questions when the user's intent is ambiguous — before executing any irreversible action. Use this pattern:

  • Is the goal clear? If not, ask one focused question.
  • Are the constraints known? (scope, output format, data sources)
  • What does success look like?

2. Specification Before Code

Before writing agent logic, generate a spec or task list file:

  1. Define the agent's role and responsibilities
  2. List all tools it needs access to
  3. Define input/output contracts
  4. Identify failure modes and fallback behavior
  5. Then write the code

3. Single Responsibility

Each agent should do one thing well. Prefer a team of specialized agents over one general-purpose agent.


Orchestration Patterns

PatternWhen to UseDescription
SequentialLinear pipelinesAgents chain in fixed order (draft → review → publish)
SupervisorComplex multi-module tasksLead agent routes to specialized workers
ReActAutonomous problem solvingCombines reasoning (Thought) + acting (Tool Use)
Group ChatCollaborative tasksMulti-agent communication with human oversight
DAGStateful workflowsDirected acyclic graph for cyclical, stateful orchestration

Framework Selection Guide

FrameworkBest ForStatus
LangGraphComplex stateful agents, cyclical workflows, multi-agent orchestration, production-grade✅ Active — GA May 2025
LangChainSimple RAG pipelines, linear workflows, quick prototypes✅ Active — use for RAG, not for agents
CrewAIRole-based multi-agent teams ("Manager", "Researcher", "Writer")✅ Active
Microsoft Agent FrameworkEnterprise agents in Azure ecosystem — replaces AutoGen + Semantic Kernel✅ Active — Public Preview Oct 2025, GA targeted Q1 2026
AutoGenLegacy — still works but no new features⚠️ Maintenance mode since Oct 2025
Custom (MCP)Lightweight, portable, interoperable agent tools via open standard✅ Active

LangChain vs LangGraph — Which to Use

The LangChain team now explicitly recommends this split:

  • LangGraph → for agents: stateful, cyclical, multi-agent, long-running tasks
  • LangChain → for RAG and linear pipelines: simple document Q&A, step-by-step transforms

LangGraph is built on top of LangChain — you can use both together, starting with LangChain and dropping to LangGraph when you need more control.


RAG Pipeline Design

Standard RAG Flow

User Query → Embed Query → Vector Search → Retrieve Chunks → Augment Prompt → LLM → Response

Chunking Strategy (2026 Best Practice)

  • Use semantic chunking — break on meaning, not character count
  • Chunk size: 256–512 tokens for precision; 1024 for narrative content
  • Always include metadata: source, page, section, timestamp

Hybrid Search (Recommended)

Combine dense vectors (semantic) + sparse vectors (keyword) for best recall:

Final Score = α × Dense Score + (1 - α) × Sparse Score

Vector Database Selection

DBBest For
pgvectorExisting PostgreSQL stack, simple use cases
PineconeManaged, production-scale, minimal ops
WeaviateMulti-modal, hybrid search built-in
MilvusHigh-performance, self-hosted, large scale
ChromaLocal dev, prototyping

Agent Memory Architecture

TypeDescriptionImplementation
In-contextCurrent conversation windowChat history array
External short-termSession-scoped memoryRedis / in-memory store
External long-termPersistent across sessionsVector DB + metadata
EpisodicSummarized past interactionsSummarization chain → vector store

Context Rot Warning: Long context windows degrade agent quality over time. Implement a summarization step every N turns to maintain relevance.


Tool Use & Function Calling

Tool Definition Pattern

Every tool needs:

name: descriptive_tool_name
description: When to use this tool and what it does (be explicit)
parameters:
  - name: param_name
    type: string
    description: What this parameter expects
    required: true

Tool Use Best Practices

  • Tools should be idempotent where possible
  • Always validate tool outputs before passing to the next step
  • Implement timeouts and retries for external tool calls
  • Log all tool invocations for debugging

Agent Communication Patterns

Intent Clarification Protocol

When an agent receives an ambiguous request:

  1. Identify the ambiguity — what specifically is unclear?
  2. Ask one question — the most important one, not all of them
  3. Propose a default — "I'll assume X unless you tell me otherwise"
  4. Confirm before irreversible actions — always ask before deleting, publishing, or sending

Progress Reporting

For long-running tasks, agents should report:

[Step 1/4] Fetching documents... ✓
[Step 2/4] Chunking and embedding... ✓
[Step 3/4] Querying vector store...

Error Communication

✗ Tool failed: [tool_name]
Reason: [specific error]
Fallback: [what I'm doing instead]

MCP (Model Context Protocol)

MCP is the open standard for connecting agents to external tools and data sources. Use it when building portable, interoperable agent tools.

MCP Server Structure

my-mcp-server/
├── server.py (or index.ts)
├── tools/
│   └── my_tool.py
└── README.md

When to Use MCP vs Direct Integration

  • Use MCP when the tool needs to be reusable across multiple agents/platforms
  • Use direct integration for project-specific, one-off tool implementations

See mcp-builder skill for detailed MCP server implementation guidance.


Security & Safety

  • Never allow agents to execute arbitrary code without sandboxing
  • Implement rate limiting on all LLM API calls
  • Validate and sanitize all inputs before passing to tools
  • Log all agent decisions for auditability
  • Implement guardrails to prevent runaway token costs or recursive loops
  • Use system prompt injection protection — separate user input from system instructions with clear delimiters

Resilient Agent Design (Self-Healing)

Agents fail in production. Design for recovery from the start.

Validate-and-Retry Loop (LoopAgent Pattern)

Generate output → Validate output → If invalid: feedback + regenerate
Max iterations: 3  ← circuit breaker to prevent infinite loops

Plan–Validate–Execute–Observe–Replan

PLAN:     Generate plan, check feasibility before acting
EXECUTE:  Take action
OBSERVE:  Did it succeed? Check outputs, run tests
REPLAN:   If observation shows failure → adjust and retry
STOP:     If max retries hit → report failure clearly, ask for help

Agent Fallback Hierarchy

Primary approach fails → Try alternative approach
Alternative fails     → Request clarification from developer
Clarification absent  → Safe default action or graceful stop

Output Validation Before Presenting

  • Run tests/lint on generated code before presenting
  • Verify output format matches requirements
  • Use a separate validator step (different model or prompt) to check generator output
  • Never present unverified output as done

Circuit Breaker for Agents

Set hard limits to prevent runaway behavior:

  • Max tool call iterations per task (e.g. 10)
  • Max token spend per session
  • Max retries per failing step (e.g. 3)
  • Timeout per tool invocation

See self-healing-mindset skill for the full resilience philosophy and code patterns.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.