AI Data Analysis and Automated Research Report Generation in Agent Mode: A Technical Practice

    This article explains why agent mode is better suited to data analysis and research report generation than a single conversational answer, and how a typical agent workflow breaks down into task planning, code execution with tool calls, and multi-step orchestration. It contrasts code-based computation with direct model answering to show how numerical hallucination is avoided, compares code-driven plotting with generative image models, and outlines an end-to-end pipeline from tables to deliverable documents. Developers will also find a set of engineering best practices for keeping analytical output reproducible, traceable, and auditable.

    Why data analysis needs agent mode

    In a conventional chat with a large language model, you hand the model a dataset or a requirement and it produces a textual conclusion straight from its parametric memory. That approach is acceptable for open-ended questions, but its weaknesses are magnified quickly in scenarios such as data analysis and report generation, where precision matters far more.

    The defining difference of agent mode is that the model is no longer a one-shot answerer. Instead, it becomes an executor that can plan autonomously, call tools, run code, and converge on results step by step. Once it receives a task, it decomposes the goal into a set of executable subtasks, then completes them one by one through scripts, information retrieval, chart generation, and document assembly. The final deliverable is a complete report whose data is traceable. For users who need to process tables, compute quantitative factors, or produce illustrated reports, this process-driven mode is the more reliable option.

    Breaking down the core agent workflow

    A mature agent follows a fairly typical chain of stages in an analysis task, which can be grouped into three phases.

    1. Task planning and decomposition

    After receiving an instruction, the agent first produces a to-do list, much like a project manager would. Given a request such as “analyze the inventory percentile of a given asset and produce a daily report,” it breaks the work into steps automatically: read the raw table, compute the percentile according to the factor logic, pull supplementary context from the web or local knowledge sources, call a plotting tool to render charts, and merge text with figures into an exported document. Once the task is split into clear, verifiable nodes, the input and output of each step can be inspected, and failures can be localized precisely.

    2. Code execution and tool calls

    After planning, the agent generates and runs code for each node. Reading structured data, performing statistical calculations, and producing visualizations are all done by scripts that actually execute, rather than by the model “calculating in its head.” This step is where the value of the mode comes from: the scripts really run, real results come back, and those results are passed to the next step.

    1. # Read structured tabular data (deterministic source)
    2. df = load_table("inventory.csv")
    3. # Compute exactly according to business factor logic
    4. # instead of letting the model guess the numbers
    5. quantile_current = compute_quantile(df, column="current_stock")
    6. quantile_base = compute_quantile(df, column="base_diff")
    7. # Call the plotting library to render a chart from the computed results
    8. plot_figure(df, x="current_stock", title="Inventory percentile distribution")
    9. # Merge the chart with the written analysis and export as an illustrated document
    10. render_report(narrative=text, figures=["Inventory percentile distribution"], output="daily.pdf")

    3. Multi-step orchestration and output assembly

    Once the code has run successfully, the agent orchestrates the written analysis, the charts, and the retrieved material together and assembles a single illustrated deliverable. As long as the prompt explicitly asks for automatic chart generation and for the report body and figures to be merged into one document, the agent can complete the full flow end to end, from raw data to finished draft.

    The core insight: why running code beats answering directly

    This is the point developers should weigh most carefully, and it is also the dividing line for judging whether an agent is trustworthy.

    The fundamental weakness of direct answers

    A large language model is, at its core, a probabilistic generator. When it answers a numerical question, it is not performing strict mathematical operations; it is “guessing” the most probable answer based on its training data and the surrounding context. The decimal places and percentage figures it returns are therefore approximations: they may look semantically reasonable while quietly drifting from the true value. Without an intermediate step, this kind of deviation is extremely hard to detect, and once it enters a decision chain it creates real risk.

    The determinism provided by code execution

    Once the computation is handed to code that genuinely runs, the situation is entirely different. Quantiles, ratios, and rankings are produced by deterministic algorithms, and identical inputs always yield identical outputs. The model’s role here shifts from calculator to orchestrator: it understands intent, writes the correct logic, and organizes the flow, while exact numbers are delivered by the code.

    The division of labor can be summarized in one sentence: let the model understand and orchestrate, let the code compute and verify. This is the most effective engineering safeguard against numerical hallucination.

    Data visualization: code-based plotting vs. generative image models

    Chart generation faces the same fork in the road, with a clear gap in professionalism between the two routes.

    • Code-based plotting route: a plotting library in the script computes every coordinate from real data and renders it. Every point on the chart and every bar corresponds to a specific data value, and the axes, legend, and ticks follow statistical conventions. This suits reports that must be verifiable and reproducible.
    • Generative image model route: the image is drawn pixel by pixel by a generation model on a probabilistic basis. It may look more “beautiful,” but the values shown have no strict correspondence to the real data, so neither accuracy nor credibility is sufficient. It cannot support serious analytical conclusions.

    The conclusion is clear: visualization for data analysis must go through the code route. Generative image models are only suitable for decorative illustrations and cannot carry the responsibility of “letting the data speak.”

    End-to-end output: closing the loop from table to document

    Chain these capabilities together and the agent can run a complete automated pipeline:

    1. Data ingestion: read local tables, or pull external information through a retrieval interface;
    2. Precise computation: run scripts according to factor or business logic to obtain deterministic metrics;
    3. Professional charting: call plotting capabilities to generate standards-compliant charts;
    4. Document assembly: lay out text, charts, and data together and export as a deliverable document;
    5. Traceability: intermediate artifacts and results at every step can be retrieved, which supports auditing and review.

    If this pipeline runs on a cloud platform, it can be combined with object storage to keep raw data and finished output, message queues to decouple tasks, and logging services with monitoring and alerting to track the execution status of every step. That turns a one-off script run into a stable, observable, reusable production capability.

    Best practices for engineering implementation

    • Define clear boundaries of responsibility: any computation involving exact numbers, rankings, or ratios must be delegated to code; never allow the model to produce the figures directly.
    • Tighten prompt constraints: explicitly require in the instructions that “computation must be done by running scripts,” “figures must be rendered from data,” and “output must be merged into a structured document,” reducing the room for the model to improvise.
    • Keep the intermediate steps: have the agent output the task list and the result of each step instead of only the final conclusion, so results can be verified and problems diagnosed.
    • Prefer structured data: normalize complex unstructured information into tables or other structured forms before handing it to code, which significantly lowers the error rate.
    • Take the code route for visualization: generate analytical charts with a plotting library so every data point stays traceable, and use image generation models only for non-critical visual embellishment.

    Summary

    The real value of agent mode does not lie in making the model “sound more polished,” but in upgrading it from an unreliable direct answerer into a task executor that can plan, execute, and verify. Understanding the division of labor — the model handles understanding and orchestration, the code handles computation and rendering — is the key to building trustworthy automated analysis pipelines. When precise numbers are guaranteed by deterministic code, professional charts are generated from data, and the deliverable is assembled automatically by the agent, data analysis and report production can genuinely move from “looks correct” to “withstands verification.”