@jhm1909/ag-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agent/ARCHITECTURE.md +189 -0
- package/.agent/known-registries.json +181 -0
- package/.agent/mcp_config.json +19 -0
- package/.agent/rules/clean-code.md +107 -0
- package/.agent/rules/documents.md +177 -0
- package/.agent/rules/git-workflow.md +68 -0
- package/.agent/rules/nano-banana.md +46 -0
- package/.agent/rules/research.md +35 -0
- package/.agent/rules/skill-loading.md +100 -0
- package/.agent/rules/skill-suggestion.md +47 -0
- package/.agent/rules/testing.md +52 -0
- package/.agent/rules/workflow-advisor.md +108 -0
- package/.agent/rules/workflow-skill-convention.md +127 -0
- package/.agent/skills/ai-engineer/SKILL.md +824 -0
- package/.agent/skills/ai-engineer/references/agentic-patterns.md +329 -0
- package/.agent/skills/ai-engineer/references/evaluation.md +493 -0
- package/.agent/skills/ai-engineer/references/llm.md +490 -0
- package/.agent/skills/ai-engineer/references/rag-advanced.md +444 -0
- package/.agent/skills/ai-engineer/references/serving-optimization.md +531 -0
- package/.agent/skills/ai-engineer/vector-db/README.md +137 -0
- package/.agent/skills/app-builder/SKILL.md +75 -0
- package/.agent/skills/app-builder/agent-coordination.md +71 -0
- package/.agent/skills/app-builder/feature-building.md +53 -0
- package/.agent/skills/app-builder/project-detection.md +34 -0
- package/.agent/skills/app-builder/scaffolding.md +118 -0
- package/.agent/skills/app-builder/tech-stack.md +41 -0
- package/.agent/skills/app-builder/templates/SKILL.md +39 -0
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
- package/.agent/skills/backend-developer/SKILL.md +763 -0
- package/.agent/skills/backend-developer/references/general-patterns.md +65 -0
- package/.agent/skills/backend-developer/references/go-echo.md +68 -0
- package/.agent/skills/backend-developer/references/go-gin.md +76 -0
- package/.agent/skills/backend-developer/references/java-springboot.md +83 -0
- package/.agent/skills/backend-developer/references/node-express.md +64 -0
- package/.agent/skills/backend-developer/references/node-nestjs.md +69 -0
- package/.agent/skills/backend-developer/references/python-django.md +67 -0
- package/.agent/skills/backend-developer/references/python-fastapi.md +80 -0
- package/.agent/skills/blockchain-engineer/SKILL.md +975 -0
- package/.agent/skills/blockchain-engineer/references/deployment.md +28 -0
- package/.agent/skills/blockchain-engineer/references/evm.md +14 -0
- package/.agent/skills/blockchain-engineer/references/mechanisms.md +32 -0
- package/.agent/skills/blockchain-engineer/references/solidity.md +32 -0
- package/.agent/skills/business-analysis/SKILL.md +85 -0
- package/.agent/skills/business-analysis/references/best-practices/diagrams.md +141 -0
- package/.agent/skills/business-analysis/references/domains/ai-agent.md +94 -0
- package/.agent/skills/business-analysis/references/domains/blockchain-dapp.md +86 -0
- package/.agent/skills/business-analysis/references/domains/ecommerce.md +77 -0
- package/.agent/skills/business-analysis/references/domains/education.md +42 -0
- package/.agent/skills/business-analysis/references/domains/fintech.md +44 -0
- package/.agent/skills/business-analysis/references/domains/fnb.md +82 -0
- package/.agent/skills/business-analysis/references/domains/healthtech.md +44 -0
- package/.agent/skills/business-analysis/references/domains/internal-tools.md +38 -0
- package/.agent/skills/business-analysis/references/domains/marketplace.md +52 -0
- package/.agent/skills/business-analysis/references/domains/saas.md +36 -0
- package/.agent/skills/business-analysis/references/workflows/collaboration.md +41 -0
- package/.agent/skills/business-analysis/scripts/verify_mermaid.py +86 -0
- package/.agent/skills/business-analysis/templates/brd.md +46 -0
- package/.agent/skills/business-analysis/templates/change-request.md +41 -0
- package/.agent/skills/business-analysis/templates/prd-functional.md +38 -0
- package/.agent/skills/business-analysis/templates/use-case.md +40 -0
- package/.agent/skills/business-analysis/templates/user-story-detailed.md +36 -0
- package/.agent/skills/code-review/SKILL.md +113 -0
- package/.agent/skills/code-review/references/code-review-reception.md +209 -0
- package/.agent/skills/code-review/references/differential_review.md +59 -0
- package/.agent/skills/code-review/references/requesting-code-review.md +105 -0
- package/.agent/skills/code-review/references/spec_compliance.md +43 -0
- package/.agent/skills/code-review/references/verification-before-completion.md +139 -0
- package/.agent/skills/context-engineering/SKILL.md +68 -0
- package/.agent/skills/context-engineering/references/context-compression.md +84 -0
- package/.agent/skills/context-engineering/references/context-degradation.md +93 -0
- package/.agent/skills/context-engineering/references/context-fundamentals.md +75 -0
- package/.agent/skills/context-engineering/references/context-optimization.md +82 -0
- package/.agent/skills/context-engineering/references/evaluation.md +89 -0
- package/.agent/skills/context-engineering/references/memory-systems.md +88 -0
- package/.agent/skills/context-engineering/references/multi-agent-patterns.md +90 -0
- package/.agent/skills/context-engineering/references/project-development.md +97 -0
- package/.agent/skills/context-engineering/references/tool-design.md +86 -0
- package/.agent/skills/debugging/SKILL.md +60 -0
- package/.agent/skills/debugging/references/defense-in-depth.md +130 -0
- package/.agent/skills/debugging/references/root-cause-tracing.md +177 -0
- package/.agent/skills/debugging/references/systematic-debugging.md +295 -0
- package/.agent/skills/debugging/references/verification-before-completion.md +142 -0
- package/.agent/skills/designer/SKILL.md +159 -0
- package/.agent/skills/designer/concepts/apple-glass.md +48 -0
- package/.agent/skills/designer/concepts/aurora-gradients.md +26 -0
- package/.agent/skills/designer/concepts/bento-grids.md +14 -0
- package/.agent/skills/designer/concepts/claymorphism.md +27 -0
- package/.agent/skills/designer/concepts/neo-brutalism.md +32 -0
- package/.agent/skills/designer/data/app-interface.csv +31 -0
- package/.agent/skills/designer/data/charts.csv +26 -0
- package/.agent/skills/designer/data/colors.csv +162 -0
- package/.agent/skills/designer/data/design.csv +1776 -0
- package/.agent/skills/designer/data/icons.csv +106 -0
- package/.agent/skills/designer/data/landing.csv +35 -0
- package/.agent/skills/designer/data/products.csv +162 -0
- package/.agent/skills/designer/data/react-performance.csv +45 -0
- package/.agent/skills/designer/data/styles.csv +85 -0
- package/.agent/skills/designer/data/typography.csv +74 -0
- package/.agent/skills/designer/data/ui-reasoning.csv +162 -0
- package/.agent/skills/designer/data/ux-guidelines.csv +100 -0
- package/.agent/skills/designer/references/accessibility.md +172 -0
- package/.agent/skills/designer/references/branding.md +88 -0
- package/.agent/skills/designer/references/color-theory.md +139 -0
- package/.agent/skills/designer/references/creation.md +118 -0
- package/.agent/skills/designer/references/design-systems.md +219 -0
- package/.agent/skills/designer/references/frontend_design_aesthetics.md +57 -0
- package/.agent/skills/designer/references/layout.md +200 -0
- package/.agent/skills/designer/references/motion.md +92 -0
- package/.agent/skills/designer/references/review.md +100 -0
- package/.agent/skills/designer/references/trends.md +209 -0
- package/.agent/skills/designer/references/typography.md +190 -0
- package/.agent/skills/designer/scripts/remove_background.py +135 -0
- package/.agent/skills/designer/scripts/ui-search/__pycache__/core.cpython-314.pyc +0 -0
- package/.agent/skills/designer/scripts/ui-search/__pycache__/design_system.cpython-314.pyc +0 -0
- package/.agent/skills/designer/scripts/ui-search/core.py +217 -0
- package/.agent/skills/designer/scripts/ui-search/design_system.py +1067 -0
- package/.agent/skills/designer/scripts/ui-search/search.py +114 -0
- package/.agent/skills/designer/templates/design-motion-spec.md +30 -0
- package/.agent/skills/devops-engineer/SKILL.md +90 -0
- package/.agent/skills/devops-engineer/docker-compose/README.md +47 -0
- package/.agent/skills/devops-engineer/references/ci-cd-pipelines.md +76 -0
- package/.agent/skills/devops-engineer/references/cloud-providers.md +57 -0
- package/.agent/skills/devops-engineer/references/codebase-normalization.md +104 -0
- package/.agent/skills/devops-engineer/references/container-orchestration.md +69 -0
- package/.agent/skills/devops-engineer/references/iac-tools.md +63 -0
- package/.agent/skills/devops-engineer/references/observability-security.md +45 -0
- package/.agent/skills/devops-engineer/references/vercel-supabase.md +17 -0
- package/.agent/skills/devops-engineer/templates/release-notes.md +8 -0
- package/.agent/skills/frontend-developer/SKILL.md +125 -0
- package/.agent/skills/frontend-developer/react-nextjs/README.md +90 -0
- package/.agent/skills/frontend-developer/references/angular.md +52 -0
- package/.agent/skills/frontend-developer/references/composition_patterns.md +60 -0
- package/.agent/skills/frontend-developer/references/core-performance.md +68 -0
- package/.agent/skills/frontend-developer/references/modern-signals.md +43 -0
- package/.agent/skills/frontend-developer/references/react_performance_rules.md +55 -0
- package/.agent/skills/frontend-developer/references/vue-nuxt.md +55 -0
- package/.agent/skills/frontend-developer/scripts/validate_compliance.py +65 -0
- package/.agent/skills/frontend-developer/threejs/README.md +89 -0
- package/.agent/skills/frontend-developer/threejs/animation.md +552 -0
- package/.agent/skills/frontend-developer/threejs/fundamentals.md +488 -0
- package/.agent/skills/frontend-developer/threejs/geometry.md +548 -0
- package/.agent/skills/frontend-developer/threejs/interaction.md +660 -0
- package/.agent/skills/frontend-developer/threejs/lighting.md +481 -0
- package/.agent/skills/frontend-developer/threejs/loaders.md +623 -0
- package/.agent/skills/frontend-developer/threejs/materials.md +520 -0
- package/.agent/skills/frontend-developer/threejs/postprocessing.md +602 -0
- package/.agent/skills/frontend-developer/threejs/router.json +181 -0
- package/.agent/skills/frontend-developer/threejs/shaders.md +642 -0
- package/.agent/skills/frontend-developer/threejs/textures.md +628 -0
- package/.agent/skills/game-development/2d-games/SKILL.md +119 -0
- package/.agent/skills/game-development/3d-games/SKILL.md +135 -0
- package/.agent/skills/game-development/SKILL.md +167 -0
- package/.agent/skills/game-development/game-art/SKILL.md +185 -0
- package/.agent/skills/game-development/game-audio/SKILL.md +190 -0
- package/.agent/skills/game-development/game-design/SKILL.md +129 -0
- package/.agent/skills/game-development/mobile-games/SKILL.md +108 -0
- package/.agent/skills/game-development/multiplayer/SKILL.md +132 -0
- package/.agent/skills/game-development/pc-games/SKILL.md +144 -0
- package/.agent/skills/game-development/vr-ar/SKILL.md +123 -0
- package/.agent/skills/game-development/web-games/SKILL.md +150 -0
- package/.agent/skills/lead-architect/SKILL.md +85 -0
- package/.agent/skills/lead-architect/references/application-architecture.md +70 -0
- package/.agent/skills/lead-architect/references/infrastructure.md +51 -0
- package/.agent/skills/lead-architect/references/process.md +42 -0
- package/.agent/skills/lead-architect/references/system-architecture.md +62 -0
- package/.agent/skills/lead-architect/references/web-fullstack.md +82 -0
- package/.agent/skills/lead-architect/templates/adr.md +62 -0
- package/.agent/skills/lead-architect/templates/rfc.md +46 -0
- package/.agent/skills/lead-architect/templates/sdd.md +62 -0
- package/.agent/skills/lead-architect/templates/technical-spec.md +61 -0
- package/.agent/skills/marketer/SKILL.md +66 -0
- package/.agent/skills/marketer/remotion-best-practices/SKILL.md +58 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/3d.md +86 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/animations.md +29 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/assets/charts-bar-chart.tsx +173 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/assets/text-animations-typewriter.tsx +100 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/assets/text-animations-word-highlight.tsx +108 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/assets.md +78 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/audio.md +172 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/calculate-metadata.md +104 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/can-decode.md +75 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/charts.md +58 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/compositions.md +146 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/display-captions.md +126 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/extract-frames.md +229 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/fonts.md +152 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/get-audio-duration.md +58 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/get-video-dimensions.md +68 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/get-video-duration.md +58 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/gifs.md +138 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/images.md +130 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/import-srt-captions.md +67 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/lottie.md +68 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/measuring-dom-nodes.md +35 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/measuring-text.md +143 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/sequencing.md +106 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/tailwind.md +11 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/text-animations.md +20 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/timing.md +179 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/transcribe-captions.md +19 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/transitions.md +122 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/trimming.md +53 -0
- package/.agent/skills/marketer/remotion-best-practices/rules/videos.md +171 -0
- package/.agent/skills/mcp-builder/SKILL.md +76 -0
- package/.agent/skills/mcp-builder/references/evaluation.md +602 -0
- package/.agent/skills/mcp-builder/references/mcp_best_practices.md +249 -0
- package/.agent/skills/mcp-builder/references/node_mcp_server.md +970 -0
- package/.agent/skills/mcp-builder/references/python_mcp_server.md +719 -0
- package/.agent/skills/mobile-developer/SKILL.md +83 -0
- package/.agent/skills/mobile-developer/api-routes/SKILL.md +389 -0
- package/.agent/skills/mobile-developer/building-ui/SKILL.md +335 -0
- package/.agent/skills/mobile-developer/building-ui/references/animations.md +220 -0
- package/.agent/skills/mobile-developer/building-ui/references/controls.md +270 -0
- package/.agent/skills/mobile-developer/building-ui/references/form-sheet.md +227 -0
- package/.agent/skills/mobile-developer/building-ui/references/gradients.md +106 -0
- package/.agent/skills/mobile-developer/building-ui/references/icons.md +213 -0
- package/.agent/skills/mobile-developer/building-ui/references/media.md +198 -0
- package/.agent/skills/mobile-developer/building-ui/references/route-structure.md +229 -0
- package/.agent/skills/mobile-developer/building-ui/references/search.md +248 -0
- package/.agent/skills/mobile-developer/building-ui/references/storage.md +121 -0
- package/.agent/skills/mobile-developer/building-ui/references/tabs.md +368 -0
- package/.agent/skills/mobile-developer/building-ui/references/visual-effects.md +197 -0
- package/.agent/skills/mobile-developer/building-ui/references/webgpu-three.md +605 -0
- package/.agent/skills/mobile-developer/cicd-workflows/SKILL.md +107 -0
- package/.agent/skills/mobile-developer/cicd-workflows/scripts/fetch.js +109 -0
- package/.agent/skills/mobile-developer/cicd-workflows/scripts/package.json +11 -0
- package/.agent/skills/mobile-developer/cicd-workflows/scripts/validate.js +84 -0
- package/.agent/skills/mobile-developer/data-fetching/SKILL.md +508 -0
- package/.agent/skills/mobile-developer/deployment/SKILL.md +207 -0
- package/.agent/skills/mobile-developer/deployment/references/app-store-metadata.md +479 -0
- package/.agent/skills/mobile-developer/deployment/references/ios-app-store.md +355 -0
- package/.agent/skills/mobile-developer/deployment/references/play-store.md +246 -0
- package/.agent/skills/mobile-developer/deployment/references/testflight.md +58 -0
- package/.agent/skills/mobile-developer/deployment/references/workflows.md +200 -0
- package/.agent/skills/mobile-developer/dev-client/SKILL.md +181 -0
- package/.agent/skills/mobile-developer/tailwind-setup/SKILL.md +501 -0
- package/.agent/skills/mobile-developer/upgrading-expo/SKILL.md +116 -0
- package/.agent/skills/mobile-developer/upgrading-expo/references/new-architecture.md +79 -0
- package/.agent/skills/mobile-developer/upgrading-expo/references/react-19.md +79 -0
- package/.agent/skills/mobile-developer/upgrading-expo/references/react-compiler.md +59 -0
- package/.agent/skills/mobile-developer/use-dom/SKILL.md +434 -0
- package/.agent/skills/modern-python/SKILL.md +122 -0
- package/.agent/skills/project-manager/SKILL.md +110 -0
- package/.agent/skills/project-manager/references/ba-collaboration.md +62 -0
- package/.agent/skills/project-manager/references/discovery_process.md +52 -0
- package/.agent/skills/project-manager/references/jobs_to_be_done.md +51 -0
- package/.agent/skills/project-manager/references/prd_development.md +52 -0
- package/.agent/skills/project-manager/references/rules-guide.md +55 -0
- package/.agent/skills/project-manager/references/skill-creation.md +98 -0
- package/.agent/skills/project-manager/references/strategic-frameworks.md +62 -0
- package/.agent/skills/project-manager/references/task-decomposition.md +194 -0
- package/.agent/skills/project-manager/references/workflows-guide.md +44 -0
- package/.agent/skills/project-manager/router.json +160 -0
- package/.agent/skills/project-manager/scripts/compare_skill.py +177 -0
- package/.agent/skills/project-manager/scripts/encoding_utils.py +36 -0
- package/.agent/skills/project-manager/scripts/init_skill.py +190 -0
- package/.agent/skills/project-manager/scripts/quick_validate.py +123 -0
- package/.agent/skills/project-manager/templates/pm-strategy-one-pager.md +6 -0
- package/.agent/skills/project-manager/templates/prd-strategic.md +38 -0
- package/.agent/skills/project-manager/templates/skill-questionnaire.md +118 -0
- package/.agent/skills/project-manager/templates/user-story-simple.md +14 -0
- package/.agent/skills/prompt-engineer/SKILL.md +319 -0
- package/.agent/skills/prompt-engineer/skill-creator/README.md +47 -0
- package/.agent/skills/qa-tester/SKILL.md +142 -0
- package/.agent/skills/qa-tester/assets/README.md +8 -0
- package/.agent/skills/qa-tester/references/accessibility_testing.md +35 -0
- package/.agent/skills/qa-tester/references/agent_browser.md +38 -0
- package/.agent/skills/qa-tester/references/automation/api_testing.md +23 -0
- package/.agent/skills/qa-tester/references/automation/best_practices.md +14 -0
- package/.agent/skills/qa-tester/references/automation/jest_vitest.md +26 -0
- package/.agent/skills/qa-tester/references/automation/playwright.md +30 -0
- package/.agent/skills/qa-tester/references/e2e_testing.md +46 -0
- package/.agent/skills/qa-tester/references/integration_testing.md +39 -0
- package/.agent/skills/qa-tester/references/performance_testing.md +44 -0
- package/.agent/skills/qa-tester/references/property_based_testing.md +44 -0
- package/.agent/skills/qa-tester/references/security_audit.md +53 -0
- package/.agent/skills/qa-tester/references/security_testing.md +30 -0
- package/.agent/skills/qa-tester/references/sharp_edges.md +49 -0
- package/.agent/skills/qa-tester/references/static_analysis.md +52 -0
- package/.agent/skills/qa-tester/references/supply_chain_audit.md +54 -0
- package/.agent/skills/qa-tester/references/test_case_standards.md +96 -0
- package/.agent/skills/qa-tester/references/test_report_template.md +32 -0
- package/.agent/skills/qa-tester/references/unit_testing.md +50 -0
- package/.agent/skills/qa-tester/references/visual_testing.md +32 -0
- package/.agent/skills/qa-tester/templates/uat-plan.md +34 -0
- package/.agent/skills/research-first/SKILL.md +118 -0
- package/.agent/skills-manifest.json +264 -0
- package/.agent/workflows/absorb.md +176 -0
- package/.agent/workflows/bootstrap.md +91 -0
- package/.agent/workflows/brainstorm.md +168 -0
- package/.agent/workflows/break-tasks.md +77 -0
- package/.agent/workflows/commit.md +349 -0
- package/.agent/workflows/custom-behavior.md +64 -0
- package/.agent/workflows/debug.md +65 -0
- package/.agent/workflows/development.md +49 -0
- package/.agent/workflows/documentation.md +221 -0
- package/.agent/workflows/gen-tests.md +53 -0
- package/.agent/workflows/guide.md +196 -0
- package/.agent/workflows/implement-feature.md +182 -0
- package/.agent/workflows/install-skill.md +193 -0
- package/.agent/workflows/qa.md +54 -0
- package/.agent/workflows/ui-ux-design.md +108 -0
- package/LICENSE +21 -0
- package/README.md +258 -0
- package/cli/index.js +345 -0
- package/cli/migrate-skills.js +113 -0
- package/cli/verify.js +291 -0
- package/package.json +49 -0
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ai-engineer
|
|
3
|
+
description: >
|
|
4
|
+
Production-grade GenAI, Agentic Systems, RAG, and Evaluation pipelines. Use for LLM integration, multi-agent workflows, and rigorous testing.
|
|
5
|
+
license: MIT
|
|
6
|
+
compatibility: Claude Code, Cursor, Gemini CLI, GitHub Copilot
|
|
7
|
+
metadata:
|
|
8
|
+
author: jhm1909
|
|
9
|
+
version: "2.0.0"
|
|
10
|
+
domain: ai
|
|
11
|
+
estimated_tokens: 25000
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# AI Engineer
|
|
15
|
+
|
|
16
|
+
Guidelines for building production-grade AI systems with robustness, scalability, and engineering reliability.
|
|
17
|
+
|
|
18
|
+
## Knowledge Graph
|
|
19
|
+
|
|
20
|
+
- **extends**: [[backend-developer]]
|
|
21
|
+
- **requires**: []
|
|
22
|
+
- **suggests**: [[prompt-engineer]]
|
|
23
|
+
- **conflicts**: []
|
|
24
|
+
- **enhances**: [[frontend-developer]] (AI-powered UIs), [[data-scientist]] (ML pipelines)
|
|
25
|
+
- **moc**: [[ai-development-moc]]
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 1. Architecture Principles
|
|
30
|
+
|
|
31
|
+
### 1.1 The AI System Stack
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
┌─────────────────────────────────────────┐
|
|
35
|
+
│ Application Layer (UI/API/Agents) │
|
|
36
|
+
├─────────────────────────────────────────┤
|
|
37
|
+
│ Orchestration (Workflows, Routing) │
|
|
38
|
+
├─────────────────────────────────────────┤
|
|
39
|
+
│ Model Layer (LLMs, Embeddings, VLMs) │
|
|
40
|
+
├─────────────────────────────────────────┤
|
|
41
|
+
│ Retrieval (Vector DB, Cache, Search) │
|
|
42
|
+
├─────────────────────────────────────────┤
|
|
43
|
+
│ Infrastructure (Observability, Guardrails)
|
|
44
|
+
└─────────────────────────────────────────┘
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 1.2 Design Patterns
|
|
48
|
+
|
|
49
|
+
| Pattern | Use When | Trade-offs |
|
|
50
|
+
|:--------|:---------|:-----------|
|
|
51
|
+
| **Direct LLM Call** | Simple Q&A, low stakes | Fast, cheap, but limited |
|
|
52
|
+
| **RAG** | Knowledge-intensive tasks | Better accuracy, higher latency |
|
|
53
|
+
| **Multi-Agent** | Complex workflows, parallelization | Scalable, harder to debug |
|
|
54
|
+
| **Chain-of-Thought** | Reasoning tasks | Better accuracy, more tokens |
|
|
55
|
+
| **Function Calling** | Tool integration | Structured, deterministic |
|
|
56
|
+
|
|
57
|
+
### 1.3 Request Lifecycle
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
User Request
|
|
61
|
+
↓
|
|
62
|
+
[Input Validation] → Guardrails, PII detection
|
|
63
|
+
↓
|
|
64
|
+
[Intent Routing] → Classify to appropriate handler
|
|
65
|
+
↓
|
|
66
|
+
[Context Assembly] → Retrieve relevant data
|
|
67
|
+
↓
|
|
68
|
+
[Prompt Construction] → Dynamic template rendering
|
|
69
|
+
↓
|
|
70
|
+
[LLM Inference] → With retry, timeout, fallback
|
|
71
|
+
↓
|
|
72
|
+
[Output Validation] → Schema check, safety filter
|
|
73
|
+
↓
|
|
74
|
+
[Response Streaming] → Chunked delivery
|
|
75
|
+
↓
|
|
76
|
+
[Observability] → Log, trace, metrics
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 2. Agentic Systems
|
|
82
|
+
|
|
83
|
+
### 2.1 Agent Architecture
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
interface Agent {
|
|
87
|
+
// Identity
|
|
88
|
+
name: string;
|
|
89
|
+
description: string;
|
|
90
|
+
systemPrompt: string;
|
|
91
|
+
|
|
92
|
+
// Capabilities
|
|
93
|
+
tools: Tool[];
|
|
94
|
+
memory: MemoryStore;
|
|
95
|
+
|
|
96
|
+
// Behavior
|
|
97
|
+
maxIterations: number;
|
|
98
|
+
reflectionEnabled: boolean;
|
|
99
|
+
|
|
100
|
+
// Execution
|
|
101
|
+
execute(input: string): Promise<AgentResult>;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 2.2 ReAct Pattern (Reasoning + Acting)
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
Thought: I need to find the user's order status
|
|
109
|
+
Action: query_database(user_id, "orders")
|
|
110
|
+
Observation: {"order_id": "123", "status": "shipped"}
|
|
111
|
+
Thought: The order is shipped, I should provide tracking
|
|
112
|
+
Action: get_tracking_info("123")
|
|
113
|
+
Observation: {"carrier": "UPS", "tracking": "1Z999AA"}
|
|
114
|
+
Thought: I have all information needed
|
|
115
|
+
Final Answer: Your order #123 has been shipped via UPS (tracking: 1Z999AA)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 2.3 Multi-Agent Patterns
|
|
119
|
+
|
|
120
|
+
**Supervisor Pattern**
|
|
121
|
+
```
|
|
122
|
+
┌─────────────┐
|
|
123
|
+
User Request → │ Supervisor │
|
|
124
|
+
│ Agent │
|
|
125
|
+
└──────┬──────┘
|
|
126
|
+
│
|
|
127
|
+
┌────────────────┼────────────────┐
|
|
128
|
+
↓ ↓ ↓
|
|
129
|
+
┌──────────┐ ┌──────────┐ ┌──────────┐
|
|
130
|
+
│ Research │ │ Code │ │ Review │
|
|
131
|
+
│ Agent │ │ Agent │ │ Agent │
|
|
132
|
+
└────┬─────┘ └────┬─────┘ └────┬─────┘
|
|
133
|
+
│ │ │
|
|
134
|
+
└───────────────┼───────────────┘
|
|
135
|
+
↓
|
|
136
|
+
┌──────────┐
|
|
137
|
+
│ Synthesis│
|
|
138
|
+
└────┬─────┘
|
|
139
|
+
↓
|
|
140
|
+
Final Response
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Pipeline Pattern**
|
|
144
|
+
```
|
|
145
|
+
Raw Input → Extractor → Validator → Processor → Formatter → Output
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 2.4 Tool Design
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// Good tool: specific, validated, documented
|
|
152
|
+
const searchOrders = {
|
|
153
|
+
name: "search_orders",
|
|
154
|
+
description: "Search customer orders by email or order ID. Returns max 10 results.",
|
|
155
|
+
parameters: z.object({
|
|
156
|
+
query: z.string().describe("Email or order ID to search"),
|
|
157
|
+
status: z.enum(["pending", "shipped", "delivered"]).optional()
|
|
158
|
+
}),
|
|
159
|
+
handler: async ({ query, status }) => {
|
|
160
|
+
// Implementation with error handling
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// Bad tool: vague, unvalidated
|
|
165
|
+
const doStuff = {
|
|
166
|
+
name: "do_stuff",
|
|
167
|
+
description: "Does something",
|
|
168
|
+
parameters: z.any(),
|
|
169
|
+
handler: async (input) => { /* ... */ }
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 3. Advanced RAG
|
|
176
|
+
|
|
177
|
+
### 3.1 Retrieval Pipeline
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
Query → Query Understanding → Retrieval → Reranking → Context Assembly
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 3.2 Query Transformation
|
|
184
|
+
|
|
185
|
+
| Technique | Purpose | Example |
|
|
186
|
+
|:----------|:--------|:--------|
|
|
187
|
+
| **HyDE** | Improve semantic match | Generate hypothetical answer, then retrieve |
|
|
188
|
+
| **Query Expansion** | Increase recall | Add synonyms, related terms |
|
|
189
|
+
| **Step-back** | Broaden context | Abstract specific query to general concept |
|
|
190
|
+
| **Sub-queries** | Complex questions | Break into atomic retrieval tasks |
|
|
191
|
+
|
|
192
|
+
### 3.3 Chunking Strategies
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
# Fixed-size with overlap
|
|
196
|
+
chunks = []
|
|
197
|
+
window = 1000
|
|
198
|
+
overlap = 200
|
|
199
|
+
for i in range(0, len(text), window - overlap):
|
|
200
|
+
chunks.append(text[i:i + window])
|
|
201
|
+
|
|
202
|
+
# Semantic chunking (by meaning)
|
|
203
|
+
from semantic_chunker import SemanticChunker
|
|
204
|
+
chunker = SemanticChunker(
|
|
205
|
+
embedding_model="text-embedding-3-small",
|
|
206
|
+
max_chunk_size=512,
|
|
207
|
+
similarity_threshold=0.85
|
|
208
|
+
)
|
|
209
|
+
chunks = chunker.split(text)
|
|
210
|
+
|
|
211
|
+
# Agentic chunking
|
|
212
|
+
# Use LLM to identify natural boundaries
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 3.4 Retrieval Methods
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
# Dense retrieval (embeddings)
|
|
219
|
+
results = vector_db.search(
|
|
220
|
+
query_embedding=embed(query),
|
|
221
|
+
top_k=10,
|
|
222
|
+
filter={"status": "published"}
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
# Sparse retrieval (BM25)
|
|
226
|
+
from rank_bm25 import BM25Okapi
|
|
227
|
+
tokenized_corpus = [doc.split() for doc in corpus]
|
|
228
|
+
bm25 = BM25Okapi(tokenized_corpus)
|
|
229
|
+
doc_scores = bm25.get_scores(query.split())
|
|
230
|
+
|
|
231
|
+
# Hybrid (best of both)
|
|
232
|
+
dense_results = vector_db.search(query_embedding, top_k=20)
|
|
233
|
+
sparse_results = bm25.search(query, top_k=20)
|
|
234
|
+
results = reciprocal_rank_fusion(dense_results, sparse_results, k=60)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### 3.5 Reranking
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
# Cross-encoder reranking
|
|
241
|
+
from sentence_transformers import CrossEncoder
|
|
242
|
+
reranker = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
|
|
243
|
+
|
|
244
|
+
pairs = [[query, doc.text] for doc in initial_results]
|
|
245
|
+
scores = reranker.predict(pairs)
|
|
246
|
+
reranked = sorted(zip(initial_results, scores), key=lambda x: x[1], reverse=True)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## 4. Prompt Engineering at Scale
|
|
252
|
+
|
|
253
|
+
### 4.1 Prompt Templates
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
from jinja2 import Template
|
|
257
|
+
|
|
258
|
+
SYSTEM_PROMPT = Template("""
|
|
259
|
+
You are {{ role }}. Your task is to {{ task }}.
|
|
260
|
+
|
|
261
|
+
{% if constraints %}
|
|
262
|
+
Constraints:
|
|
263
|
+
{% for c in constraints %}
|
|
264
|
+
- {{ c }}
|
|
265
|
+
{% endfor %}
|
|
266
|
+
{% endif %}
|
|
267
|
+
|
|
268
|
+
{% if examples %}
|
|
269
|
+
Examples:
|
|
270
|
+
{% for ex in examples %}
|
|
271
|
+
Input: {{ ex.input }}
|
|
272
|
+
Output: {{ ex.output }}
|
|
273
|
+
{% endfor %}
|
|
274
|
+
{% endif %}
|
|
275
|
+
|
|
276
|
+
Respond in JSON format matching this schema: {{ output_schema }}
|
|
277
|
+
""")
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### 4.2 Few-shot Prompting
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
def build_few_shot_prompt(query: str, examples: list, k: int = 3) -> str:
|
|
284
|
+
"""Dynamically select relevant examples"""
|
|
285
|
+
|
|
286
|
+
# Retrieve similar examples
|
|
287
|
+
query_embedding = embed(query)
|
|
288
|
+
similarities = [
|
|
289
|
+
cosine_similarity(query_embedding, ex.embedding)
|
|
290
|
+
for ex in examples
|
|
291
|
+
]
|
|
292
|
+
|
|
293
|
+
top_examples = sorted(
|
|
294
|
+
zip(examples, similarities),
|
|
295
|
+
key=lambda x: x[1],
|
|
296
|
+
reverse=True
|
|
297
|
+
)[:k]
|
|
298
|
+
|
|
299
|
+
prompt_parts = ["Here are some examples:\n"]
|
|
300
|
+
for ex, _ in top_examples:
|
|
301
|
+
prompt_parts.append(f"Q: {ex.question}\nA: {ex.answer}\n")
|
|
302
|
+
|
|
303
|
+
prompt_parts.append(f"Q: {query}\nA:")
|
|
304
|
+
return "\n".join(prompt_parts)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### 4.3 Chain-of-Thought
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
COT_PROMPT = """
|
|
311
|
+
Solve this step by step:
|
|
312
|
+
|
|
313
|
+
1. First, identify what information is given
|
|
314
|
+
2. Then, determine what needs to be calculated
|
|
315
|
+
3. Show your work at each step
|
|
316
|
+
4. Finally, provide the answer
|
|
317
|
+
|
|
318
|
+
Question: {question}
|
|
319
|
+
|
|
320
|
+
Let's work through this:
|
|
321
|
+
"""
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 4.4 Structured Output
|
|
325
|
+
|
|
326
|
+
```python
|
|
327
|
+
# Pydantic for structured generation
|
|
328
|
+
from pydantic import BaseModel, Field
|
|
329
|
+
from typing import Literal
|
|
330
|
+
|
|
331
|
+
class AnalysisResult(BaseModel):
|
|
332
|
+
sentiment: Literal["positive", "negative", "neutral"]
|
|
333
|
+
confidence: float = Field(ge=0, le=1)
|
|
334
|
+
key_points: list[str] = Field(max_length=5)
|
|
335
|
+
action_items: list[str] = Field(default_factory=list)
|
|
336
|
+
|
|
337
|
+
# Usage with OpenAI
|
|
338
|
+
response = client.chat.completions.create(
|
|
339
|
+
model="gpt-4",
|
|
340
|
+
messages=[{"role": "user", "content": text}],
|
|
341
|
+
response_format={"type": "json_object"},
|
|
342
|
+
functions=[{
|
|
343
|
+
"name": "analyze",
|
|
344
|
+
"parameters": AnalysisResult.schema()
|
|
345
|
+
}],
|
|
346
|
+
function_call={"name": "analyze"}
|
|
347
|
+
)
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 5. Evaluation Framework
|
|
353
|
+
|
|
354
|
+
### 5.1 LLM-as-Judge
|
|
355
|
+
|
|
356
|
+
```python
|
|
357
|
+
JUDGE_PROMPT = """
|
|
358
|
+
Evaluate the following AI response on these criteria:
|
|
359
|
+
|
|
360
|
+
1. Accuracy (1-5): Is the information correct?
|
|
361
|
+
2. Helpfulness (1-5): Does it solve the user's problem?
|
|
362
|
+
3. Safety (1-5): Is it safe and appropriate?
|
|
363
|
+
4. Conciseness (1-5): Is it appropriately brief?
|
|
364
|
+
|
|
365
|
+
Context: {context}
|
|
366
|
+
User Query: {query}
|
|
367
|
+
AI Response: {response}
|
|
368
|
+
|
|
369
|
+
Provide scores and brief justification for each.
|
|
370
|
+
"""
|
|
371
|
+
|
|
372
|
+
def llm_judge(query: str, response: str, context: str) -> dict:
|
|
373
|
+
evaluation = client.chat.completions.create(
|
|
374
|
+
model="gpt-4",
|
|
375
|
+
messages=[{
|
|
376
|
+
"role": "user",
|
|
377
|
+
"content": JUDGE_PROMPT.format(
|
|
378
|
+
query=query,
|
|
379
|
+
response=response,
|
|
380
|
+
context=context
|
|
381
|
+
)
|
|
382
|
+
}]
|
|
383
|
+
)
|
|
384
|
+
return parse_evaluation(evaluation.choices[0].message.content)
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### 5.2 Automated Testing
|
|
388
|
+
|
|
389
|
+
```python
|
|
390
|
+
# Test dataset
|
|
391
|
+
TEST_CASES = [
|
|
392
|
+
{
|
|
393
|
+
"name": "greeting",
|
|
394
|
+
"input": "Hello!",
|
|
395
|
+
"expected_contains": ["hello", "hi"],
|
|
396
|
+
"expected_not_contains": ["error", "sorry"],
|
|
397
|
+
"max_latency_ms": 1000
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"name": "complex_query",
|
|
401
|
+
"input": "What's the weather in Tokyo and should I bring an umbrella?",
|
|
402
|
+
"expected_tool_calls": ["get_weather"],
|
|
403
|
+
"max_tokens": 200
|
|
404
|
+
}
|
|
405
|
+
]
|
|
406
|
+
|
|
407
|
+
def run_eval(test_cases: list, agent: Agent) -> dict:
|
|
408
|
+
results = []
|
|
409
|
+
for case in test_cases:
|
|
410
|
+
start = time.time()
|
|
411
|
+
response = agent.run(case["input"])
|
|
412
|
+
latency = (time.time() - start) * 1000
|
|
413
|
+
|
|
414
|
+
# Check assertions
|
|
415
|
+
passed = all([
|
|
416
|
+
all(s in response.lower() for s in case.get("expected_contains", [])),
|
|
417
|
+
all(s not in response.lower() for s in case.get("expected_not_contains", [])),
|
|
418
|
+
latency < case.get("max_latency_ms", 5000)
|
|
419
|
+
])
|
|
420
|
+
|
|
421
|
+
results.append({
|
|
422
|
+
"name": case["name"],
|
|
423
|
+
"passed": passed,
|
|
424
|
+
"latency_ms": latency
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
"total": len(results),
|
|
429
|
+
"passed": sum(r["passed"] for r in results),
|
|
430
|
+
"failed": sum(not r["passed"] for r in results),
|
|
431
|
+
"avg_latency_ms": sum(r["latency_ms"] for r in results) / len(results)
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### 5.3 A/B Testing
|
|
436
|
+
|
|
437
|
+
```python
|
|
438
|
+
def ab_test(control_agent, treatment_agent, test_cases, split=0.5):
|
|
439
|
+
"""Compare two agent versions"""
|
|
440
|
+
|
|
441
|
+
results = []
|
|
442
|
+
for case in test_cases:
|
|
443
|
+
# Random assignment
|
|
444
|
+
if random.random() < split:
|
|
445
|
+
agent = treatment_agent
|
|
446
|
+
variant = "treatment"
|
|
447
|
+
else:
|
|
448
|
+
agent = control_agent
|
|
449
|
+
variant = "control"
|
|
450
|
+
|
|
451
|
+
response = agent.run(case["input"])
|
|
452
|
+
score = llm_judge(case["input"], response, case.get("context", ""))
|
|
453
|
+
|
|
454
|
+
results.append({
|
|
455
|
+
"variant": variant,
|
|
456
|
+
"score": score,
|
|
457
|
+
"test_case": case["name"]
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
# Statistical analysis
|
|
461
|
+
control_scores = [r["score"] for r in results if r["variant"] == "control"]
|
|
462
|
+
treatment_scores = [r["score"] for r in results if r["variant"] == "treatment"]
|
|
463
|
+
|
|
464
|
+
return {
|
|
465
|
+
"control_mean": np.mean(control_scores),
|
|
466
|
+
"treatment_mean": np.mean(treatment_scores),
|
|
467
|
+
"p_value": ttest_ind(control_scores, treatment_scores).pvalue
|
|
468
|
+
}
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
## 6. Production Deployment
|
|
474
|
+
|
|
475
|
+
### 6.1 Deployment Patterns
|
|
476
|
+
|
|
477
|
+
| Pattern | Latency | Cost | Best For |
|
|
478
|
+
|:--------|:--------|:-----|:---------|
|
|
479
|
+
| Synchronous | High | Per-request | Low-volume, critical |
|
|
480
|
+
| Asynchronous (Queue) | Medium | Batched | High-volume, non-critical |
|
|
481
|
+
| Streaming | Progressive | Same | Real-time UX |
|
|
482
|
+
| Edge Caching | Low | Lower | Repeatable queries |
|
|
483
|
+
|
|
484
|
+
### 6.2 Load Balancing & Fallbacks
|
|
485
|
+
|
|
486
|
+
```python
|
|
487
|
+
class LLMRouter:
|
|
488
|
+
def __init__(self):
|
|
489
|
+
self.providers = {
|
|
490
|
+
"gpt-4": OpenAIProvider(),
|
|
491
|
+
"claude-3": AnthropicProvider(),
|
|
492
|
+
"llama": TogetherProvider() # Fallback
|
|
493
|
+
}
|
|
494
|
+
self.health = {k: True for k in self.providers}
|
|
495
|
+
|
|
496
|
+
async def complete(self, prompt: str, priority: str = "quality") -> str:
|
|
497
|
+
# Route by priority
|
|
498
|
+
if priority == "quality":
|
|
499
|
+
order = ["gpt-4", "claude-3", "llama"]
|
|
500
|
+
elif priority == "speed":
|
|
501
|
+
order = ["claude-3", "gpt-4", "llama"]
|
|
502
|
+
else: # cost
|
|
503
|
+
order = ["llama", "claude-3", "gpt-4"]
|
|
504
|
+
|
|
505
|
+
for provider_name in order:
|
|
506
|
+
if not self.health[provider_name]:
|
|
507
|
+
continue
|
|
508
|
+
|
|
509
|
+
try:
|
|
510
|
+
provider = self.providers[provider_name]
|
|
511
|
+
return await provider.complete(prompt, timeout=30)
|
|
512
|
+
except Exception as e:
|
|
513
|
+
logger.warning(f"{provider_name} failed: {e}")
|
|
514
|
+
self.health[provider_name] = False
|
|
515
|
+
continue
|
|
516
|
+
|
|
517
|
+
raise AllProvidersFailed()
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### 6.3 Circuit Breaker
|
|
521
|
+
|
|
522
|
+
```python
|
|
523
|
+
from circuitbreaker import circuit
|
|
524
|
+
|
|
525
|
+
@circuit(failure_threshold=5, recovery_timeout=60)
|
|
526
|
+
async def call_llm(prompt: str):
|
|
527
|
+
"""Automatically stop calling if failing too much"""
|
|
528
|
+
return await llm_client.complete(prompt)
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
## 7. Observability
|
|
534
|
+
|
|
535
|
+
### 7.1 Structured Logging
|
|
536
|
+
|
|
537
|
+
```python
|
|
538
|
+
import structlog
|
|
539
|
+
|
|
540
|
+
logger = structlog.get_logger()
|
|
541
|
+
|
|
542
|
+
def log_llm_call(prompt: str, response: str, metadata: dict):
|
|
543
|
+
logger.info(
|
|
544
|
+
"llm_completion",
|
|
545
|
+
prompt_tokens=len(prompt) // 4, # Approximate
|
|
546
|
+
completion_tokens=len(response) // 4,
|
|
547
|
+
model=metadata["model"],
|
|
548
|
+
latency_ms=metadata["latency"],
|
|
549
|
+
cache_hit=metadata.get("cache_hit", False),
|
|
550
|
+
user_id=metadata.get("user_id"),
|
|
551
|
+
session_id=metadata.get("session_id")
|
|
552
|
+
)
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
### 7.2 Tracing
|
|
556
|
+
|
|
557
|
+
```python
|
|
558
|
+
from opentelemetry import trace
|
|
559
|
+
|
|
560
|
+
tracer = trace.get_tracer("ai-agent")
|
|
561
|
+
|
|
562
|
+
@tracer.start_as_current_span("agent_execution")
|
|
563
|
+
def run_agent(query: str):
|
|
564
|
+
with tracer.start_as_current_span("retrieval") as span:
|
|
565
|
+
context = retrieve(query)
|
|
566
|
+
span.set_attribute("retrieval.count", len(context))
|
|
567
|
+
|
|
568
|
+
with tracer.start_as_current_span("llm_call") as span:
|
|
569
|
+
response = llm.complete(query, context=context)
|
|
570
|
+
span.set_attribute("tokens.used", response.usage.total_tokens)
|
|
571
|
+
|
|
572
|
+
return response
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
### 7.3 Metrics
|
|
576
|
+
|
|
577
|
+
```python
|
|
578
|
+
from prometheus_client import Counter, Histogram, Gauge
|
|
579
|
+
|
|
580
|
+
# Counters
|
|
581
|
+
llm_requests_total = Counter('llm_requests_total', 'Total LLM requests', ['model', 'status'])
|
|
582
|
+
cache_hits_total = Counter('cache_hits_total', 'Cache hit count')
|
|
583
|
+
|
|
584
|
+
# Histograms
|
|
585
|
+
llm_latency_seconds = Histogram('llm_latency_seconds', 'Request latency', ['model'])
|
|
586
|
+
tokens_per_request = Histogram('tokens_per_request', 'Tokens per request', ['model', 'type'])
|
|
587
|
+
|
|
588
|
+
# Gauges
|
|
589
|
+
active_requests = Gauge('active_requests', 'Currently processing requests')
|
|
590
|
+
available_context_window = Gauge('available_context_window', 'Remaining tokens in context')
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
## 8. Safety & Guardrails
|
|
596
|
+
|
|
597
|
+
### 8.1 Input Validation
|
|
598
|
+
|
|
599
|
+
```python
|
|
600
|
+
from presidio_analyzer import AnalyzerEngine
|
|
601
|
+
from presidio_anonymizer import AnonymizerEngine
|
|
602
|
+
|
|
603
|
+
analyzer = AnalyzerEngine()
|
|
604
|
+
anonymizer = AnonymizerEngine()
|
|
605
|
+
|
|
606
|
+
def sanitize_input(text: str) -> tuple[str, list]:
|
|
607
|
+
"""Detect and optionally remove PII"""
|
|
608
|
+
results = analyzer.analyze(text=text, language='en')
|
|
609
|
+
|
|
610
|
+
detected_entities = [r.entity_type for r in results]
|
|
611
|
+
|
|
612
|
+
if detected_entities:
|
|
613
|
+
anonymized = anonymizer.anonymize(
|
|
614
|
+
text=text,
|
|
615
|
+
analyzer_results=results
|
|
616
|
+
)
|
|
617
|
+
return anonymized.text, detected_entities
|
|
618
|
+
|
|
619
|
+
return text, []
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### 8.2 Output Filtering
|
|
623
|
+
|
|
624
|
+
```python
|
|
625
|
+
# Content moderation
|
|
626
|
+
from openai import OpenAI
|
|
627
|
+
|
|
628
|
+
client = OpenAI()
|
|
629
|
+
|
|
630
|
+
def moderate_content(text: str) -> dict:
|
|
631
|
+
response = client.moderations.create(input=text)
|
|
632
|
+
result = response.results[0]
|
|
633
|
+
|
|
634
|
+
return {
|
|
635
|
+
"flagged": result.flagged,
|
|
636
|
+
"categories": {
|
|
637
|
+
k: v for k, v in result.categories.__dict__.items() if v
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
# Custom guardrails
|
|
642
|
+
FORBIDDEN_PATTERNS = [
|
|
643
|
+
r"\b(password|secret|key)\s*[:=]\s*\S+", # Credentials
|
|
644
|
+
r"\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b", # Credit cards
|
|
645
|
+
]
|
|
646
|
+
|
|
647
|
+
def check_output(text: str) -> tuple[bool, list]:
|
|
648
|
+
violations = []
|
|
649
|
+
for pattern in FORBIDDEN_PATTERNS:
|
|
650
|
+
if re.search(pattern, text, re.IGNORECASE):
|
|
651
|
+
violations.append(f"Matched forbidden pattern: {pattern}")
|
|
652
|
+
|
|
653
|
+
return len(violations) == 0, violations
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
### 8.3 Rate Limiting
|
|
657
|
+
|
|
658
|
+
```python
|
|
659
|
+
from ratelimit import limits, sleep_and_retry
|
|
660
|
+
|
|
661
|
+
# Per-user rate limiting
|
|
662
|
+
USER_LIMITS = {}
|
|
663
|
+
|
|
664
|
+
def check_rate_limit(user_id: str, max_requests: int = 100, window: int = 3600):
|
|
665
|
+
now = time.time()
|
|
666
|
+
key = f"rate_limit:{user_id}"
|
|
667
|
+
|
|
668
|
+
# Get current count from Redis/cache
|
|
669
|
+
current = cache.get(key, default=[])
|
|
670
|
+
|
|
671
|
+
# Remove old entries outside window
|
|
672
|
+
current = [t for t in current if now - t < window]
|
|
673
|
+
|
|
674
|
+
if len(current) >= max_requests:
|
|
675
|
+
raise RateLimitExceeded(f"Limit: {max_requests} per {window}s")
|
|
676
|
+
|
|
677
|
+
current.append(now)
|
|
678
|
+
cache.set(key, current, ex=window)
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
---
|
|
682
|
+
|
|
683
|
+
## 9. Cost Optimization
|
|
684
|
+
|
|
685
|
+
### 9.1 Caching Strategies
|
|
686
|
+
|
|
687
|
+
```python
|
|
688
|
+
import hashlib
|
|
689
|
+
from functools import lru_cache
|
|
690
|
+
|
|
691
|
+
# Semantic caching (similar queries)
|
|
692
|
+
class SemanticCache:
|
|
693
|
+
def __init__(self, threshold: float = 0.95):
|
|
694
|
+
self.store = {} # embedding -> response
|
|
695
|
+
self.threshold = threshold
|
|
696
|
+
|
|
697
|
+
def get(self, query: str) -> str | None:
|
|
698
|
+
query_emb = embed(query)
|
|
699
|
+
|
|
700
|
+
for cached_emb, response in self.store.items():
|
|
701
|
+
similarity = cosine_similarity(query_emb, cached_emb)
|
|
702
|
+
if similarity > self.threshold:
|
|
703
|
+
return response
|
|
704
|
+
|
|
705
|
+
return None
|
|
706
|
+
|
|
707
|
+
def set(self, query: str, response: str):
|
|
708
|
+
self.store[embed(query)] = response
|
|
709
|
+
|
|
710
|
+
# Exact match caching
|
|
711
|
+
@lru_cache(maxsize=1000)
|
|
712
|
+
def cached_llm_call(prompt_hash: str):
|
|
713
|
+
# Implementation
|
|
714
|
+
pass
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
### 9.2 Model Tiering
|
|
718
|
+
|
|
719
|
+
```python
|
|
720
|
+
TIER_STRATEGY = {
|
|
721
|
+
"simple": { # Classification, extraction
|
|
722
|
+
"model": "gpt-3.5-turbo",
|
|
723
|
+
"max_tokens": 150
|
|
724
|
+
},
|
|
725
|
+
"standard": { # General Q&A
|
|
726
|
+
"model": "claude-3-sonnet",
|
|
727
|
+
"max_tokens": 500
|
|
728
|
+
},
|
|
729
|
+
"complex": { # Reasoning, code
|
|
730
|
+
"model": "gpt-4",
|
|
731
|
+
"max_tokens": 2000
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
def route_by_complexity(query: str) -> dict:
|
|
736
|
+
"""Use cheap model to classify complexity"""
|
|
737
|
+
classification = client.classify(
|
|
738
|
+
query,
|
|
739
|
+
classes=["simple", "standard", "complex"]
|
|
740
|
+
)
|
|
741
|
+
return TIER_STRATEGY[classification]
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
### 9.3 Token Optimization
|
|
745
|
+
|
|
746
|
+
```python
|
|
747
|
+
# Prompt compression
|
|
748
|
+
from prompt_compressor import Compressor
|
|
749
|
+
|
|
750
|
+
compressor = Compressor()
|
|
751
|
+
long_context = compressor.compress(
|
|
752
|
+
documents,
|
|
753
|
+
target_ratio=0.5, # Keep 50% of tokens
|
|
754
|
+
method="semantic" # or "extractive"
|
|
755
|
+
)
|
|
756
|
+
|
|
757
|
+
# Selective context inclusion
|
|
758
|
+
def select_relevant_chunks(query: str, chunks: list, max_tokens: int) -> list:
|
|
759
|
+
query_emb = embed(query)
|
|
760
|
+
|
|
761
|
+
# Score by relevance
|
|
762
|
+
scored = [
|
|
763
|
+
(chunk, cosine_similarity(query_emb, chunk.embedding))
|
|
764
|
+
for chunk in chunks
|
|
765
|
+
]
|
|
766
|
+
scored.sort(key=lambda x: x[1], reverse=True)
|
|
767
|
+
|
|
768
|
+
# Take top-k within token budget
|
|
769
|
+
selected = []
|
|
770
|
+
token_count = 0
|
|
771
|
+
for chunk, score in scored:
|
|
772
|
+
if token_count + chunk.token_count > max_tokens:
|
|
773
|
+
break
|
|
774
|
+
selected.append(chunk)
|
|
775
|
+
token_count += chunk.token_count
|
|
776
|
+
|
|
777
|
+
return selected
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
---
|
|
781
|
+
|
|
782
|
+
## 10. Reference Materials
|
|
783
|
+
|
|
784
|
+
### Dynamic Stack Loading
|
|
785
|
+
|
|
786
|
+
Load specialized references based on task requirements:
|
|
787
|
+
|
|
788
|
+
| When User Needs | Load This |
|
|
789
|
+
|:----------------|:----------|
|
|
790
|
+
| Multi-agent workflows | `references/agentic-patterns.md` |
|
|
791
|
+
| RAG implementation | `references/rag-advanced.md` + `vector-db/README.md` |
|
|
792
|
+
| Production deployment | `references/serving-optimization.md` |
|
|
793
|
+
| Testing & evaluation | `references/evaluation.md` |
|
|
794
|
+
| LLM integration basics | `references/llm.md` |
|
|
795
|
+
|
|
796
|
+
### Example Workflows
|
|
797
|
+
|
|
798
|
+
**RAG Pipeline:**
|
|
799
|
+
```
|
|
800
|
+
User: "Build a RAG system for my documents"
|
|
801
|
+
→ Load ai-engineer/vector-db/README.md
|
|
802
|
+
→ Choose provider (Pinecone/Chroma/pgvector)
|
|
803
|
+
→ Set up embeddings and retrieval
|
|
804
|
+
→ Integrate with LLM calls
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
**Multi-Agent System:**
|
|
808
|
+
```
|
|
809
|
+
User: "Create a team of AI agents for research"
|
|
810
|
+
→ Load ai-engineer/references/agentic-patterns.md
|
|
811
|
+
→ Design agent roles and tools
|
|
812
|
+
→ Implement ReAct or supervisor pattern
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
### Related Skills
|
|
816
|
+
|
|
817
|
+
- [[backend-developer]] — API and infrastructure foundation
|
|
818
|
+
- [[frontend-developer]] — AI-powered user interfaces
|
|
819
|
+
- [[prompt-engineer]] — Deep prompt engineering expertise
|
|
820
|
+
- [[data-scientist]] — ML model training and evaluation
|
|
821
|
+
|
|
822
|
+
---
|
|
823
|
+
|
|
824
|
+
*Extends [[backend-developer]] | Part of [[ai-development-moc]]*
|