Yolo Tầm nhìn Thâm Quyến
Thâm Quyến
Tham gia ngay
Bảng chú giải thuật ngữ

Chuỗi Prompt (Prompt Chaining)

Explore how prompt chaining decomposes complex AI tasks into reliable workflows. Learn to integrate [Ultralytics YOLO26](https://docs.ultralytics.com/models/yolo26/) with LLMs for advanced applications.

Prompt chaining is an advanced architectural pattern in Artificial Intelligence (AI) development where a complex task is decomposed into a sequence of smaller, manageable sub-tasks. In this workflow, the output of one step—often generated by a Large Language Model (LLM) or a computer vision system—serves as the input for the subsequent step. Unlike a single monolithic prompt that attempts to solve a multifaceted problem all at once, chaining allows developers to build more reliable, testable, and capable applications. This modular approach is essential for creating sophisticated AI Agents that can reason, browse the web, or interact with physical environments.

The Mechanics of Chaining

At its core, prompt chaining addresses the limitations of context windows and reasoning capabilities in Foundation Models. When a model is asked to perform too many distinct operations in a single request (e.g., "Analyze this image, extract the text, translate it to Spanish, and format it as a JSON invoice"), the probability of error increases. By splitting this into a pipeline, developers can verify the accuracy of each stage.

Effective chains often utilize "glue code" written in Python or managed by orchestration libraries like LangChain to handle data transformation between steps. This allows for the integration of disparate technologies, such as combining the visual acuity of Object Detection with the linguistic fluency of generative text models.

Các Ứng dụng Thực tế

Prompt chaining is particularly powerful when bridging the gap between different data modalities, enabling Multi-Modal Models to function in dynamic industrial and commercial settings.

  1. Automated Visual Reporting: In Smart Manufacturing, a quality control system can chain a vision model with an LLM. First, a high-speed model like Ultralytics YOLO26 scans components on an assembly line. The structured output (e.g., "Class: Dented_Can, Confidence: 0.92") is converted into a text string. This text is then passed to a language model with a prompt like "Draft a maintenance request based on this defect," generating a human-readable email for the floor manager.
  2. Context-Aware Customer Support: Intelligent chatbots often use chaining to navigate complex user queries. The first link in the chain might use Natural Language Processing (NLP) to classify user intent. If the intent is technical, the system triggers a Retrieval-Augmented Generation (RAG) workflow: it generates embeddings for the query, searches a vector database for documentation, and finally prompts an LLM to synthesize the retrieved chunks into a helpful answer.

Vision-to-Language Code Example

The following example demonstrates the first "link" in a chain: using Computer Vision (CV) to generate structured data that serves as the context for a downstream prompt.

from ultralytics import YOLO

# Load the YOLO26 model (natively end-to-end and highly efficient)
model = YOLO("yolo26n.pt")

# Step 1: Run inference to 'see' the environment
results = model("https://ultralytics.com/images/bus.jpg")

# Step 2: Format visual detections into a natural language string
det_names = [model.names[int(c)] for c in results[0].boxes.cls]
prompt_context = f"The scene contains: {', '.join(det_names)}. Please describe the likely activity."

# The 'prompt_context' variable is now ready to be sent to an LLM API
print(prompt_context)

Phân biệt các khái niệm liên quan

To implement effective Machine Learning (ML) architectures, it is helpful to differentiate prompt chaining from similar terms in the AI landscape:

  • Vs. Chain-of-Thought Prompting: Chain-of-Thought (CoT) is a technique used within a single prompt to encourage a model to "show its work" (e.g., "Think step-by-step"). Prompt chaining involves multiple distinct API calls where the input to step B depends on the output of step A.
  • Vs. Prompt Engineering: Prompt engineering is the broader discipline of optimizing text inputs to elicit better model performance. Chaining is a specific engineering pattern that focuses on the sequential flow of operations and logic control.
  • Vs. Prompt Tuning: Prompt tuning is a Model Optimization method that updates learnable parameters (soft prompts) during a training phase. Prompt chaining occurs entirely during Real-time Inference and does not alter the model's Model Weights.

By leveraging prompt chaining, teams can build robust applications that integrate logic, data retrieval, and Action Recognition. For managing the datasets and training the vision models that power these chains, the Ultralytics Platform offers a centralized solution for annotation, training, and deployment.

Tham gia Ultralytics cộng đồng

Tham gia vào tương lai của AI. Kết nối, hợp tác và phát triển cùng với những nhà đổi mới toàn cầu

Tham gia ngay