---
name: ai-llm-patterns-06d57eecf3d3
description: "AI/LLM integration patterns: Anthropic SDK streaming with TypeScript, RAG architecture (chunking, embedding, vector search with pgvector), tool use / function calling, model selection guide (Haiku 4.5 vs Sonnet 5 vs Opus 4.8), prompt caching, structured output with Zod, token cost management. Use when building AI features, RAG pipelines, AI agents."
allowed-tools: Read, Grep, Glob
---

# AI/LLM Integration Patterns

## When to Use This Skill
- Building AI features with Claude / Anthropic SDK
- Implementing RAG (Retrieval-Augmented Generation)
- Using tool use / function calling patterns
- Choosing the right Claude model for the task
- Managing token costs and prompt caching

## Core Principles

1. **Model selection matters for cost** — Haiku is 10× cheaper than Sonnet; Sonnet is 5× cheaper than Opus; use the smallest model that can do the task
2. **Streaming for user experience** — start showing text immediately; never make users wait for full response
3. **Tool use for deterministic operations** — LLM decides what to do; your code does it safely; never trust LLM output directly for DB writes
4. **Prompt caching for repeated context** — system prompts, documents, RAG context: cache if >1024 tokens
5. **RAG chunk size matters** — too small (50 tokens) = no context; too large (2000 tokens) = irrelevant context dilutes relevance

## References available
- `references/prompt-engineering.md` — streaming with SSE, model selection guide (Haiku/Sonnet/Opus), prompt caching, structured output with Zod
- `references/rag-architecture.md` — chunking strategy, embedding with text-embedding-3-small, pgvector cosine search, retrieval pipeline
- `references/llm-ops.md` — tool use / agent loop pattern, cost tracking, token budgeting, multi-model routing, error handling


---
Source attribution: rnavarych
Original project: https://github.com/rnavarych/alpha-engineer/blob/c5b74102c7fd584af3d344ba7c331a7bbec3c729/plugins/billy-milligan/skills/shared/ai-llm-patterns/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2024-2026 Raman Navarych

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: rnavarych
Original project: https://github.com/rnavarych/alpha-engineer/blob/c5b74102c7fd584af3d344ba7c331a7bbec3c729/plugins/billy-milligan/skills/shared/ai-llm-patterns/SKILL.md
Attribution basis: Source repository record

Fields of work: Data & Analytics, Development & Engineering
Roles: Backend Developer, Data Scientist, ML / AI Engineer
Specialties: API, Backend
Tools: Anthropic Sdk
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 502c89c7f7b386485d15af4fc323092f85cd66f0657c42c4b2fbe9f1036bf5ba
