Subchapter 27.40
references/phases/generate/generate-ai.mdMarkdown18 KBView on GitHub
Loaded by generate.md when estimation-ai.json exists.
Execute ALL steps in order. Do not skip or optimize.
Read from $MIGRATION_DIR/:
aws-design-ai.json (REQUIRED) — AI architecture design from Phase 3estimation-ai.json (REQUIRED) — AI cost estimates from Phase 4ai-workload-profile.json (REQUIRED) — AI workload profile from Phase 1preferences.json (REQUIRED) — User migration preferences from Phase 2If any required file is missing: STOP. Output: “Missing required artifact: [filename]. Complete the prior phase that produces it.”
Check preferences.json → ai_constraints.ai_framework to determine the migration path. Describe effort by MECHANISM (what changes, how many files/lines) and duration by PHASE SEQUENCE — never calendar week/hour estimates (uncalibrated; see shared/migration-complexity.md § Provenance):
Gateway users (config-only path — shortest) — ai_framework includes llm_router, api_gateway, voice_platform, or framework:
| Gateway Type | Migration Action | Effort |
|---|---|---|
| LLM Router (LiteLLM, OpenRouter) | Change model string to bedrock/<model_id> | 1 config line |
| API Gateway (Kong, Apigee) | Add Bedrock upstream + SigV4 signing | 1-2 config files |
| Voice Platform (Vapi, Bland.ai) | Check native Bedrock support, update dashboard | Dashboard config |
| Framework (LangChain, LlamaIndex) | Swap provider import (e.g., ChatBedrock for ChatVertexAI) | 1-5 lines of code |
OpenAI SDK users via Mantle (config path for a Responses source; small reshape for a Chat Completions source) — ai_framework = direct AND ai_source = openai AND migration_path starts with mantle (mantle, mantle_openai_responses):
https://bedrock-mantle.{region}.api.aws/openai/v1 — note the openai/v1 segment for proprietary GPT models; a bare /v1 404sopenai.gpt-* for a same-model move)bedrock-mantle:* actions; bedrock:InvokeModel does not authorize these modelsresponses.create. A Chat Completions source must reshape to Responses — small and mechanical, but it is a code change, so do not present this path as “no code changes” without checking the detected surfaceMatch the migration_path prefix, not the exact string: Design writes the more specific mantle_openai_responses for a same-model OpenAI migration, and an equality test against mantle would misroute those runs into the adapter path below.
Direct SDK users (adapter path — the long pole) — ai_framework = direct AND (ai_source != openai OR migration_path = converse):
Duration drivers: multiple models (adapter + evaluation per model), framework integration, custom inference pipeline (the longest driver), and — when alongside infra migration — alignment with the infra deployment stage.
Based on ai-workload-profile.json → integration.pattern and integration.languages, generate SDK migration examples.
Migration patterns to include (matched to detected language and source):
| Source SDK | Target | Key Change |
|---|---|---|
| OpenAI SDK (same model) | Mantle Responses API | Base URL → .../openai/v1, Bedrock token/API key (not an OpenAI key), openai.gpt-* model ID. Config-only if already on responses.create; a Chat Completions source must reshape to Responses. |
| Vertex AI (Python) | boto3 Bedrock Converse API | GenerativeModel.generate_content() → bedrock.converse() |
| Vertex AI (JS) | @aws-sdk/client-bedrock-runtime | model.generateContent() → client.send(new ConverseCommand()) |
| Vertex AI (Go) | aws-sdk-go-v2 bedrockruntime | aiplatform → bedrockruntime.Converse() |
| Vertex AI (Java) | AWS SDK BedrockRuntimeClient | GenerativeModel → BedrockRuntimeClient.converse() |
| OpenAI SDK | boto3 Bedrock Converse API | client.chat.completions.create() → bedrock.converse() (if Mantle unavailable) |
| LiteLLM | LiteLLM config change | model="gpt-4o" → model="bedrock/anthropic.claude-sonnet-5", or keep the GPT family via the mantle endpoint when the source model is on Bedrock |
| LangChain | langchain_aws | ChatOpenAI/ChatVertexAI → ChatBedrock |
| LlamaIndex | llama_index.llms.bedrock_converse | Vertex → BedrockConverse |
For each detected language and pattern, generate before/after code examples using actual model IDs from aws-design-ai.json.
Include streaming migration (converse_stream) if capabilities_summary.streaming = true.
Include embeddings migration (Titan Embeddings v2 via invoke_model) if capabilities_summary.embeddings = true.
Feature flag strategy: AI_PROVIDER env var controls routing:
vertex_ai (default) — existing providerbedrock — switch to Bedrockshadow — send to both, return source response (for comparison)Rollback triggers: quality below threshold, P95 latency > 2x baseline, error rate > 1% for 5 min, cost per request > 3x source.
Rollback steps: Set AI_PROVIDER=vertex_ai (instant), verify source traffic, monitor 1 hour, investigate, re-attempt.
Key metrics and alert thresholds:
| Metric | Alert Threshold | Severity |
|---|---|---|
| Error rate | > 5% for 2 min → auto-rollback | Critical |
| Latency P95 | > 3x baseline for 5 min | High |
| Daily cost | > 2x projected | Medium |
| Token usage trend | > 120% of estimate | Low |
| Response quality | < 90% of source score | High |
Dashboard panels: Request volume by provider, latency comparison (P50/P95/P99), error rates, token usage, cost tracking, quality scores.
bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream| Category | Criteria | Target |
|---|---|---|
| Quality | Response quality | >= 90% of source baseline |
| Quality | Capability coverage | 100% of ai-workload-profile.json |
| Latency | P50 | Within 1.5x of source |
| Latency | P95 | Within 2x of source |
| Cost | Monthly | Within 20% of estimation-ai.json |
| Cost | Per request | Within 30% of source per-request |
Write generation-ai.json to $MIGRATION_DIR/.
Schema — top-level fields:
| Field | Type | Description |
|---|---|---|
phase | string | "generate" |
generation_source | string | "ai" |
timestamp | string | ISO 8601 |
migration_plan | object | duration_drivers[], approach, phases[] (name, sequence, activities), models_to_migrate[] |
step_by_step_guide | object | languages[], primary_pattern, files_to_modify[], dependency_changes |
rollback_plan | object | mechanism, flag_name, default_value, rollback_time, triggers[] |
monitoring | object | dashboards[], alerting_rules[] (severity, condition, action) |
production_readiness_checklist | array | String checklist items (at least 5) |
success_criteria | object | quality, latency, cost sub-objects with targets |
recommendation | object | approach, confidence, key_risks[] |
migration_plan.models_to_migrate covers all models from aws-design-ai.jsonstep_by_step_guide.languages matches ai-workload-profile.json languagesstep_by_step_guide.files_to_modify matches aws-design-ai.json code_migrationrollback_plan.mechanism is "feature_flag"success_criteria covers quality, latency, and costThe parent orchestrator (generate.md) uses generation-ai.json to:
generate-artifacts-ai.md requires this filegenerate-artifacts-docs.md for MIGRATION_GUIDE.md.phase-status.jsonAlways generate $MIGRATION_DIR/STARTUP_PROGRAMS.md when preferences.json contains ai_monthly_spend or startup_program_status. This artifact summarizes applicable AWS startup programs based on Q27 (startup_program_status) and workload type — not GCP or AI spend bands alone.
Content rules (all amounts from AWS official sources only):
# AWS Startup Programs for Your Migration
Based on your migration profile, here are the AWS programs most relevant to you.
Credits apply to Bedrock usage (Claude, Llama, Nova, and other third-party models).
## AWS Activate Credits
AWS Activate provides promotional credits to offset AWS costs including Amazon Bedrock.
Apply at: https://aws.amazon.com/startups/credits/
### Which tier applies to you
| Your situation | Package | Credits | How to apply |
| --------------------------------------- | --------------------------- | -------------- | ---------------------------------------------------------------------- |
| Self-funded, no VC/accelerator | Activate Founders | Up to $5,000 | Apply directly at aws.amazon.com/startups/credits — no Org ID needed |
| VC or accelerator-backed (pre-Series B) | Activate Portfolio | Up to $200,000 | Get your Activate Provider Org ID from your VC/accelerator, then apply |
| Ready to scale post-Activate-Portfolio | AWS Credits for AI Startups | $200,000+ | Invite-only — talk with your AWS Account Manager |
**Activate eligibility (Founders & Portfolio):** Pre-Series B, founded in the last 10 years, AWS Account on Paid Tier Plan, and either new to Activate Credits or requesting more credits than previously received.
Generation rules:
ai_monthly_spend is "$2K-$10K" or ">$10K" AND agentic_profile.is_agentic == truestartup_program_status.value == "has_credits": replace the “Apply for AWS Activate” steps with “You already have AWS Activate credits — ensure they are applied to your account before running terraform apply”startup_program_status.value == "unknown": never write your status: eligible_founders, your status: eligible_portfolio, or “Eligible Founders tier” in this file or the migration report — use neutral copy per the unknown branch abovestartup_program_status.value == "eligible_founders": may recommend Founders specifically; still mention Portfolio exists for VC-backed teamsstartup_program_status.value == "eligible_portfolio": may recommend Portfolio specifically; still mention Founders for self-funded teamsscripts/validate-startup-program-artifacts.py with --migration-dir $MIGRATION_DIR (see validate-artifacts.md check 16)