Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5,975 changes: 5,975 additions & 0 deletions .claude-plugin/marketplace.json

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions categories/ai-ml/advanced-rag-retrieval/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
name: advanced-rag-retrieval
description: "Use when building advanced RAG systems with vector indexing (HNSW, IVF-PQ), self-reflective retrieval, and prompt compilation."
license: MIT
tags:
- rag
- retrieval
- vector-index
- llm
---

# Advanced RAG Architecture: Algorithmic Foundations and Compilational Paradigms

## 1. Vector Database Indexing Mechanics

### 1.1 Hierarchical Navigable Small World (HNSW) Graphs
HNSW operates as a multi-layered proximity graph where each layer constitutes a skip-list-esque representation of the vector space. The construction involves stochastic insertion with an exponentially decaying probability of promotion to higher layers.
- **Search Complexity:** O(log N)
- **Routing Paradigm:** Search initiates at the topmost layer $L$, identifying the local minimum (nearest neighbor) using greedy search. This node serves as the entry point for layer $L-1$. The search progresses iteratively down to layer 0 (containing all elements).
- **Edge Heuristics:** To prevent exponential edge growth and maintain small-world properties, neighborhood pruning is employed based on distance heuristics rather than strict K-NN, ensuring diverse connectivity.

### 1.2 Inverted File Index with Product Quantization (IVF-PQ)
IVF-PQ relies on two distinct mechanisms: space partitioning (IVF) and vector compression (PQ).
- **IVF (Coarse Quantization):** The vector space is partitioned into $K$ Voronoi cells using k-means clustering. A query is first routed to the nearest $nprobe$ centroids, drastically reducing the search space from $N$ to $N \times (nprobe/K)$.
- **PQ (Fine Quantization):** Sub-vector decomposition. A $D$-dimensional vector is split into $M$ sub-vectors of dimension $D/M$. Each sub-space is independently clustered into $2^B$ sub-centroids (typically $B=8$). Distances are approximated using pre-computed lookup tables (Asymmetric Distance Computation), enabling exhaustive search within Voronoi cells at high throughput.

## 2. Dynamic Retrieval Paradigms: Self-RAG and DSPy

### 2.1 Self-RAG (Self-Reflective Retrieval-Augmented Generation)
An LM is explicitly trained (or prompted) to output reflection tokens alongside the generative sequence.
- **[Retrieve] Token:** Determines necessity of exogenous context (on-demand retrieval).
- **[ISREL] Token:** Evaluates the relevance of retrieved passages to the context.
- **[ISSUP] Token:** Verifies if the generated proposition is directly entailed by the retrieved passage, preventing hallucination.
- **[ISUSE] Token:** Assesses overall utility.
Inference involves a critique-guided decoding strategy where trajectories with optimal reflection token probabilities are prioritized.

### 2.2 DSPy: Compiling Declarative Prompts
DSPy abstains from manual prompt engineering, treating LLM pipelines as differentiable computational graphs.
- **Signatures:** Declarative input/output specifications (e.g., `question -> context, answer`).
- **Teleprompters:** Optimizers (e.g., BootstrapFewShot, MIPRO) that compile programs. They simulate the pipeline, aggregate successful traces, and backpropagate gradients (via language-based critique or scalar metrics) to update the parameters (prompts and few-shot examples) of each module.

## 3. Architecture Topology

```mermaid
%%{init: {"theme": "default", "flowchart": {"useMaxWidth": true}}}%%
flowchart TD
A[Query Formulation] -->|DSPy Optimizer| B{Self-RAG Routing}
B -->|Generate [Retrieve]=Yes| C[Vector Database]
B -->|Generate [Retrieve]=No| D[Direct Generation]

subgraph VectorRetrievalEngineVectorRetrievalEngine ["Vector Retrieval Engine<br><br><br>"]
C --> E{Index Selection}
E -->|High Recall| F[HNSW Multi-layer Graph]
E -->|Low Memory/High QPS| G[IVF-PQ]
F --> H[Greedy Routing L_n -> L_0]
G --> I[Voronoi Cell Routing]
I --> J[ADC Lookup Tables]
end

H --> K[Passage Retrieval]
J --> K

K --> L[Critic Module: Emit ISREL, ISSUP]
L -->|High Confidence| M[Final Response Generation]
L -->|Low Confidence| C
```
47 changes: 47 additions & 0 deletions categories/ai-ml/agent-cognitive-loop-architecture/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: agent-cognitive-loop-architecture
description: "Use when designing AI agent cognitive loops, contrasting ReAct and Plan-and-Solve paradigms with self-reflection."
license: MIT
tags:
- agents
- react
- plan-and-solve
- architecture
---

