LLM Agent Mode for Data Analysis: Why Code-Driven Research Reports Beat Text Generation

    This article explains why the agent paradigm makes LLM-powered data analysis and research report generation more reliable than plain text generation. It walks through a typical agent workflow — task planning, tool orchestration, code execution, and result integration — shows why report charts should come from plotting libraries rather than image generation models, and includes a representative Python snippet for producing a chart-backed report. It also covers the inherent limits of letting an LLM do arithmetic directly, plus practical safeguards for exact computation, verifiable intermediate steps, and cross-checking results.

    From Text Generation to Agent Mode: A Step Change in Data Analysis Reliability

    Conventional interaction with a large language model is essentially probabilistic generation at the language level: the model predicts the most likely output one token at a time, based on its training corpus and the current context. This mechanism works very well for writing prose, polishing phrasing, and organizing ideas. The moment you move into work that demands exact numerical computation and structured data processing, however, the weakness becomes obvious. The model does not actually execute arithmetic — it recalls and infers a result that merely looks plausible.

    Agent mode changes this paradigm. Instead of having the model conjure an answer out of thin air, it casts the model in the role of a programmer: the model breaks the task down on its own, writes code, calls a runtime environment to execute that code, and then returns the real computation result as the answer. For precision-sensitive work such as quantitative analysis, financial modeling, and report parsing, “let the code do the math” is far more reliable than “let the language model guess.” It also removes, at the source, the memory bias and numerical hallucination that models exhibit on complex data.

    The Core Agent Workflow

    A mature agent workflow follows an execution logic that closely mirrors mainstream AI coding assistants, and it typically consists of the following stages:

    1. Task planning: once it receives a goal, the agent first creates a to-do list on its own, breaking “read data — clean and compute — retrieve information — visualize — compile the draft” into executable sub-steps.
    2. Tool orchestration: for each sub-task it selects and invokes the appropriate tool — running a script to read a spreadsheet, searching the web, or recalling material from a local knowledge base.
    3. Code execution: in a controlled runtime it actually runs a scripting language such as Python, reads structured data, and performs exact computations such as quantiles, differences, and statistical measures.
    4. Result integration: it merges the computation output, charts, and written explanations into a finished document that combines text and figures.

    This “plan first, execute next, integrate last” loop makes complex analysis tasks stably reproducible, rather than a one-off, untraceable piece of text.

    Code-Driven Visualization: The Dividing Line Between Precision and Professionalism

    When you generate an analysis report, charts are indispensable. Here is a key distinction that is easy to overlook: should the figures be produced by a plotting library, or by an image generation model?

    Image generation models are, at their core, probability-based pixel generators. The curves, axes, and numbers they draw are only pixel arrangements that “look like a chart” — none of their data points correspond to real computation results, so both professionalism and accuracy fall short.

    Code-driven plotting works entirely differently: every point and every curve in the figure is derived from concrete data through deterministic computation. When the prompt explicitly requires that the agent “call a plotting library to generate the figures automatically and merge text and images into the report,” the agent draws strictly according to the data logic or the factor source code, ensuring each chart maps one-to-one to the underlying data. For finance, scientific research, and similar domains, this verifiable and reproducible form of visualization cannot be replaced by image generation.

    How an Automated Research Report Actually Runs

    Chain these capabilities together and you get a text-and-chart research report from a single sentence. A representative execution snippet:

    1. # Read structured tabular data
    2. data = load_table("data.xlsx")
    3. # Perform exact computation with deterministic code instead of having the model infer values
    4. current_quantile = percentile_rank(data["inventory"]) # inventory quantile as of today
    5. basis_quantile = percentile_rank(data["basis"]) # basis quantile
    6. # Code-driven plotting: every point is derived from real data
    7. chart = plot_series(data["date"], data["inventory"], highlight_last=True)
    8. chart.save("chart.png")
    9. # Combine the computed conclusions and the chart into a text-and-figure report
    10. report = f"Current inventory quantile: {current_quantile:.1%}; basis quantile: {basis_quantile:.1%}"
    11. build_report(report, chart, output="research_report.pdf")

    The point worth stressing is this: under agent mode, metrics such as quantiles come from deterministic computation in code, so the results are exact and reproducible, rather than approximate guesses about the numbers. This is the essential difference between “computing with code” and “having the model guess.”

    Knowing the Limits: Why LLMs Struggle with Exact Arithmetic

    Agent mode substantially improves reliability, but one fact must be kept clearly in mind: large models are simply not good at precise decimal arithmetic. When a problem is handed straight to the model’s language layer, it produces an “approximate” answer based on training data and context rather than strictly following mathematical rules. In quantiles, percentages, and financial reconciliation, this can yield conclusions that look reasonable but are actually off.

    So the best practice boils down to the following:

    • Anything involving exact numerical computation should always be handed to code execution, never done as mental arithmetic by the model;
    • For key metrics, require the agent to output the intermediate computation steps and the data sources so they can be verified;
    • Hand deterministic steps such as visualization and document generation to the toolchain, and let the model focus on task decomposition and logical organization;
    • Add cross-checks on final results — for example, recompute a key quantile two independent ways and confirm the two values agree.

    Conclusion

    The shift from text generation to agent mode is a fundamental change in the value large models bring to professional analysis: their role has moved from “a language model that guesses answers” to “an analysis assistant that writes code, executes it, and produces reproducible results.” For developers, the real skill is dividing responsibilities sensibly — the model understands intent and organizes logic, the code handles exact computation and visualization, and the toolchain delivers stable output. Holding that boundary is what lets you land large models reliably in quantitative analysis, financial research reports, and an even wider range of data-driven decision-making scenarios.