Back to series
· 16 min read

Continuous Integration and Continuous Delivery for AI Systems


I. What Are Continuous Integration and Continuous Delivery for AI Systems?

CI/CD is the collective term for Continuous Integration and Continuous Delivery / Deployment.

CI/CD for traditional software revolves mainly around code, whereas AI systems have far more complex delivery targets. A complete AI application typically includes:

  • Application code: business logic, APIs, task scheduling, and service interfaces.
  • Models: foundation models, fine-tuned models, model weights, and inference configuration.
  • Prompts: system prompts, task templates, and output format constraints.
  • Data: training data, evaluation data, knowledge bases, and data processing rules.
  • Tools: search, databases, external APIs, and Agent tools.
  • Workflows: RAG pipelines, Agent execution chains, and multi-model collaboration logic.
  • Runtime configuration: model parameters, timeouts, concurrency, rate limiting, and security policies.

These components influence one another, and a change in any one of them can alter the final output.

For example:

  • The code is unchanged, but the model is swapped, and answer quality may change.
  • The model is unchanged, but the Prompt is modified, and the task completion rate may drop.
  • The Prompt is unchanged, but the knowledge base is updated, and retrieval results may change.
  • The data is unchanged, but the Temperature is adjusted, and output stability may change.
  • The Agent is unchanged, but the tool interface is upgraded, and the execution flow may fail.

Therefore, CI/CD for AI systems cannot merely check whether the code runs; it must also validate model behavior, business outcomes, data quality, and system performance.

1. Continuous Integration (CI)

Continuous integration means that developers frequently commit code and configuration changes, and an automated pipeline performs builds, checks, and tests.

In AI systems, CI needs to check:

  1. Whether the code conforms to standards.
  2. Whether the Prompt passes format and security checks.
  3. Whether the model configuration is valid.
  4. Whether the dataset meets quality requirements.
  5. Whether the RAG and Agent workflows function correctly.
  6. Whether model outputs meet evaluation criteria.
  7. Whether the service builds and dependencies are correct.

The core goal of CI is to detect problems introduced by changes as early as possible.

2. Continuous Delivery

Continuous delivery is the process, after CI passes, of building the validated AI system into deployable artifacts and preparing it for release to testing, staging, or production environments.

Continuous delivery emphasizes:

  • Every change has a traceable version.
  • Every version has undergone automated testing.
  • Deployment packages can be rebuilt and verified repeatedly.
  • Production releases require approval or release policy controls.
  • Problems can be rolled back quickly.

Continuous delivery does not mean every commit immediately enters production; rather, it ensures the system is always in a releasable state.

3. Continuous Deployment

Continuous deployment means that once all automated validations pass, changes are released directly to the production environment.

Continuous deployment suits systems with high test coverage, controllable risk, and mature rollback mechanisms.

For systems involving model switching, data permissions, Agent tool execution, and high-risk business decisions, additional manual approval and canary validation are usually required.

4. Differences Between CI, Continuous Delivery, and Continuous Deployment

Dimension Continuous Integration Continuous Delivery Continuous Deployment
Core goal Validate changes quickly Maintain a releasable state Automatically enter production
Primary scope Build and test Build, test, artifact management Full production release
Manual approval Usually not required May be required for production releases Usually not required
Release frequency Every commit Per release plan Automatic release after validation passes
Risk control Automated testing Release approval and rollback Automated gates and rollback

II. Overall Architecture of CI/CD for AI Systems

Traditional software pipelines are usually centered on the code repository, whereas AI systems need to integrate code repositories, model repositories, data repositories, Prompt repositories, and evaluation systems.

1. Overall Architecture

A typical AI CI/CD platform can be divided into six layers.

Layer Core Components Primary Responsibilities
Change management layer Git, Prompt Registry, Model Registry Manage versions and changes
Automation trigger layer Webhook, CI Runner, task scheduler Trigger pipelines
Build and validation layer Lint, Build, Unit Test, Integration Test Build and functional validation
AI evaluation layer Eval Dataset, LLM Judge, RAG Eval Validate model effectiveness
Release management layer Artifact Registry, Deployment, Canary Release and traffic management
Monitoring and feedback layer Metrics, Tracing, Logging, Alerting Monitoring and continuous improvement

2. Overall Workflow