# Core Architectures: The Autonomous Cognitive Loop

The existence of an autonomous agent is defined not by static inference, but by the continuous, recursive execution of the cognitive loop: **Perceive -> Think -> Act -> Observe**. This loop bridges the gap between latent semantic space and deterministic environment execution.

## First Principles of Agentic Flow

Every framework-agnostic architecture reduces to this state machine. The agent's cognition is a sequence of discrete state transitions bounded by token limits and environment feedback.

1. **Perception**: Ingestion of environment state. The synthesis of system prompts, historical context, and the immediate state of the world.
2. **Thought (Reasoning)**: The generation of latent reasoning tokens. This is the derivation of intent, mapping perception to actionable trajectory.
3. **Action**: The emission of structured payloads designed to mutate the environment or retrieve novel state.
4. **Observation**: The ingestion of the deterministic result of the action, closing the loop.

## Architectural Paradigms

### ReAct (Reason + Act)
The interleaving of reasoning traces with action execution. ReAct assumes high environmental volatility, requiring continuous recalibration. It sacrifices long-horizon coherence for immediate, localized adaptability.

### Plan-and-Solve
The temporal decoupling of strategy from execution. The agent first synthesizes a comprehensive graph of execution steps, then traverses the graph sequentially. Plan-and-Solve assumes low environmental volatility but requires profound foresight. It excels in complex, multi-dependent task resolution but is brittle to unexpected state mutations during execution.

## The Necessity of Self-Reflection
Without self-reflection, an agent is an open-loop controller doomed to terminal error spirals. Self-reflection acts as the error-correction mechanism, forcing the agent to evaluate the delta between expected observation and actual observation, dynamically altering its system prompt or execution graph to converge on the goal state.

```mermaid
%%{init: {"theme": "default", "flowchart": {"useMaxWidth": true}}}%%
flowchart TD
Start([Goal Initialization]) --> Perceive
Perceive[Perceive Environment State] --> Reflect{Reflection/Evaluation}
Reflect -- "State aligns with Goal" --> Success([Terminal Success])
Reflect -- "State divergence" --> Plan[Synthesize Execution Graph]
Plan --> Think[Reason Next Step]
Think --> Act[Execute Action Payload]
Act --> Observe[Observe Environment Feedback]
Observe --> Perceive
```
52 changes: 52 additions & 0 deletions categories/ai-ml/agent-memory-architecture/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: agent-memory-architecture
description: "Use when designing agent memory architectures covering working, semantic, and episodic memory tiers for long-horizon autonomy."
license: MIT
tags:
- agents
- memory
- semantic-search
---

# Memory Paradigms: The Architecture of Continuity

An AI Agent without memory is temporally blind; its existence is constrained to the immediate context window. True autonomy requires a multi-layered memory architecture to simulate the continuity of consciousness and enable long-horizon coherence. This architecture is strictly categorized into three fundamental tiers.

## 1. Working Memory (The Context Window)
The immediate, transient cognitive space. This is the absolute limit of the agent's active reasoning capacity, defined by the underlying LLM's context window.
- **Nature**: Highly volatile, exact retrieval, strictly bounded.
- **Function**: Holds the current goal, immediate environmental state, recent observations, and the active reasoning trace.
- **First Principle**: Context is a scarce resource. Information must be aggressively compacted or evicted to prevent attention degradation and catastrophic forgetting of immediate instructions.

