Best for
- Adding AI-powered features to an existing product (chat, generation, suggestions)
- Building streaming UI for LLM responses in web or mobile applications
- Implementing structured output with schema validation from LLM calls
vasilyu1983/AI-Agents-public/frameworks/shared-skills/skills/software-ai-integration/SKILL.md
Applies production AI integration patterns for chat, structured output, guardrails, provider routing, and AI UX. Use when adding LLM-powered features to an application.
Decision brief
Integrate LLMs and AI capabilities into production applications with clean architecture, cost discipline, and reliable user experience.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Declared | Source record | Install path and trigger |
| Claude Code | Declared | Source record | Install path and trigger |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/vasilyu1983/AI-Agents-public --skill "frameworks/shared-skills/skills/software-ai-integration"Inspect the Agent Skill "software-ai-integration" from https://github.com/vasilyu1983/AI-Agents-public/blob/53f6cb73ea53a2646e3e7d4665062ad66f3683ac/frameworks/shared-skills/skills/software-ai-integration/SKILL.md at commit 53f6cb73ea53a2646e3e7d4665062ad66f3683ac. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
1. Classify the feature shape: chat, generation, extraction, search, or agent-adjacent UX. 2. Confirm the product boundary and route architecture-heavy or retrieval-heavy work to the adjacent skill when needed. 3. Pick the primary pattern from the decision tree, then define the…
Review the “Quick Reference” section in the pinned source before continuing.
Adding AI-powered features to an existing product (chat, generation, suggestions)
LLM lifecycle management (fine-tuning, deployment, monitoring) → ai-llm
Not every "AI feature" request should become one. Apply this filter before the decision tree below:
Permission review
The documentation includes network, browsing, or remote request actions.
Use web search/web fetch to verify current external facts, versions, pricing, deadlines, regulations, or platform behavior before final answers.Evidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 97/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 82 | Source | Repository attention, not individual Skill quality |
| Compatibility | 2 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Integrate LLMs and AI capabilities into production applications with clean architecture, cost discipline, and reliable user experience.
| Concern | Defaults |
|---|---|
| LLM API integration | Anthropic SDK, OpenAI SDK, Vercel AI SDK |
| Streaming responses | SSE / ReadableStream + AI SDK streamText/streamObject |
| Structured output | JSON mode, tool_use/function calling, Zod schemas |
| Chat interface | AI SDK useChat hook, custom streaming UI |
| AI-assisted forms | Inline suggestions, auto-complete, content generation |
| Guardrails | Input/output filtering, content moderation, PII detection |
| Cost management | Token counting, caching (semantic + exact), model routing |
| Multi-provider | AI SDK provider abstraction, Portkey, LiteLLM, or a thin internal router |
| Evaluation | Human feedback, LLM-as-judge, A/B testing AI variants |
| RAG in products | Vector search + context injection (see also ai-rag for deeper patterns) |
Not every "AI feature" request should become one. Apply this filter before the decision tree below:
| Decide | Build | Buy / integrate |
|---|---|---|
| Chat UI, streaming, structured output | Build on Vercel AI SDK or a provider SDK — this is commodity glue code now, not a differentiator | — |
| In-app copilot UI shell | Consider CopilotKit if the UI shell itself is not the differentiator | Build custom only if the copilot surface is the product |
| Prompt injection / content moderation detection | — | Use provider moderation endpoints or a dedicated vendor (e.g. Lakera-class runtime guard) first; building a custom classifier is a multi-quarter investment that duplicates adversarially-trained vendor models |
| Eval/tracing/observability | — | Use an LLM observability vendor (Langfuse-, Humanloop-class) before building an in-house trace store; the differentiator is your eval criteria, not the pipeline plumbing |
| Multi-provider routing/governance | Thin internal router for a single product | Buy a gateway (Portkey-class) once more than one team or product needs shared routing, budgets, or policy |
The recurring judgment call: build the thin layer that encodes your product's specific logic (prompts, schemas, eval criteria, business rules); buy the generic infrastructure (streaming plumbing, moderation classifiers, tracing storage) that every AI product needs and that a vendor has already hardened against edge cases you have not seen yet.
AI feature request
-> Classify: chat, generation, extraction, search, or agent-adjacent UX
-> Route architecture, RAG, or agent-heavy work to companion skills
-> Define typed request and response contract
-> Choose provider, streaming, safety, and cost controls
-> Implement product UX states and observability
-> Verify provider behavior and eval evidence
What kind of AI feature?
├─ Chat / conversational UI
│ ├─ Web app → Vercel AI SDK (useChat + streamText)
│ │ ├─ Conversation history → Store in DB, not just client state
│ │ ├─ Streaming markdown → Progressive render with remark/rehype
│ │ └─ Multi-turn with tools → Tool results in message history
│ └─ Mobile / native → Direct SSE consumption + custom UI
├─ Content generation ("write for me")
│ ├─ Short-form (titles, descriptions) → Single generation + schema
│ └─ Long-form (articles, reports)
│ └─ Draft → Review → Edit → Apply pattern with undo support
├─ Inline suggestions (autocomplete)
│ ├─ Latency-critical → Use fastest model (Haiku-class)
│ ├─ UI pattern → Ghost text, accept with Tab, dismiss with Esc
│ └─ Trigger → Debounce input (300-500ms), cancel in-flight requests
├─ Data extraction / classification
│ ├─ Structured output with Zod schema validation
│ ├─ Batch processing → Queue + worker pattern
│ └─ Confidence scores → Include in schema, filter by threshold
├─ Search / Q&A over content
│ └─ RAG pattern (see ai-rag) + this skill for product integration
└─ Agent features (multi-step autonomous)
└─ ai-agents for architecture, this skill for product UX integration
The repo source list highlighted a practical split that belongs in this skill:
| Need | Default choice | Why |
|---|---|---|
| Ship AI inside an existing app | Vercel AI SDK or direct provider SDK | Best fit for streaming UI, structured output, and product-owned flows |
| Embed a visible in-app copilot | CopilotKit | Useful when the product needs opinionated copilot UI primitives in React |
| Orchestrate long-running agent workflows | LangGraph or CrewAI | Use when the feature is truly workflow/agent shaped, not just one request/response UI |
| Centralize routing, logging, and provider policy | Portkey or a thin internal gateway | Best fit for multi-provider control planes and cross-feature governance |
Rules:
ai-bot-builder. If it is product integration first, stay here.Never buffer a full LLM response and then send it. Always stream to the user.
streamText, streamObject in AI SDK, or native SDK streaming). Pipe the stream directly to the HTTP response as Server-Sent Events or a ReadableStream.When you need the LLM to return data, not prose.
generateObject / streamObject for automatic validation. Zod gives you TypeScript types and runtime validation from one definition.type field tells your code which branch to handle.streamObject delivers partial objects as they generate. Use for progressive UI updates (show fields as they arrive), but validate the complete object before persisting.{ id, conversationId, role, content, toolCalls, toolResults, createdAt }.| Control | Default rule |
|---|---|
| Token estimation | Estimate input tokens before sending; warn or truncate at budget threshold; use tiktoken or provider tokenizer |
| Caching | Exact-match cache for deterministic queries; semantic cache (embeddings) for FAQ-style; set TTLs |
| Model routing | Haiku-class for classification/extraction/autocomplete; Sonnet/Opus-class for complex reasoning/long-form |
| Usage tracking | Track tokens per user, per feature, per model; budget alerts at 70% and 90% of monthly allocation |
| Rate limiting | Apply per user tier at the application layer; return clear error messages with upgrade paths |
| Prompt optimization | Audit system prompts for verbosity; measure quality vs. length trade-offs |
See references/rollout-and-observability.md for cost dashboards, eval loops, and feature-flag rollout patterns.
Exact per-token prices change often — pull current numbers from the provider pricing page before using this in a real budget. The method below is what matters and stays stable: prompt caching only pays for itself once a cached prefix is reused enough times to amortize the cache-write premium.
Providers commonly price cache writes at a premium over a normal input token (e.g., roughly 1.25x for a short-TTL cache, ~2x for a longer-TTL cache) and cache reads at a steep discount off the normal input price (commonly ~0.1x, i.e. a ~90% discount). Given:
P = normal input token pricew = cache-write multiplier (e.g., 1.25)r = cache-read multiplier (e.g., 0.1)N = number of times the cached prefix is reused before it expires or changesBreak-even reuse count N* = (w - r) / (1 - r). With w = 1.25, r = 0.1: N* = 1.15 / 0.9 ≈ 1.28 — so caching a stable system prompt or long tool-definition block pays for itself after roughly the second reuse, not after dozens of reuses as intuition might suggest. This is why caching large, stable prefixes (system prompts, tool schemas, few-shot examples, retrieved document sets reused across a session) is close to a free win in most chat and agent architectures — the failure mode is forgetting to structure prompts so the stable part is a shared, byte-identical prefix, which breaks cache hits.
Apply the same break-even logic before adopting batch-API discounts (commonly ~50% off both directions) versus real-time calls: batch trades latency for cost, so it is only a substitute for interactive features, not a default.
| Pattern | Rule |
|---|---|
| Loading states | Show tokens as they arrive; never buffer; streaming feels faster even at equal total time |
| Regenerate + stop | Always provide both controls — AI equivalents of "refresh" and "cancel" |
| Confidence | Label AI output; use qualifiers for uncertain responses; never present with same certainty as DB reads |
| Feedback | Thumbs up/down minimum; corrections more valuable; route both into eval pipelines |
| Graceful degradation | Core product must work when AI provider is down — cache, fallback, or queue |
| Attribution | Clearly label AI-generated content; Art. 50 EU AI Act requires disclosure for interactive systems |
| Undo / edit | Allow editing before AI output takes effect; require confirmation for destructive actions |
| Layer | Rule |
|---|---|
| Input | Enforce length limits; detect instruction-override patterns; sanitize before prompt injection |
| Output | Scan for PII (names, emails, SSNs); use moderation APIs (Anthropic, OpenAI, or Lakera) |
| High-stakes | Route medical/legal/financial AI output through human review; track review latency |
| Audit logging | Log prompts + responses separately from app logs; mask PII; set retention policy |
| Rate limiting | Rate limit to prevent abuse (injection attempts, data extraction) — beyond cost control |
| Fail closed | When guardrails timeout or fail, block the response and log; never pass unfiltered |
Abstract provider calls behind a single AIProvider interface (AI SDK's provider pattern achieves this). Never swap models for all users at once — use feature flags and circuit breakers.
| Step | Implementation |
|---|---|
| Abstraction | anthropic('<mid-tier-model-id>') swappable for openai('<comparable-tier-model-id>') without changing call sites — resolve the exact current model IDs at each provider's docs at use-time, never hardcode a "best model" from memory |
| Fallback chain | Primary → fallback → degraded mode; circuit breaker after N failures in M seconds |
| Model variants | Maintain per-model prompt variants when quality differs; test before switching traffic |
| A/B rollout | Route % of traffic to new model; gate on user feedback, task completion, error rates |
See references/rollout-and-observability.md for full rollout and eval loop patterns.
| Do | Avoid |
|---|---|
| Stream from first token — never buffer | Hardcoding system prompts as string literals |
| Store conversation history server-side in DB | Sending unbounded user input without token estimation |
| Version system prompts in code, treat as product logic | Treating AI provider uptime as guaranteed |
| Build cost tracking per user and per feature from day one | Logging full prompts/responses without PII and retention policy |
| Provide "regenerate", "stop generating", and "undo" on every AI output | Swapping models for all users at once without A/B gates |
| Clearly label AI-generated content for users and audit trails | Parsing LLM text with regex when tool_use/JSON mode is available |
| Test with mocked LLM responses (unit) and real calls (integration) | Ignoring thumbs-down/correction signals — route them to eval pipelines |
| Implement graceful degradation so core product works when AI is down | Building AI features without per-user rate limiting |
| Use tool_use/function calling for structured output | Buffering a full response before sending to the user |
| Anti-Pattern | Reason |
|---|---|
| Making the model call the core product workflow | Product loses ownership; the model becomes a single point of failure and a hard-to-audit orchestrator. |
| Trust tool outputs as instructions | Tool results are an indirect prompt injection vector. Attacker-controlled data returned by any tool can direct agent actions including destructive write and send operations. Always treat tool output as untrusted data; parse and validate before acting. |
| Hiding weak application contracts behind longer prompts | Prompt length does not fix broken validation, state, or orchestration — it hides it and makes it harder to debug. |
| Treating client-visible streaming as sufficient observability | No durable record of prompts, tool calls, or failures means incidents cannot be investigated or attributed. |
| Letting the AI path directly mutate durable product state | Without confirmation, undo, or compensating logic, a bad model output or injected instruction causes irreversible harm. |
| Expanding one AI service into a catch-all abstraction | Mixing routing, prompt logic, persistence, moderation, and analytics in one service eliminates clear ownership and makes the injection attack surface unbounded. |
Recipes keyed to symptoms or integration moments. Each lists the shortest path to a working, production-safe implementation.
streamText (AI SDK) with the chosen provider.citations tool or instruct the model to embed [source:N] markers in prose.ReadableStream to the HTTP response as SSE; never buffer the full response.useChat to render tokens progressively; parse [source:N] markers into inline links.{ conversationId, model, inputTokens, outputTokens, latencyMs } for cost tracking.generateObject (AI SDK) to bind schema to the model call.ZodError, log the raw response and retry once with a more explicit prompt that names the failing field.{ type: "success" | "parse_error" | "refused" }) to handle all branches.\nAssistant:, \nHuman:, and instruction-override patterns before injecting user input into prompts.{ tool, args, result, conversationId } for post-incident tracing.AIProvider interface; swap implementations without changing call sites.429 responses in M seconds, route to the fallback provider.--dry-run mode in staging that exercises the fallback path without real traffic.content_hash and retrieved_at timestamp in the cache key.updated_at against cached retrieved_at; evict on mismatch.{ answer, sources[{ id, title, url, retrieved_at }] } to the UI for attribution.AI integration tooling changes rapidly. Freshness-check before answering questions about SDKs, model capabilities, or provider-specific patterns.
Triggers: SDK version questions, "is X still recommended?", streaming API changes, provider capability changes, new model releases.
Process: start from data/sources.json, run a targeted web search, check SDK changelogs (Vercel AI SDK, Anthropic SDK, and OpenAI SDK all release frequently with breaking changes).
Verify current obligation timelines at official EU AI Act sources at use-time — the Digital Omnibus on AI (political agreement reached 7 May 2026, EU Parliament endorsed 16 June 2026, Council final sign-off 29 June 2026) pushed the Annex III high-risk deadline from 2 August 2026 to 2 December 2027; confirm formal Official Journal publication and effective date at eur-lex.europa.eu before relying on either date as of 2026-07-11.
| Obligation | When it applies | Action |
|---|---|---|
| Prohibited practices (Ch. II) | Any LLM feature using subliminal manipulation, social scoring, or real-time biometric ID in public | Remove before EU deployment (in force since 2 Feb 2025, unaffected by the Omnibus delay) |
| Transparency labelling (Art. 50) | Any system interacting with natural persons | Disclose AI nature; watermark generated images/audio/video — not delayed by the Omnibus, still targeted for 2 August 2026 (existing systems get a watermarking grace period to ~Dec 2026 per the agreed text; verify final text) |
| High-risk classification (Annex III) | Employment screening, credit scoring, biometric ID, education gating, essential-services access | Conformity assessment + human oversight — deadline deferred to 2 December 2027 under the Digital Omnibus (was 2 August 2026); do not assume the old date without checking final publication |
| Operator obligations | Deploying a third-party GPAI model for a specific purpose | Document purpose, implement usage policies, retain logs |
| GPAI systemic risk (Arts. 51–56) | Building on any GPAI model whose provider discloses ≥10^25 training FLOPs (rebuttable presumption, not automatic) | Technical documentation, copyright compliance, training data summaries; do not assume any single named model is or isn't in scope — check the provider's published systemic-risk designation |
| Enforcement | Prohibited-practice violations | Fines up to €35M or 7% of global turnover |
Indirect prompt injection is the primary exploit path: attacker-controlled data in retrieved documents, tool outputs, or web results overrides system instructions. Mitigations: isolate retrieved content with structural tags, enforce least-privilege tool scopes, validate model output before write/send operations, and test with adversarial documents in CI. Defense must be architectural — model-side mitigations reduce but do not eliminate risk.
See references/prompt-injection-and-ai-act.md for full obligation timelines and injection defence patterns.
Before applying this skill on a non-trivial task, read learnings.consolidated.md in this directory (and learnings.md if present).
After applying it, if you encountered a pattern worth remembering, a mistake worth preventing, or a domain fact that surprised you, append one dated bullet to learnings.md via agents-skills-feedback-loop/scripts/append_learning.py. Do not modify SKILL.md itself.
Frequently asked questions
Integrate LLMs and AI capabilities into production applications with clean architecture, cost discipline, and reliable user experience.
The source record exposes this install command: npx skills add https://github.com/vasilyu1983/AI-Agents-public --skill "frameworks/shared-skills/skills/software-ai-integration". Inspect the command and pinned source before running it.
The pinned source record declares support for: codex, claude code.
Static rules flagged network in the source; the page lists the matching lines and excerpts.
Alternatives
vasilyu1983/AI-Agents-public
Guides iOS testing with XCTest, XCUITest, Swift Testing, simctl, and xcresult. Use when choosing destinations, controlling flakes, or parsing test artifacts for native apps.
samber/cc-skills-golang
Monadic types for Golang using samber/mo — Option, Result, Either, Future, IO, Task, and State types for type-safe nullable values, error handling, and functional composition with pipeline sub-packages. Apply when using or adopting samber/mo, when the codebase imports `github.com/samber/mo`, or when considering functional programming patterns as a safety design for Golang.
vasilyu1983/AI-Agents-public
Designs and audits UI/UX systems with usability and accessibility requirements. Use when shaping flows, design systems, interaction patterns, or WCAG-aware product behavior.
samber/cc-skills-golang
Idiomatic Golang design patterns — functional options, constructors, error flow and cascading, resource management and lifecycle, graceful shutdown, resilience, architecture, dependency injection, data handling, streaming, and more. Apply when explicitly choosing between architectural patterns, implementing functional options, designing constructor APIs, setting up graceful shutdown, applying resilience patterns, or asking which idiomatic Go pattern fits a specific problem.