AI Agent-Driven Data Analysis and Automated Research Report Generation: A Practical Implementation Guide

    This article explains why data analysis tasks benefit from an agent execution model rather than a purely conversational one, and how to build an automated pipeline that turns raw data into illustrated research reports. It covers the difference between code-based and generative-model charting, the task-list-driven agent workflow, the full chain from data ingestion to PDF report assembly, the limits of large language models when asked to compute values directly, and the engineering practices needed to keep output reproducible and auditable.

    1. From “Conversation” to “Execution”: Why Data Analysis Needs an Agent Mode

    Conversational LLMs have a structural weakness when they are asked to handle data analysis: they can describe data, but they cannot operate on it. Hand a complex spreadsheet to a purely conversational model and it will often lean on its training corpus to produce a conclusion that “looks reasonable” while diverging badly from what the data actually says. In a discipline where precision and reproducibility matter, that appearance of correctness is the biggest risk of all.

    The core value of the agent mode is that it turns the model from an answerer into an executor. Instead of only generating text, the agent can decompose a task on its own, write and run code, call external tools, read local or online data, and finally emit structured files. For data analysis this shift is fundamental: conclusions no longer come from the model’s memory or guesses, but from computations that actually ran.

    2. Code-Based Agents vs. Chart-Generating Models: Where Accuracy Divides

    One of the key decisions in data analysis is whether to chart with code or with a generative model. Their underlying logic is completely different:

    • Code-based charting: every point and every curve is the result of a deterministic computation on concrete data. Coordinates, scales, and error ranges can all be traced back to the source data, which means they can be verified, reproduced, and audited.
    • Generative-model charting: this is essentially probabilistic pixel synthesis. It looks like a chart, but the numbers are inferred by the model from probability, and it carries no mathematical guarantee of accuracy.

    In professional settings such as finance, accounting, and supply chain management, a chart that is attractive but numerically wrong is not merely useless — it can mislead decisions. Professional data visualization should therefore be handed to a code-writing agent, not a chart-drawing model. Here the agent plays the role of a programmer: it processes the data by writing code and renders the chart from real computed results.

    A sketch of what data analysis and plotting code looks like:

    1. # Load structured data (tabular processing)
    2. data = read_table("inventory.csv")
    3. # Compute quantiles with deterministic functions; results are reproducible and verifiable
    4. current_quantile = quantile(data["current_stock"], 0.25)
    5. base_quantile = quantile(data["base_diff"], 0.25)
    6. # Use the plotting capability to render the data; every point comes from the computation above
    7. draw_bar_chart(
    8. labels=["Current Stock Quantile", "Current Basis-Diff Quantile"],
    9. values=[current_quantile, base_quantile],
    10. title="Comparison of Quantile Results",
    11. )
    12. save_figure("comparison.png", dpi=150)

    3. The Typical Agent Workflow: Execution Driven by a Task List

    The dominant agent execution paradigm today has converged strongly, and it mirrors how coding assistants operate: the agent first creates a task list (a TODO list), then works through the items one by one. A typical flow looks like this:

    1. Parse the request and break it into executable subtasks.
    2. Generate the task list, defining the goal and deliverable for each step.
    3. Write and run code to load data and perform statistical analysis.
    4. Supplement context by searching the web or querying a local knowledge base.
    5. Call the plotting capability to produce figures.
    6. Assemble text and figures into the final deliverable.

    A conceptual agent execution loop:

    1. while not all_tasks_done:
    2. task = pick_next_task(todo_list)
    3. match task.type:
    4. case "load_data": run_code(task.script) # Load the data
    5. case "compute": result = run_code(task.script) # Compute metrics
    6. case "search": facts = search_web(task.query) # Retrieve background information
    7. case "plot": chart = run_code(task.script) # Generate the chart
    8. update_todo_list(task, result)

    Because every step rests on real execution rather than model recall, all intermediate artifacts — data tables, computed results, charts — can be inspected, which makes problems easy to locate.

    4. From Data to Illustrated Research Reports: Breaking Down the Automated Chain

    Take the example of producing a daily quantitative report with both text and charts. As long as the prompt states the output requirement clearly — for instance, “automatically call the plotting capability to generate figures and merge the text with the figures into a PDF document” — the agent can complete the whole chain end to end:

    • Data ingestion: read structured data such as inventory levels and basis differentials.
    • Metric computation: run deterministic calculations following the logic in the code to derive quantiles, means, volatility, and similar metrics.
    • Visualization: generate figures from the computed results.
    • Content assembly: write the analytical narrative using information retrieved along the way.
    • Document synthesis: lay out and merge text and charts, then export a standard PDF report.

    Compared with manual production, the advantage of this chain is standardization and reusability: the same pipeline triggered on a daily schedule yields reports with consistent formatting and consistent definitions, sharply reducing repetitive work.

    5. The Limits of LLM Arithmetic: Why You Shouldn’t Let the Model “Compute” Quantiles in Its Head

    One point deserves particular caution: an LLM is fundamentally a probabilistic next-token predictor, not a calculation engine. When you ask it directly to “compute” a quantile or a decimal result, it does not strictly apply mathematical rules — it produces an approximation based on training data and context.

    An intuitive illustration: give the same dataset to several models and ask each one to “estimate” the stock quantile and the basis-differential quantile, and the answers will typically disagree — some report values in the low twenties as a percentage, others land closer to thirty or higher. That inconsistency is precisely the evidence that relying on a model’s memory or mental arithmetic for exact numbers is unreliable; complex computation is where hallucination thrives.

    The correct approach follows the principle of separating reasoning from computation:

    • Let the LLM handle understanding and orchestration: reading the requirement, breaking down tasks, writing code, and interpreting results.
    • Let deterministic programs handle exact computation: an interpreter executes mathematical operations that a human can review.

    With this division, every number in the final output comes from real computation rather than the model’s approximation, so both accuracy and professionalism are protected.

    6. Engineering Recommendations: Making Agent Output Reproducible and Verifiable

    To use agents reliably in an enterprise setting for data analysis and report generation, focus on the following practices:

    1. Isolate the execution environment: run the code the agent generates inside a controlled sandbox, with restricted file and network access, so a mistake cannot affect production systems.
    2. Retain intermediate artifacts: record data tables, computation steps, and charts in full, so results can be traced and audited.
    3. Cross-check critical numbers: for key metrics, re-verify the agent’s output with an independent script to confirm the numbers match the source data.
    4. Standardize the delivery format: use a unified report template and layout so that batch output stays consistent.
    5. Invest in supporting infrastructure: general-purpose cloud capabilities — container platforms to host the agent runtime, object storage to archive reports and chart artifacts, message queues to schedule recurring jobs, and logging plus monitoring with alerting to track run status and anomalies — provide a stable foundation for this kind of automated pipeline. Platforms such as Baidu AI Cloud offer these generic capabilities, which can underpin such automation.

    7. Conclusion

    The agent mode is pushing LLMs from being a conversation tool toward being a productivity tool. In areas such as data analysis and report generation, where precision is paramount, real value does not lie in how well the model can talk, but in whether it can write code, run computations, and deliver results. Understanding the two principles — that a code-writing agent outperforms a chart-drawing model, and that reasoning should be separated from computation — and then making the engineering reproducible and verifiable, is the key to building a dependable automated analysis solution.