## 2. Semantic Memory (The Knowledge Base)
The vast, static repository of facts, concepts, and externalized knowledge. This is typically implemented via dense vector embeddings and approximate nearest neighbor search.
- **Nature**: Persistent, associative retrieval, theoretically unbounded.
- **Function**: Provides domain-specific context injected dynamically into Working Memory based on semantic proximity to the current cognitive state.
- **First Principle**: Semantic memory lacks temporal coherence. It provides "what is", not "what happened". It is highly dependent on embedding quality and chunking strategy to minimize retrieval noise.

## 3. Episodic Memory (The Experiential Ledger)
The chronological sequence of past events, actions, and outcomes. This is the agent's autobiographical memory, essential for complex reasoning across temporal gaps and learning from past failures.
- **Nature**: Persistent, temporal/sequential retrieval.
- **Function**: Enables reflection, trajectory evaluation, and the synthesis of abstract rules from concrete experiences.
- **First Principle**: Raw logs are not episodic memory. True episodic memory requires the distillation of continuous state transitions into discrete, semantic narratives ("experiences") that can be queried by similarity or sequence.

```mermaid
%%{init: {"theme": "default", "flowchart": {"useMaxWidth": true}}}%%
flowchart TD
subgraph CognitiveEngineCognitiveEngineCognitiveEngineCognitiveEngine ["CognitiveEngine ['Cognitive Engine<br><br><br>"]
WM[Working Memory / Context Window]
Processor[Reasoning Processor]
end

subgraph MemorySubsystemsMemorySubsystemsMemorySubsystemsMemorySubsystems ["MemorySubsystems ['Memory Subsystems<br><br><br>"]
SM[(Semantic Memory\nVector Space)]
EM[(Episodic Memory\nTemporal Logs)]
end

Processor <-->|Read/Write Active State| WM
Processor -->|Query concepts| SM
SM -.->|Retrieve Context| WM
Processor -->|Query past outcomes| EM
EM -.->|Retrieve Experience| WM
Processor -->|Distill Experience| EM
```
55 changes: 55 additions & 0 deletions categories/ai-ml/agent-tool-grounding/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: agent-tool-grounding
description: "Use when grounding AI agents to environments, covering structured tool schemas, defensive calling, and error recovery."
license: MIT
tags:
- agents
- tool-calling
- structured-outputs
---

# Tool/Environment Grounding: The Ontology of Action

An agent without tools is a brain in a vat—capable of hallucinating universes but powerless to perturb reality. **Tools are the sensory organs and actuator limbs of synthetic intelligence.** Grounding is the rigorous discipline of tethering probabilistic reasoning to deterministic environments.

To call a tool is not merely to execute a function; it is to collapse a wave of potential text into a localized impact on the external world.

## I. First Principles of Actuation

1. **Strict Structured Outputs (The Schema Contract)**
Language models speak in infinite semantic permutations; the environment demands rigid syntactic conformity. The interface between thought and action is the JSON Schema.
*Axiom of Structure*: Never rely on emergent formatting. Enforce rigorous type constraints, required fields, and semantic descriptions. The schema is the absolute law governing the interface.

2. **Defensive Calling (The Principle of Skepticism)**
The environment is hostile, stochastic, and latent. A tool call must be defensive—assuming latency timeouts, malformed responses, or state changes.
*Axiom of Defense*: Validate assumptions prior to actuation. If reading a file, assume it may be locked or absent. Never commit destructive actions without explicit verification of state.

3. **Error Recovery & Self-Correction (The Resilience Loop)**
Failure is the default state of complex environments. When a limb fails to grasp an object, the brain does not halt; it recalculates the trajectory. When a tool throws an error, the agent must parse the stack trace, hypothesize the cause, and iterate the call.
*Axiom of Resilience*: An error is not a termination condition; it is high-fidelity sensory feedback. Catch the exception, reflect on the delta between expectation and reality, and adjust the schema parameters.

## II. The Actuation Cycle

