Building Reliable LLM Agents: From Task Planning to Automated Research Report Generation

    LLM agents have evolved from answering questions to autonomously completing tasks. This article walks through the key capabilities of modern agent workflows—task planning, code execution, programmatic chart generation, and deployment trade-offs—using automated research report generation as a running example. It also presents a multi-model numerical accuracy comparison, explains why LLMs fail at precise calculations, and offers architecture recommendations for building dependable data-to-report systems.

    Building Reliable LLM Agents: From Task Planning to Automated Research Report Generation

    Background: What LLM Agents Are Changing

    Over the past two years, the application paradigm of large language models has shifted noticeably: from simple question answering, to retrieval-augmented generation (RAG), and now to goal-driven autonomous agents. Question answering solves the problem of “knowledge acquisition,” while the agent paradigm solves the problem of “task completion”—the user provides only a goal, and the model handles decomposition, execution, verification, and delivery on its own.

    A typical scenario is automated research report generation: given a raw data table and a one-sentence natural-language request, the system automatically reads the data, retrieves relevant news, computes statistical indicators, draws charts, and produces an illustrated PDF document. This used to take a data analyst team hours; an agent workflow can close the loop in minutes.

    This article uses that scenario as the main thread to break down the key technical capabilities of the new generation of LLM agents, and discusses lessons learned and pitfalls in practice.

    Core Stages of an Agent Workflow

    1. Task Planning: From Goal to To-Do List

    The first action of a mature agent upon receiving a task is not execution—it is planning. It decomposes the user’s goal into a structured task list, for example:

    1. Read the local data file and parse the table schema and field meanings;
    2. Compute core statistical indicators (e.g., the current inventory percentile and basis percentile);
    3. Search the web or a local knowledge base for relevant industry news;
    4. Write the analytical narrative;
    5. Generate charts and merge everything into a PDF.

    This “plan first, execute step by step, check off items as you go” pattern significantly improves the reliability of long-chain tasks. Compared with generating all content in one shot, step-by-step execution makes every intermediate result inspectable and correctable, and allows partial retries on failure instead of starting over.

    2. Code Execution: Using Programs to Guarantee Reproducible Computation

    The agent’s primary means of executing tasks is generating and running script code, not “answering directly.” Taking Python as an example, a typical execution path is:

    1. import pandas as pd
    2. df = pd.read_excel("inventory.xlsx")
    3. inventory_quantile = df["inventory"].rank(pct=True).iloc[-1]
    4. basis_quantile = df["basis"].rank(pct=True).iloc[-1]
    5. print(f"Current inventory percentile: {inventory_quantile:.1%}")

    This point is critical: anything involving numerical computation, data aggregation, or file processing should be done by the agent through code execution rather than relying on the model’s own “mental arithmetic.” The reasons are covered in the next section.

    3. Chart Generation: Programmatic Plotting Beats Image-Generation Models

    For document illustrations, there are two technical routes:

    • Programmatic plotting: The agent calls mature data visualization libraries and draws line charts, bar charts, heatmaps, etc., precisely according to the data logic. The advantages are exact values, rigorous axes, and reproducibility—well suited to professional research reports.
    • Generative illustration: Images are produced by an image-generation model. The advantage is flexible visual style; the drawback is that the numbers in the image cannot be guaranteed to match the real data, falling short on professionalism and precision.

    In finance, quantitative analysis, and other scenarios that demand data accuracy, programmatic plotting should be the default. In practice, simply adding an instruction to the prompt such as “use a visualization library to draw the charts, and merge the narrative and charts into a PDF document” is enough for the agent to complete the full pipeline of plotting, layout, and document assembly.

    4. Deployment: Local vs. Cloud-Hosted Agents

    Agent runtime environments currently fall into two categories:

    • Local execution: The agent operates directly on the user’s local files and toolchain; data never leaves the premises. This suits scenarios involving sensitive data but requires local environment setup.
    • Cloud-hosted: A cloud agent host with a browser interface, usable without connecting your own API keys, often with a free quota upon sign-up and a low barrier to entry. The limitations are: first, the tool ecosystem depends on capabilities provided by the platform; second, if the charting step uses an image-generation model, precision suffers; third, once the free quota is exhausted, intermediate artifacts are hard to keep editing, limiting task continuity.

    For serious production scenarios, prefer a solution with controllable data and a customizable execution environment; cloud-hosted agents are better suited for rapid validation and prototyping.

    A Multi-Model Numerical Accuracy Comparison

    We used the computation of two indicators—“current inventory percentile” and “current basis percentile”—as a test task, letting multiple models complete it independently in agent mode. The results (approximate measured values) were:

    Model Inventory Percentile Basis Percentile
    Model A 26.3% 55.0%
    Model B 21.2% 55.2%
    Model C 27.4% 68.0%
    Model D ~30% ~30%

    The models clearly disagree, and some even returned vague conclusions like “approximately 30%.”

    Why LLMs Get Precise Decimals Wrong

    The root cause lies in how large language models work: they are fundamentally probabilistic generators based on training data and context, not symbolic computation engines. When asked to “answer directly” with a precise decimal, the model is effectively guessing a plausible-looking answer rather than strictly following mathematical rules. This is especially evident on tasks like statistical percentiles, which require precise sorting and interpolation.

    This leads to a golden rule for building reliable agent systems:

    If it can be written as code, never let the model “answer verbally.”

    Concrete implementation recommendations:

    1. Enforce a code-execution path: Explicitly require in the system prompt that all numerical conclusions must come from script execution results; the model only interprets and narrates.
    2. Result verification step: Set up independent verification for key indicators, such as cross-checking with different implementations; if the deviation exceeds a threshold, trigger recomputation.
    3. Output format constraints: Require scripts to output fixed-precision formatted results to avoid rounding errors introduced when the model paraphrases them.
    4. Keep computation traces: Have the agent include methodology notes and key code in the final document for manual review.

    Architecture Recommendations for an Automated Report System

    Synthesizing the practices above, a robust “data-to-report” automation system can be abstracted into five layers:

    • Data layer: Local files, databases, or object storage, with access control to protect data security;
    • Execution layer: A controlled code sandbox that lets the agent run scripts within defined access boundaries;
    • Retrieval layer: A hybrid channel of web search and local knowledge-base retrieval, ensuring both news timeliness and coverage of private data;
    • Generation layer: A division of labor among narrative writing (the model), chart drawing (visualization libraries), and document layout (PDF assembly);
    • Verification layer: Numerical cross-validation, chart–text consistency checks, and spot fact-checking.

    For enterprises looking to productize these capabilities, mature cloud platforms offer general-purpose building blocks such as model services, containerized execution environments, and object storage. The key is engineering the “plan–execute–verify” loop, not piling up prompt-engineering tricks.

    Conclusion

    The capability boundary of the new generation of LLM agents has expanded from “answering questions” to “delivering results.” Task planning, code execution, tool invocation, and automated document generation form the four key pillars along this pipeline. But real-world testing also reminds us clearly: numerical capability is the model’s weak spot, and reliability comes from engineering, not the model itself—replacing verbal computation with code execution and backstopping uncertainty with verification steps is what makes agent-generated research reports genuinely usable at a professional standard.