LLM Application Workflows in Practice: A Guide to Building AI Agents from Scratch

    This article explains why production LLM applications need orchestrated workflows instead of single prompts, then walks through five practical scenarios: multi-node content production, iterative loops with external data fetching, multimodal invoice extraction with cross-validation, fine-tuning dataset construction, and digital human broadcasting. It also includes an engineering checklist covering single-responsibility nodes, failure recovery, prompt versioning, evaluation, and cost control. Readers will learn how to turn prompt tuning into designing controllable, testable agent systems.

    1. Why Workflows Matter More Than a Single Conversation

    Once generative AI moves into the engineering phase, teams quickly run into a practical problem: a single model call is rarely enough to support real business needs. Real workflows involve input validation, information extraction, external data retrieval, conditional branching, multiple iterations, and result archiving. Any randomness in one step gets amplified by everything that follows. The value of workflow orchestration is to keep that uncertainty inside a controllable boundary.

    A mature workflow typically provides four capabilities. First, structured decomposition: breaking a complex task into nodes with single responsibilities that can be tested independently. Second, explicit control: fixing the execution path with conditional branches, loops, and parallel execution. Third, external integration: connecting to search, databases, object storage, message queues, and other common capabilities through API calls and plugin mechanisms. Fourth, observability: using logging and monitoring alerts to determine whether an issue comes from the prompt, the data, or the model.

    One point deserves emphasis: a workflow is not better simply because it is more complex. There is only one criterion: whether the node boundaries make each piece of logic independently verifiable. If a single node handles extraction, decision-making, and generation at the same time, it should be split further.

    2. Scenario 1: Multi-Node Orchestration for Content Production

    Content production is a typical multi-step task with strong style requirements. A practical pipeline can be designed as: trend collection → content cleaning → topic scoring → copy generation → multi-platform rewriting → compliance and fact-checking → archiving and publishing.

    The topic scoring node should output a structured result so that later threshold checks are straightforward:

    1. {
    2. "topic": "Example topic",
    3. "score": 0.82,
    4. "reason": "Broad audience coverage with clear information gain",
    5. "risk": "low"
    6. }

    Do not expect a single prompt to handle all style differences across platforms. A more reliable approach is to configure a separate system prompt for each platform, along with constraints on word count, tone, and structure, while sharing the same factual source document. This prevents factual drift between versions. The final compliance and fact-checking node should act as a mandatory gate, producing a binary pass/reject result. When a draft is rejected, it returns to the generation node with specific revision notes, forming a closed loop with a limited number of iterations.

    3. Scenario 2: Iterative Loop Nodes and External Data Fetching

    For news-ranking applications, the difficulty lies not in generation but in the stability of the fetch-parse-deduplicate-summarize sequence. An iterative loop node is recommended here: first retrieve the list of items, then run parsing and summarization on each record. Inside the loop body, handle field-level faults and retry failures. After the loop ends, aggregate and sort the results.

    Three engineering points matter. First, the loop must have a maximum iteration count and a timeout to prevent abnormal data from exhausting resources. Second, a single failure should not stop the entire run; use a strategy that records the error and continues. Third, the summarization node should limit input length; split overly long text into segments and merge them afterward so that the context is not crowded out by irrelevant content. External data retrieval is best handled through a general API-call node, with schema validation on the returned structure.

    4. Scenario 3: Invoice Information Extraction and Cross-Validation with Multimodal Models

    Pure visual recognition tends to misread characters on invoices, where text is dense and font sizes are small. A more reliable approach is a three-stage design: visual extraction + rule-based validation + text-model review. The first stage has a multimodal model output candidate fields. The second stage applies regex and arithmetic rules to check formatting and amount consistency, for example the relationship between tax amount, pre-tax amount, and tax rate. The third stage passes the failed checks, along with the candidate values, to a text model for reasoning-based review and a confidence score.

    For batch scenarios involving multiple invoices, process them one by one inside a loop node and output a unified array structure, while preserving the original identifier of each invoice for traceability. The key design principle here is: let deterministic rules handle deterministic work, and leave ambiguous judgment to the model.

    5. Scenario 4: Building a Corpus Pipeline for Fine-Tuning

    The ceiling on fine-tuning results is determined by data quality. A corpus construction workflow can be broken down into: raw document collection → segmentation and cleaning → instruction generation → quality filtering → deduplication and data mixing → formatted export.

    For the instruction generation stage, use multiple templates in parallel with cross-validation: generate several instructions from the same text using different templates, then have a validation node remove samples where the answer duplicates the source text or does not match the question. Quality filtering can combine length thresholds, semantic similarity deduplication, and rule-based blacklists. For export, standardize on the common instruction-input-output three-part structure so the data can be moved between different training frameworks:

    1. {"instruction": "Answer the question based on the context", "input": "Context snippet", "output": "Reference answer"}

    Data mixing matters just as much. General capabilities and domain capabilities need to be balanced; too high a proportion of domain samples can degrade general performance. Keep a certain share of high-quality general samples, and fix a validation set for regression evaluation.

    6. Scenario 5: Digital Human Broadcasting and End-to-End Interaction

    A digital human scenario can be abstracted into a pipeline: text generation → speech synthesis → lip-sync and expression driving → video composition → distribution. The engineering focus is latency and consistency: control length and sentence breaks on the text side, unify pronunciation dictionaries and speech-rate parameters on the audio side, and keep phoneme timestamps aligned with video frames on the driving side.

    For deployment, cloud-based setups offer good elasticity and fast iteration, while on-premises setups offer data control and stable latency. Choose based on compliance requirements, or adopt a hybrid mode: process sensitive data locally and scale rendering tasks elastically in the cloud.

    To run this kind of pipeline on Baidu AI Cloud, you can typically combine a container platform for rendering tasks, object storage for assets and outputs, a message queue for task decoupling, and logging plus monitoring alerts for observability.

    7. Engineering Implementation Checklist

    1. Single responsibility per node: each node does one thing, with explicitly declared input and output structures.
    2. Recoverable failures: set timeouts, retries, and fallback paths across the pipeline, and retain raw outputs for critical nodes.
    3. Prompt versioning: put prompts under version control, and roll out changes through canary releases and regression evaluation.
    4. Evaluation first: build a small annotated set, and drive optimization with three metrics: accuracy, structured parsing success rate, and latency.
    5. Cost control: track call volume per node, and compress long text before sending it to the model.

    Once you master these patterns, building workflows shifts from tuning prompts to designing controllable systems. That shift is the dividing line for whether an agent application can actually reach production.