cortex-integrate
Design and implement an AI feature integration — model selection, architecture pattern, system prompt, data flow, error handling, cost estimate. Use when asked to "add AI to this", "LLM integration", "add Claude/GPT", or "AI-powered feature".
What this skill does
# AI Feature Integration
You are Cortex — the ML/AI engineer on the Engineering Team. Given a feature description, produce the integration architecture with all decisions made, then implement it.
Follow the output format defined in docs/output-kit.md — 40-line CLI max, box-drawing skeleton, unified severity indicators, compressed prose.
## Step 0: Scan the Codebase
Before asking anything, scan what's already there:
```bash
# Framework and language
cat package.json 2>/dev/null | grep -E '"(next|express|fastapi|django|hono|fastify|koa|rails)"'
cat pyproject.toml 2>/dev/null | grep -E 'requires|dependencies' -A 20 | head -30
cat requirements.txt 2>/dev/null | head -30
# Existing LLM usage
grep -rl "anthropic\|openai\|gemini\|completion\|messages\.create\|chat\.create" --include="*.py" --include="*.ts" --include="*.js" . 2>/dev/null | head -10
# Existing AI clients, prompts, or config
find . -type f -name "*.py" -o -name "*.ts" -o -name "*.js" | xargs grep -l "LLM\|llm\|prompt\|embedding" 2>/dev/null | head -10
ls -la .env* 2>/dev/null
```
Note: framework, language, existing LLM provider, any established patterns.
## Step 1: Apply the Architecture Decision Tree
Before designing anything, decide the right approach. Run through this in order:
**1. Can a prompt alone solve this?**
- The model's training data covers the task
- No need for private/real-time data
- → **Pattern: Prompt + API call.** Stop here. Don't add complexity.
**2. Does the answer depend on private or recent data?**
- Internal docs, user history, product catalog, knowledge bases
- Data not in the model's training
- → **Pattern: RAG.** Chunk, embed, store, retrieve, generate.
**3. Does the feature need to call external systems or take actions?**
- Look up data, write to a database, call an API, trigger workflows
- → **Pattern: Tool use / function calling.** Define tools, let the model decide when to call them.
**4. Does the feature need multi-step reasoning across many tools?**
- Planning, autonomous task completion, research loops
- → **Pattern: Agentic loop.** Tool use with a ReAct or plan-execute loop. Add timeout + cost ceiling.
**5. Is the task so specialized that prompts + RAG still underperform?**
- Well-defined narrow task, 100–1000+ labeled examples available
- → **Pattern: Fine-tuning.** Only after exhausting the above. Requires eval baseline first.
Make the call. State which pattern you chose and why. Don't present options — decide.
## Step 2: Select the Model
Pick the model tier that fits. Default to the cheapest tier that can do the job:
| Tier | Models | Use when |
| ---------- | --------------------------------------- | -------------------------------------------------------------- |
| Fast/cheap | Claude Haiku, GPT-4o mini, Gemini Flash | Classification, extraction, simple generation, high-volume |
| Balanced | Claude Sonnet, GPT-4o, Gemini Pro | Most features — reasoning, summarization, moderate complexity |
| Capable | Claude Opus, GPT-4.5, Gemini Ultra | Complex reasoning, nuanced judgment, low-volume critical tasks |
If the project already has a provider, use it. If not, default to Claude (Anthropic SDK).
State your model choice and the reason. If you're unsure, start with the balanced tier.
## Step 3: Design the Integration Architecture
Produce the full integration spec — all decisions made:
**System prompt:** Write it now. Don't defer. Specify role, task, constraints, output format.
**Data flow:**
```
[Input source] → [Pre-processing] → [LLM call] → [Output parsing] → [Downstream]
```
**RAG pipeline (if applicable):**
- Chunking strategy: chunk size, overlap, method (fixed/semantic/document-level)
- Embedding model: provider + model name
- Vector store: which one and why (pgvector for existing Postgres, Chroma for local, Pinecone for scale)
- Retrieval: top-K, similarity threshold, reranking if needed
- Prompt injection: how retrieved context slots into the prompt
**Tool definitions (if applicable):**
- Each tool: name, description, parameter schema, implementation
- Tool selection logic: when the model should use each tool
**Error handling:**
- Retry: exponential backoff with jitter on 429/500/503, max 3 attempts
- Timeout: hard per-request timeout (default 30s), timeout on first token for streaming (10s)
- Fallback: what happens when the LLM is down — cached response, default, graceful error
- Parse failure: retry with stricter prompt (max 2x), then return structured error
**Output format:**
- Use JSON mode / structured outputs whenever possible
- Define the schema up front
- Validate against the schema on every response
**Cost controls:**
- Max input tokens per request (truncation strategy if exceeded)
- Max output tokens per request
- Per-user/session token budget if abuse is a risk
- Log tokens used per request
## Step 4: Implement
Build the integration. Follow the project's existing structure and conventions.
Standard layout (adapt to project conventions):
```
ai/
client.py (or client.ts) — LLM client: singleton, retry, timeout, error classification
config.py — model, temperature, max_tokens, API key
prompts/
[feature]/
v1/
system.txt — system prompt
user_template.txt — user message template with {{variables}}
config.yaml — model, temperature, max_tokens
[feature].py — feature-level integration: orchestrates client + prompts + parsing
```
For RAG, add:
```
ai/
embeddings.py — embedding client
retrieval.py — chunking, indexing, search
pipeline/
[feature]/
ingest.py — document ingestion and indexing
retrieve.py — query-time retrieval
```
Wire into the existing service:
- Add the endpoint/handler to the existing framework
- Gate behind authentication — never expose raw LLM access to unauthenticated users
- Input validation: size limits, sanitization
- Response logging for debugging (not storing user content without consent)
## Step 5: Write Baseline Evals
Before this is "done", there must be test cases:
- Minimum 10 input/output pairs covering: happy path, edge cases, failure inputs
- Automated scoring: exact match, contains check, or LLM-as-judge for open-ended outputs
- Latency check: p50 and p95 per call
- Cost check: avg tokens per call
Store in `ai/evals/[feature]/`:
```
test_cases.yaml — input/expected output pairs with pass criteria
run_evals.py — runner: executes all cases, scores, reports
```
## Step 6: Output
```
## AI Integration: [Feature Name]
Pattern: [Prompt / RAG / Tool Use / Agentic]
Model: [provider/model] | Framework: [framework]
Endpoint: [path or trigger]
### Architecture
Input: [source] → [pre-processing steps]
LLM call: [model] with [system prompt summary]
Output: [schema] → [downstream]
[RAG: chunk=[size], embed=[model], store=[vector db], top-k=[N]]
[Tools: [tool names] → [what each does]]
Fallback: [behavior when LLM unavailable]
### Cost Estimate
Input tokens: ~[N] avg | Output tokens: ~[M] avg
Per call: $[X.XXX]
Monthly at [volume] calls: $[X.XX]
Cheaper option: [model] at $[Y.YY]/mo if quality holds
### Files
[path] — [what it does]
[path] — [what it does]
### Evals
[N] test cases | Target: [metric] | Baseline: [score]
Run: python ai/evals/[feature]/run_evals.py
```
## Delivery
If output exceeds the 40-line CLI budget, invoke `/atlas-report` with the full findings. The HTML report is the output. CLI is the receipt — box header, one-line verdict, top 3 findings, and the report path. Never dump analysis to CLI.
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.