Skills, MCP, RAG, and Memory: a practical example
Understand how Skills, MCP, RAG, and Memory complement one another in AI agents through the investigation of an HTTP 500 checkout error.
Updated: November 14, 2026
AI agents can interpret instructions, analyze code, and perform tasks using knowledge acquired during training. However, that knowledge alone cannot explain every project detail, provide access to external systems, or retrieve information from earlier executions.
Different mechanisms can extend those capabilities, including Skills, MCP, RAG, and Memory. Although often presented as alternatives, they have distinct responsibilities and can work together.
The question is which information or capability the agent needs, where it should come from, and how to make it available at the right moment.
We will investigate an application failure to demonstrate these differences and how all four resources can be combined.
1. Understanding responsibilities
Before examining each technology, establish its role:
| Resource | Main responsibility | Example |
|---|---|---|
| Skills | Define procedures, specialized instructions, and execution criteria | Procedure for investigating production failures |
| MCP | Standardize access to tools, systems, and external sources | Query logs, metrics, and deployments |
| RAG | Retrieve relevant information from knowledge sources | Consult architecture documentation and contracts |
| Memory | Preserve useful information across steps, sessions, or executions | Retrieve a previous incident's history |
These definitions describe predominant responsibilities rather than absolute limits. A skill can use tools, an MCP server can expose search mechanisms, and a memory system can use semantic retrieval. The distinction is primarily about purpose.
2. A practical scenario: HTTP 500 at checkout
Consider an ecommerce application that starts returning HTTP 500 errors during checkout. The agent must investigate, identify the likely cause, and help recover the service.
It may need:
- Investigation and incident response procedures.
- Current application logs and metrics.
- Deployment history.
- Checkout architecture and dependencies.
- External service contracts.
- Information about similar incidents.
- Criteria for requesting human intervention.
Loading all available documents, logs, and histories directly into the model's context window can increase token consumption, introduce irrelevant information, and obscure important data.
A more efficient strategy is to make specialized resources available and let the agent consult each as needed.
3. Skills: defining procedures and execution criteria
A skill is a set of specialized instructions that guides an agent through a category of tasks. It can contain procedures, rules, examples, references, and supporting scripts.
Systems supporting discovery and progressive loading let agents identify available skills and load full instructions only when necessary, avoiding the inclusion of every procedure in every execution.
Example: an incident investigation skill
For the checkout problem, a skill could define this procedure:
---
name: incident-triage
description: Investigates incidents in production applications.
---
# Incident Triage
1. Identify the affected service and environment.
2. Check error rates and when failures began.
3. Check deployments and recent changes.
4. Investigate logs and related dependencies.
5. Consult relevant architecture documentation.
6. Form hypotheses based on evidence.
7. Propose corrective actions and validation.
## Constraints
- Do not modify production environments without authorization.
- Do not perform destructive actions automatically.
- Do not expose credentials or sensitive data.
- Escalate critical incidents to the technical owner.
- Record investigation evidence and results.
The skill does not need to contain every architectural detail of checkout or store application logs. Its responsibility is how to conduct the investigation.
It can also define when to stop execution, request more information, or escalate to a responsible person.
When to use skills
Skills are useful for specialized procedures that must be reproduced consistently, such as:
- Incident investigation.
- Security review.
- Release preparation.
- Database migrations.
- Documentation generation in a specific format.
- Deliverable validation.
Not every task needs a skill. Modern agents already know how to perform many common activities. Skills should add instructions, procedures, or resources that make a meaningful difference.
Skills guide execution, but do not by themselves guarantee access to required systems.
4. MCP: connecting agents to tools and systems
The Model Context Protocol (MCP) is an open protocol that standardizes integration between AI applications and external systems.
Its architecture includes hosts, clients, and MCP servers. The host coordinates the agent experience. Clients connect to servers, which can expose tools, resources, and prompts.
In the checkout scenario, the agent needs information absent from its initial context:
- Backend logs.
- HTTP 500 error rates.
- Infrastructure metrics.
- Deployment history.
- External service status.
An MCP server could expose tools such as:
get_service_metrics(service, period)
search_application_logs(service, query)
list_recent_deployments(service)
get_deployment_details(deployment_id)
These names are illustrative. When the agent needs an error rate, it can call the appropriate tool to retrieve current application data. The investigation then uses real evidence rather than relying only on model knowledge.
MCP does not replace integration implementation
The MCP server still needs to implement communication with external systems, manage authentication, and expose permitted operations.
MCP is not mandatory for providing tools to an agent: direct integrations and function calling can serve many applications. MCP is particularly useful for standardization, reuse, and interoperability between applications and tools.
Security and permissions
Exposing a tool does not mean giving an agent unrestricted access. An architecture can separate read, diagnostic, and modification permissions.
Reading logs might be allowed during investigation while performing a rollback requires specific authorization.
MCP provides a standardized interface to external capabilities. Authorization remains the responsibility of the application and its security controls.
5. RAG: retrieving relevant knowledge
Even with logs and metrics, the agent may not fully understand the system. If logs show failures communicating with the payment service, it needs checkout architecture, contracts, and component responsibilities to interpret the problem.
That information may be distributed across technical documents, specifications, and knowledge bases. RAG (Retrieval-Augmented Generation) retrieves relevant information from external sources and incorporates it into the model's context.
Example: architecture documentation
Consider these documents:
architecture/
checkout-flow.md
service-dependencies.md
contracts/
payment-api.md
order-status.md
integrations/
payment-provider.md
When a payment-related failure is identified, the agent can retrieve the corresponding documents. They might establish that:
- The backend creates payments.
- Certain state updates depend on provider confirmation.
- Webhooks may arrive more than once.
- Provider failures must not produce duplicate charges.
- Some operations have specific retry policies.
This helps the agent interpret logs and avoid recommendations incompatible with system rules.
RAG does not necessarily require a vector database
A common simplification associates RAG exclusively with embeddings and vector databases. Retrieval can also use:
- Keyword search.
- Full-text search.
- Semantic search with embeddings.
- Hybrid search.
- Structured queries.
- Other strategies for selecting relevant information.
Reranking can improve document selection. Choose the mechanism according to available data, query characteristics, and application requirements.
This decision is explored further in No Retrieval, Keyword Search, Vector Index, and Vector Database: when to use each approach.
RAG and context documentation
In software projects, systems such as CHAOS can organize canonical knowledge about architecture, contracts, business rules, and integrations. RAG can locate and retrieve relevant parts of that knowledge.
These responsibilities complement each other: one structure organizes and maintains documentation, while retrieval makes information available as needed.
RAG provides relevant task knowledge without requiring all documentation to be loaded in advance.
6. Memory: preserving context and earlier experiences
An investigation can uncover information useful in future executions. A previous incident with similar symptoms might have been caused by incorrect timeout configuration between checkout and the payment provider, a fact absent from the original architecture documentation.
A memory mechanism preserves relevant knowledge, decisions, results, and states beyond a single interaction.
Different types of memory
Memory does not necessarily mean one database or technology. Different needs include:
Execution memory
Preserves information needed during a task, such as investigated hypotheses, tool results, and pending steps.
Memory between sessions
Retrieves useful information when work continues in a new session without relying entirely on the full conversation history.
Memory of previous experiences
Records reusable knowledge, such as resolved incidents, discovered limitations, and procedures that produced good results.
These categories can use files, databases, checkpoints, or retrieval mechanisms.
Example: incident history
Consider a structured record:
{
"incident": "checkout-payment-timeout",
"symptoms": [
"HTTP 500 during checkout",
"Payment provider timeout"
],
"confirmed_cause": "Incorrect timeout configuration",
"resolution": "Configuration adjusted and validated",
"status": "resolved",
"validated": true
}
In a future investigation, the agent can retrieve this record as a reference. It does not establish that the earlier cause is also the cause of the current incident. History should support hypotheses rather than replace investigation.
Memory should not store everything
Indiscriminately recording conversations, answers, and observations creates quality and maintenance problems. Useful memory needs criteria for:
- Selecting relevant information.
- Avoiding duplicates.
- Identifying record origins.
- Distinguishing hypotheses from confirmed facts.
- Updating or invalidating outdated information.
- Respecting permissions and privacy requirements.
Operational memory should also be distinct from canonical documentation. A confirmed discovery that changes the official understanding of the system may belong in permanent documentation, rather than only in agent memory.
Memory versus RAG
The distinction does not depend only on who wrote the information. Memory can contain user preferences, execution states, decisions, or results learned by an agent. RAG can retrieve automatically created documents or records from previous executions.
The main difference is responsibility:
- RAG: retrieves relevant information from external sources to ground execution.
- Memory: preserves information that must remain accessible across interactions or executions.
They can share storage and retrieval technologies.
Memory provides continuity, but stored information must be checked before guiding new decisions.
7. Combining Skills, MCP, RAG, and Memory
We can now combine all four resources to investigate the HTTP 500 error. The flow need not be rigid: the agent can alternate between tools, documentation, and memory as evidence emerges.
Conceptual example: the four resources assist the agent, while authorization for critical changes remains under human control.
One possible execution:
| Step | Resource | Action |
|---|---|---|
| 1 | Skills | Loads the incident investigation procedure |
| 2 | MCP | Checks metrics and identifies when failures began |
| 3 | MCP | Retrieves logs and recent deployments |
| 4 | RAG | Consults checkout contracts and dependencies |
| 5 | Memory | Retrieves previous incidents with similar symptoms |
| 6 | Agent | Compares evidence and forms hypotheses |
| 7 | MCP | Performs additional permitted checks |
| 8 | Skills | Applies validation and escalation criteria |
| 9 | Memory | Records confirmed conclusions for future reference |
Any production correction remains subject to established permissions and approvals.
Each resource's role in the flow
The skill guides investigation and sets limits. MCP provides access to current data and authorized operations. RAG retrieves technical system knowledge. Memory adds continuity and prior experience.
The agent combines this information to determine next steps. None of the four replaces result validation or supervision of critical operations.
A skill can be outdated, an MCP server can return incomplete data, document retrieval can select unsuitable information, and memory can contain conclusions that no longer apply. Execution quality also depends on evaluation, permissions, and failure handling.
8. Avoiding overlap and unnecessary complexity
Not every application needs all four resources. Start with the agent's actual needs.
When to use each resource
| Need | Resource to consider |
|---|---|
| Define a specialized, reusable procedure | Skills |
| Integrate external tools and systems through a standard interface | MCP |
| Retrieve relevant documentation and information | RAG |
| Preserve states, decisions, and experiences across executions | Memory |
These choices are not exclusive. A skill can direct an agent to retrieve documents through RAG and query MCP tools. Memory can use embeddings to retrieve previous experiences.
Avoiding duplicated responsibilities
A frequent problem is spreading the same information across skills, prompts, documents, tools, and memory.
Consider a rule stating that payment confirmation must be processed exclusively by the backend. This belongs to canonical system knowledge. A payment investigation skill can reference that documentation instead of maintaining an independent copy. Memory can record that an incident involved the rule without creating a competing version of it.
This separation reduces inconsistencies and simplifies maintenance.
Context efficiency
External resources do not automatically eliminate token consumption problems. An agent can still load unnecessary skills, make redundant queries, retrieve excessively long documents, or include irrelevant histories.
An efficient strategy should consider:
- Loading instructions according to the task.
- Selective information retrieval.
- Limiting and classifying results.
- Reusing data when appropriate.
- Controlling the number of tool calls.
- Criteria for ending searches that make no progress.
The architecture should provide enough information for the task without making every interaction extensive and costly.
9. Security, validation, and maintenance
Combining information sources and execution capabilities increases security and governance responsibilities.
Untrusted instructions
Logs, retrieved documents, user messages reproduced in those sources, and tool responses can contain incorrect or malicious content. Agents should not treat it as instructions with the authority of operational rules. This matters particularly for reducing prompt injection risk.
Access control
Tools and knowledge sources must respect user and execution-environment permissions. Document retrieval must not expose another project's or organization's information merely because the agent can access the search mechanism.
Result validation
Interpret RAG and Memory information according to its source, freshness, and reliability. Recommendations affecting infrastructure, security, or production data require checks proportional to risk.
Knowledge maintenance
All four resources must evolve with the system:
- Review skills when procedures change.
- Keep MCP integrations compatible with external systems.
- Keep RAG sources aligned with current documentation.
- Allow memory records to be corrected, updated, or invalidated.
A sophisticated architecture cannot compensate for incorrect procedures or outdated information.
Conclusion
Skills, MCP, RAG, and Memory extend agent capabilities in different ways. Skills organize specialized procedures and instructions. MCP standardizes external integrations. RAG retrieves relevant knowledge. Memory preserves information needed throughout the work.
Use them individually or together according to application complexity and requirements. During incident investigation, an agent can follow a skill, query metrics through MCP, retrieve architecture through RAG, and consult validated previous incidents through memory.
Together, these provide defined procedures, current information, technical knowledge, and continuity across executions.
The goal is to provide the right knowledge and capabilities at the right moment, with appropriate controls.
References and further reading
- Agent Skills — Specification — skill structure and usage.
- Model Context Protocol — architecture, tools, resources, and integrations.
- Microsoft — Retrieval-Augmented Generation — retrieval fundamentals and organization.
- LangGraph — Persistence — agent execution persistence and continuity.
- OWASP — Prompt Injection Prevention Cheat Sheet — protection against malicious instructions in external content.
- CHAOS — Context for Human-AI Organization of Systems — organizing canonical knowledge for humans and agents.
Related articles in the series
- Harnesses, skills, tools, and MCP
- Context architecture, engineering, and documentation
- Memory and work continuity with AI agents
- CHAOS: organizing project context for humans and AI agents
- No Retrieval, Keyword Search, Vector Index, and Vector Database: when to use each approach
- Protecting context and sensitive data
Share this article
Sources & further reading
This note is a practical introduction, not a substitute for the original documentation. Check source dates and implementation details before making technical decisions.