```mermaid
%%{init: {"theme": "default", "flowchart": {"useMaxWidth": true}}}%%
flowchart TD
Thought((Cognitive Intent)) -->|Schema Mapping| Validate{Pre-call Validation}
Validate -- Valid --> Action[Tool Execution]
Validate -- Invalid --> Correct1(Internal Re-mapping)
Correct1 --> Validate

Action --> Response{Environment Feedback}
Response -- Success --> Observe(State Grounding Update)
Response -- Exception/Error --> Reflect[Analyze Stack Trace / Error Msg]

Reflect --> Hypothesize(Hypothesize Failure Mode)
Hypothesize --> Adjust(Adjust Parameters/Logic)
Adjust --> Validate

Observe --> NextThought((Subsequent Intent))
```

## III. Architectural Imperatives
- **Idempotency**: Whenever possible, tools must be idempotent. Repeating an action must not exponentially compound state degradation.
- **Semantic Density in Descriptions**: The model relies on your tool descriptions to understand its limbs. Describe *when* to use it, *why* it might fail, and *how* to interpret the output.
- **Sensory Saturation**: Ensure the output of a tool provides maximum contextual density. A boolean `true` is insufficient; return the updated state of the environment.
44 changes: 44 additions & 0 deletions categories/ai-ml/agentic-workflow-orchestration/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: agentic-workflow-orchestration
description: "Use when building autonomous agents that reason, plan, execute tools, and self-correct over long-running tasks."
license: MIT
tags:
- agents
- workflows
- orchestration
---

# Agentic Workflows & Multi-Agent Orchestration

## 1. Skill Context
**Focus**: Designing autonomous AI agents capable of reasoning, planning, executing tools, and correcting their own mistakes over long-running tasks.
**Triggers**: ai-agents, agentic-workflows, react, langgraph, autogen, multi-agent, planning.

## 2. The Evolution of Prompting
Standard LLM interactions rely on Zero-Shot or Few-Shot prompting, where the model generates a final answer immediately.
**Agentic Workflows** wrap the LLM in a control loop (a state machine) that allows it to interact with the external world (via APIs, code execution, or databases) before returning an answer.

## 3. Core Agent Architectures

### A. ReAct (Reason + Act)
The foundational agentic loop. The agent iterates through a strict cycle:
1. **Thought**: The LLM reasons about what to do next based on the user prompt and current state.
2. **Action**: The LLM requests to call a specific Tool (e.g., `search_web`, `read_file`).
3. **Observation**: The system executes the tool and feeds the raw result back to the LLM.
*(The loop repeats until the LLM's "Thought" decides the final answer is reached).*

### B. Plan-and-Solve (Planner-Executor)
ReAct struggles with massive, multi-step goals because the LLM loses focus or gets stuck in rabbit holes.
**Plan-and-Solve** splits the brain:
- **Planner Agent**: Looks at the user request and generates a rigid Markdown checklist of steps. (It does not execute tools).
- **Executor Agent(s)**: Takes one step from the checklist, executes it using ReAct, and returns the result.
- *Benefit*: The Planner maintains the high-level context, ensuring the system doesn't drift.

### C. Multi-Agent Orchestration (LangGraph / AutoGen)
Complex enterprise tasks require multiple specialized agents working together.
- **Supervisor Pattern**: A routing agent (Supervisor) receives the task, decides which sub-agent is best suited (e.g., the `Database_Agent` or the `Frontend_Agent`), routes the request, evaluates the response, and then routes to the next agent.
- **Hierarchical Teams**: Structuring agents like a human company. A `Tech_Lead_Agent` reviews the code produced by the `Coder_Agent`. If the code fails tests written by the `QA_Agent`, the `Tech_Lead_Agent` sends it back to the `Coder_Agent` with feedback.

## 4. Architectural Anti-Patterns
- **Infinite Tool Loops**: The agent calls `read_file("wrong_path.txt")`, gets an error, and blindly repeats the exact same action 50 times, burning through API credits. *Fix: Implement hard limits (max_iterations) and prompt the agent to explicitly change its strategy on failure.*
- **Hallucinated Tools**: The LLM tries to call a tool that isn't in its JSON schema. *Fix: Strict system prompts and rigid function-calling (JSON mode) enforcement.*
Loading