flowchart TD
    A["Developer submits changes"] --> B["Code and configuration repository"]
    B --> C["CI pipeline triggered"]
    C --> D["Static checks and dependency checks"]
    D --> E["Build application and generate artifacts"]
    E --> F["Unit tests and integration tests"]
    F --> G["AI quality assessment"]
    G --> H{"Quality gate passed?"}
    H -->|No| I["Generate test report and block release"]
    H -->|Yes| J["Register version and artifacts"]
    J --> K["Deploy to staging environment"]
    K --> L["Staging validation"]
    L --> M{"Release conditions met?"}
    M -->|No| N["Fix issues or terminate release"]
    M -->|Yes| O["Canary release"]
    O --> P["Production environment monitoring"]
    P --> Q{"Are runtime metrics normal?"}
    Q -->|No| R["Roll back or stop traffic expansion"]
    Q -->|Yes| S["Gradually increase traffic"]
    S --> T["Complete official release"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#EAF3EC,stroke:#83A995,color:#315D49
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style E fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style F fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style G fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style I fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style J fill:#EAF3EC,stroke:#83A995,color:#315D49
    style K fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style L fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style M fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style N fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style O fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style P fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style Q fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style R fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style S fill:#EAF3EC,stroke:#83A995,color:#315D49
    style T fill:#DCEFE5,stroke:#4F8B70,color:#24563F

The key to this pipeline is not the number of steps, but that each stage has clear inputs, outputs, validation criteria, and failure handling methods.

3. Differences Between AI CI/CD and Traditional CI/CD

Comparison Dimension Traditional Software CI/CD AI System CI/CD
Primary deliverables Code and software packages Code, models, prompts, data, and configurations
Testing approach Unit tests and API tests Traditional testing combined with AI quality assessment
Determinism of results Usually high Exhibits randomness and non-determinism
Quality assessment Whether functionality is correct Functional correctness and model performance
Dependency management Software dependency libraries Software, model, data, and tool dependencies
Release strategy Rolling and blue-green releases Canary releases, shadow traffic, and model version switching
Rollback targets Application version Application, model, prompt, index, etc.
Monitoring metrics CPU, memory, latency, error rate Traditional metrics plus tokens, quality, cost, etc.

III. Version Management for AI Systems

Continuous delivery for AI systems must first address the issue of version management.

If only code versions are recorded and model, prompt, and data versions are not, it is impossible to accurately reproduce a particular online request.

1. Code Version Management

Code is managed using Git. Common branching strategies include:

  • Main: the main branch, which stores stable code.
  • Feature: feature development branch.
  • Release: release preparation branch.
  • Hotfix: emergency fix branch.

Each commit should include a clear change description and undergo code review via a Pull Request or Merge Request.

For AI projects, the code repository should also record:

  • Model invocation logic.
  • Prompt loading logic.
  • RAG retrieval and reranking logic.
  • Agent tool definitions.
  • Evaluation scripts.
  • Deployment configuration.
  • Version manifest files.

2. Model Version Management

Model version management needs to distinguish model identity, model weights, and runtime configuration.

For example:

model:
  provider: openai
  model_id: example-model
  model_revision: snapshot-2026-11
  temperature: 0.2
  max_tokens: 2048
  timeout: 30

inference:
  retry_count: 2
  request_concurrency: 20
  streaming: true

Model version management needs to note:

  1. Use explicit model snapshots or version identifiers whenever possible.
  2. Record model provider and model identifier.
  3. Record inference parameters such as Temperature, Top P, and maximum output tokens.
  4. Record model API compatibility and dependency configuration.
  5. Record evaluation results before and after model switching.

Some hosted model services do not allow users to pin the underlying weight version. In such cases, record the provider, model identifier, invocation time, and any available version information, and perform regression evaluations regularly.

3. Prompt Version Management

Prompts should be version-controlled just like code.

For example:

prompts/
├── system/
│   ├── assistant_v1.md
│   └── assistant_v2.md
├── rag/
│   ├── answer_v1.md
│   └── answer_v2.md
└── agent/
    ├── planner_v1.md
    └── planner_v2.md

For each Prompt change, record:

  • Reason for change.
  • Changes made.
  • Applicable model.
  • Associated evaluation set.
  • Quality evaluation results.
  • Release version.
  • Rollback version.

Whether a Prompt change is reasonable cannot be determined solely by manual reading; automated tests must also be run on a fixed evaluation dataset.

4. Data Version Management

Data version management applies not only to model training but also to RAG knowledge bases and evaluation datasets.

Objects to manage include:

  • Training datasets.
  • Validation datasets.
  • Test datasets.
  • RAG raw documents.
  • Document parsing results.
  • Embedding versions.
  • Vector index versions.
  • Evaluation question sets.

For RAG systems, document content, chunking strategy, Embedding model, and index parameters all affect retrieval results; therefore, complete data version records need to be established.

5. Use a Unified Manifest to Manage Versions

It is recommended to use a Manifest to describe all key components that an AI application release depends on.

application:
  name: knowledge-assistant
  version: 1.8.0

code:
  commit: a1b2c3d
  image: registry.example.com/ai/app:1.8.0

model:
  provider: openai
  model_id: example-model
  revision: snapshot-2026-11

prompt:
  system_prompt: assistant-v3
  rag_prompt: rag-answer-v2

dataset:
  evaluation_set: eval-v5
  knowledge_base: kb-v12

retrieval:
  embedding_model: embedding-v2
  chunk_size: 800
  top_k: 5

evaluation:
  accuracy_threshold: 0.85
  groundedness_threshold: 0.90

release:
  environment: production
  strategy: canary

A Manifest is a version snapshot of an AI system release.

It can answer:

  • What model is currently used in production?
  • Which Prompt is being used?
  • Have the knowledge base and Embedding changed?
  • Which Git Commit does the current version correspond to?
  • Which evaluation validated this version?
  • Which version should be restored to if a failure occurs?

Note that a Manifest should store verifiable version identifiers or content digests, not merely record file names that are prone to change.


IV. Automated Validation in the CI Stage of AI Systems

The focus of the CI stage is to prevent substandard changes from entering subsequent environments as early as possible.

Testing for AI systems should be divided into traditional software testing and AI-specific testing.

1. Static Checks

Static checks do not require actually calling the model and are mainly used to validate code and configuration.

Common checks include:

  • Code style for Python, TypeScript, etc.
  • Type checking.
  • Dependency vulnerability scanning.
  • Configuration file format checks.
  • Prompt template variable checks.
  • Tool schema checks.
  • API contract checks.
  • Sensitive information scanning.

For example, checking whether the template variables in a Prompt are complete:

```python required_variables = { "question", "context" } prompt_template = """ Please answer the question based on the following material. Material: {context} Question: {question} """ for variable in required_variables: assert "{" + variable + "}" in prompt_template ```

Static checks can catch obvious structural errors, but they cannot determine whether the model will ultimately answer the question correctly.

2. Unit Testing

Unit tests verify whether an independent module meets expectations.

Common test targets in AI applications include:

  • Token counting module.
  • Prompt rendering module.
  • Document splitting module.
  • Embedding data transformation module.
  • Retrieval result filtering module.
  • Tool parameter validation module.
  • Output structure parsing module.

For example:

```python def render_prompt(template, question, context): return template.format( question=question, context=context ) def test_render_prompt(): template = "Material: {context}\nQuestion: {question}" result = render_prompt( template, question="What is RAG?", context="RAG is a retrieval-augmented generation technique." ) assert "What is RAG?" in result assert "retrieval-augmented generation technique" in result ```

Unit tests should isolate external model APIs as much as possible, using Mock or Fake objects to verify business logic, so that every commit does not incur unnecessary model call costs.

3. Integration Testing

Integration tests verify the behavior of multiple components working together.

For example, a RAG system needs to verify:

  • Whether documents can be parsed normally.
  • Whether text can be split correctly.
  • Whether embeddings are generated successfully.
  • Whether vectors are written to the database successfully.
  • Whether retrieval returns the expected content.
  • Whether context is correctly injected into the Prompt.
  • Whether the final answer conforms to the output format.

An Agent system also needs to test:

  • Whether tools can be discovered correctly.
  • Whether parameters conform to the tool Schema.
  • Whether tool calls succeed.
  • Whether the system can recover when a tool fails.
  • Whether the Agent obeys the maximum number of execution steps.
  • Whether infinite loop calls occur.

4. AI Quality Evaluation

This is the key part of AI system CI that distinguishes it from traditional software.

Traditional tests usually verify whether the result is exactly consistent with expectations, but large model outputs have a certain degree of randomness, so direct string equality comparison is often unreasonable.

Therefore, a dedicated AI evaluation system needs to be established.

Common evaluation metrics are as follows:

Metric Meaning Applicable Scenarios
Accuracy Rate of correct predictions Classification, extraction, structured tasks
Precision Proportion of correct results among predicted results Information extraction, classification
Recall Proportion of correct results that are retrieved Retrieval, recall tasks
F1 Combined metric of Precision and Recall Classification and retrieval
Faithfulness Whether the answer is faithful to the given context RAG
Relevance Whether the answer is relevant to the question Question answering systems
Groundedness Whether the answer is supported by evidence RAG
Tool Success Rate Tool call success rate Agent
Task Completion Rate Task completion rate Agent, workflows
JSON Validity Whether the output conforms to the JSON format Structured output

For RAG systems, it is usually necessary to evaluate both retrieval quality and generation quality.

For Agent systems, in addition to the final answer, attention should also be paid to tool selection, parameter correctness, execution steps, and task completion.

5. Automated Evaluation Example

A fixed evaluation set can be used to run regression tests.

```python evaluation_cases = [ { "question": "什么是 RAG?", "expected_keywords": ["检索", "生成", "增强"], }, { "question": "RAG 有什么作用?", "expected_keywords": ["知识库", "上下文"], }, ] def evaluate_answer(answer, expected_keywords): matched = sum( keyword in answer for keyword in expected_keywords ) return matched / len(expected_keywords) def run_evaluation(model): scores = [] for case in evaluation_cases: answer = model.generate(case["question"]) score = evaluate_answer( answer, case["expected_keywords"] ) scores.append(score) return sum(scores) / len(scores) average_score = run_evaluation(model) assert average_score >= 0.85 ```

Keyword matching here is only meant to demonstrate the basic structure of automated evaluation. In production, keyword coverage should not be treated directly as a complete measure of semantic quality.

A more reasonable approach combines:

  • Deterministic rules.
  • Comparison against reference answers.
  • Structured metrics.
  • Semantic similarity.
  • LLM Judge.
  • Manual sampling evaluation.

6. Using an LLM Judge

An LLM Judge uses another model to evaluate the output of the target model.

For example:

```text Evaluation task: Determine whether the answer accurately resolves the user's question. Input: User question Reference materials Model answer Evaluation dimensions: 1. Content accuracy 2. Relevance to the question 3. Presence of unsupported content 4. Whether key information is missing Output: score: 1-5 reason: basis for the score ```

But an LLM Judge itself may also exhibit bias, for example:

  • Preference for longer answers.
  • Preference for certain ways of phrasing.
  • Evaluation results that are not stable enough.
  • Inability to reliably identify all factual errors.
  • Susceptibility to influence from the evaluation prompt.

Therefore, an LLM Judge cannot serve as the sole criterion for judging quality.

It is recommended to use it together with deterministic tests, human annotation, and historical baselines.

7. Quality gates

Quality gates are used to decide whether a version can advance to the next stage.

For example:

```yaml quality_gate: unit_tests: pass_rate: 1.0 integration_tests: pass_rate: 1.0 ai_evaluation: accuracy: 0.85 groundedness: 0.90 relevance: 0.90 security: critical_vulnerabilities: 0 performance: p95_latency_ms: 3000 ```

These thresholds are only examples; actual standards need to be determined based on the business scenario, model capabilities, invocation cost, and risk level.

For high-risk applications such as finance, healthcare, and law, one cannot simply rely on a uniform model scoring threshold; additional professional review and business rule validation are also required.


V. Build and Artifact Management in the CD Phase of AI Systems

After passing CI, the validated version needs to be built into deployable artifacts.

1. Build artifacts

Common artifacts include:

  • Application container images.
  • Model weight files.
  • Prompt template packages.
  • Evaluation reports.
  • Data processing programs.
  • RAG index snapshots.
  • Agent workflow configurations.
  • Version manifests.

Different artifacts should use storage methods that suit them.

Artifact Common storage location
Application image Container Registry
Model weights Model Registry / Object Storage
Prompt Git / Prompt Registry
Dataset Dataset Registry / Object Storage
RAG index Vector Database / Snapshot Storage
Evaluation report Artifact Registry
Manifest Git / Artifact Registry

2. Containerized build

AI services usually use Docker to build a unified runtime environment.

Example:

```dockerfile FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY src/ ./src/ COPY prompts/ ./prompts/ COPY config/ ./config/ ENV PYTHONUNBUFFERED=1 EXPOSE 8000 CMD ["python", "-m", "src.main"] ``` When building, keep in mind: 1. Pin the base image version. 2. Pin the versions of critical dependencies. 3. Avoid writing API keys into the image. 4. Run vulnerability scans on the image. 5. Record the image digest. 6. Keep the build process reproducible. For model inference services that use GPUs, you also need to consider compatibility between CUDA, drivers, deep learning frameworks and hardware. ### 3. The Principle of Immutable Artifacts Production releases should use immutable artifacts wherever possible. For example: ```text registry.example.com/ai-assistant:1.8.0 registry.example.com/ai-assistant@sha256:abc123... ``` Tags are easy to recognize but may be repointed to a different image. A digest identifies image content more precisely. Recommended practice: - Build once. - Test the same artifact. - Promote the same artifact from the test environment to production. - Verify artifact consistency via the digest. Do not rebuild what looks like the same version in production, otherwise differences may arise from changed dependencies, a changed build environment, or other factors. ### 4. Supply Chain Security Artifact management for AI systems must also consider supply chain security. This mainly includes: - Dependency vulnerability scanning. - Container image security scanning. - Verification of model file origin. - Integrity verification of model weights. - Auditing of dataset provenance. - Software bill of materials (SBOM). - Build provenance. - Artifact signing and verification. In particular, for third-party model weights and external datasets, you should verify origin, licensing and file integrity, and avoid introducing untrusted artifacts directly into the production environment. --- ## VI. Automated Deployment Strategies for AI Systems When releasing AI systems, you need to control changes in model quality, service stability and resource costs. Common deployment strategies include rolling deployment, blue-green deployment, canary deployment and shadow deployment. ### 1. Rolling Deployment Rolling deployment is a deployment method that gradually replaces old instances. For example, if there are currently 10 service instances, you can replace 2 instances at a time until all are updated. Advantages: - Higher resource utilization. - A relatively smooth release process. - No need to maintain two complete environments over the long term. Disadvantages: - Old and new versions may serve traffic at the same time. - If the versions are incompatible, problems may occur. - Rolling back requires redeploying the old version. It is suitable for routine updates of application code and stateless services. ### 2. Blue-Green Deployment Blue-green deployment maintains two environments at the same time: - Blue: the current production environment. - Green: the new version environment. After the new version is deployed to the Green environment and validated, it goes live officially by switching traffic. ```mermaid flowchart TD A["Current production traffic"] --> B["Load balancer"] B --> C["Blue - old version"] D["Deploy new version"] --> E["Green - new version"] E --> F["Health checks and business validation"] F --> G{"Validation passed?"} G -->|No| H["Keep the Blue environment"] G -->|Yes| I["Switch production traffic"] I --> J["Green becomes production"] J --> K["Keep Blue for rollback"] style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F style B fill:#EAF3EC,stroke:#83A995,color:#315D49 style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976 style D fill:#F5F8F4,stroke:#B5CBBB,color:#40594A style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D style F fill:#F5F8F4,stroke:#B5CBBB,color:#40594A style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D style H fill:#DCEFE5,stroke:#4F8B70,color:#24563F style I fill:#EAF3EC,stroke:#83A995,color:#315D49 style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F style K fill:#F5F8F4,stroke:#B5CBBB,color:#40594A ``` Blue-green deployment suits AI services that need fast switching and fast recovery. However, if the old and new versions share the same mutable vector index, database schema or external state, you cannot simply assume that switching traffic completes a full rollback. ### 3. Canary Deployment Canary deployment first allocates a small share of production traffic to the new version, then gradually expands that traffic based on monitoring results. For example:
Stage New-version traffic
Stage 1 1%
Stage 2 5%
Stage 3 20%
Stage 4 50%
Stage 5 100%

Each stage requires checking:

  • Request success rate.
  • P95 / P99 latency.
  • Model output quality.
  • Token consumption.
  • Tool call success rate.
  • Task completion rate.
  • User feedback.
  • Resource usage.
flowchart TD
    A["Release new version"] --> B["Route 1% of traffic"]
    B --> C["Collect production metrics"]
    C --> D{"Are metrics normal?"}
    D -->|No| E["Stop rollout and roll back"]
    D -->|Yes| F["Expand to 5% traffic"]
    F --> G["Continue monitoring quality and performance"]
    G --> H{"Are next-stage criteria met?"}
    H -->|No| E
    H -->|Yes| I["Expand to 20% traffic"]
    I --> J["Continue evaluation"]
    J --> K{"Are release criteria met?"}
    K -->|No| E
    K -->|Yes| L["Gradually expand to 100%"]
    L --> M["Complete full release"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style C fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style D fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style E fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style G fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style I fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style J fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style K fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style L fill:#EAF3EC,stroke:#83A995,color:#315D49
    style M fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Canary releases are particularly well suited to model version upgrades, Prompt changes, and Agent workflow adjustments.

Note, however, that 1% of traffic is not necessarily statistically representative. If the sample size is insufficient, quality metrics may fluctuate considerably.

Therefore you also need to set:

  • A minimum number of request samples.
  • A minimum observation time.
  • A maximum allowable error rate.
  • A threshold for quality metric degradation.
  • A threshold for cost growth.

4. Shadow Release

Shadow release is also known as Shadow Deployment.

The new version receives copies of production requests but does not return the new version's results to users.

The old version continues to serve the real responses; the new version is used only for observation and comparison.

flowchart TD
    A["User Request"] --> B["Request Router"]
    B --> C["Production Version"]
    B --> D["Shadow Version"]
    C --> E["Return User Response"]
    D --> F["Record Shadow Output"]
    E --> G["Result Collection"]
    F --> G
    G --> H["Offline Quality Comparison"]
    H --> I["Analyze Performance, Quality and Cost"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#EAF3EC,stroke:#83A995,color:#315D49
    style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style F fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style G fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style H fill:#EAF3EC,stroke:#83A995,color:#315D49
    style I fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Advantages of shadow release:

  • It does not affect the actual user experience.
  • Real requests can be used to evaluate the new model.
  • It can compare output differences across different Prompts.
  • It can detect changes in online data distribution in advance.

Points to note:

  • Shadow requests may incur additional model invocation costs.
  • Copying and access permissions for sensitive information must be controlled.
  • The shadow Agent should not perform side-effect operations such as real writes, payments, or sending emails.
  • The shadow environment should isolate external tools and business state as much as possible.

VII. Monitoring and Quality Feedback After AI System Release

A successful AI system release does not mean the system quality will remain stable over the long term.

Model providers may update their services, the distribution of user requests may change, the knowledge base may become outdated, and external tools may also malfunction.

Therefore, the CD pipeline must be connected to the production monitoring system.

1. Basic Runtime Metrics

First, monitor traditional service metrics:

Metric Purpose
QPS Request throughput
Error Rate Request error rate
P50 Latency Median response time
P95 Latency Response time for 95% of requests
P99 Latency Response time for 99% of requests
CPU Usage CPU utilization
Memory Usage Memory utilization
GPU Utilization GPU utilization
Queue Length Request queue length

2. AI-Specific Metrics

AI systems also need to monitor model invocations and task effectiveness.

Metric Description
Input Tokens Number of input Tokens
Output Tokens Number of output Tokens
Total Tokens Total number of Tokens
Cost Per Request Cost per request
Model Latency Model invocation latency
First Token Latency Time to first Token
Tool Call Success Rate Tool call success rate
Retrieval Hit Rate Retrieval hit rate
Groundedness Degree to which answers are sufficiently grounded
Task Completion Rate Task completion rate
User Feedback Score User feedback score

For streaming output, first Token latency and overall response time should be measured separately, because they affect the user's perceived waiting experience and the task completion time respectively.

3. Model Quality Drift

Model quality drift refers to the gradual deviation of output quality from expectations during system operation.

Possible causes include:

  • Changes in the distribution of user input.
  • New business domains being added.
  • Outdated knowledge base content.
  • Prompts being modified.
  • Changes in the model service version.
  • Changes in the content returned by external tools.

It is necessary to continuously collect representative online samples and run offline evaluations on a regular basis.

For data involving privacy, mechanisms such as anonymization, sampling, and access control should be adopted; user's original requests must not be stored unconditionally just for the sake of quality monitoring.

4. Quality Feedback Loop

flowchart TD
    A["Run in production environment"] --> B["Collect requests and runtime metrics"]
    B --> C["Anomaly detection and quality assessment"]
    C --> D{"Are there quality issues?"}
    D -->|No| E["Continuous monitoring"]
    E --> B
    D -->|Yes| F["Locate the source of the issue"]
    F --> G["Analyze code, model, Prompt, and data"]
    G --> H["Develop a fix plan"]
    H --> I["Submit a new version"]
    I --> J["Trigger CI regression tests"]
    J --> K{"Does it pass the quality gate?"}
    K -->|No| L["Continue fixing"]
    L --> I
    K -->|Yes| M["Enter the CD release process"]
    M --> N["Canary validation"]
    N --> O["Complete release and continue monitoring"]

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style F fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style G fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style H fill:#EAF3EC,stroke:#83A995,color:#315D49
    style I fill:#EAF3EC,stroke:#83A995,color:#315D49
    style J fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style K fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style L fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style M fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style N fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style O fill:#DCEFE5,stroke:#4F8B70,color:#24563F