Table of Contents

πŸ‘‰ Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/agents/data_analyst_agent

Local Data Analyst Agent for C# .NET Applications


🎯 Purpose of the Demo

Local Data Analyst Agent demonstrates how to use LM-Kit.NET to build an AI data analyst that reads, parses, and analyzes your data files entirely on local hardware. The agent combines ReAct planning with built-in tools for file I/O, data parsing, and statistical computation.

The sample shows how to:

  • Build an agent with ReAct planning using Agent.CreateBuilder().
  • Register built-in tools from multiple categories (Data, Numeric, IO) via BuiltInTools.
  • Use built-in Data tools (CSV, JSON, XML parsing) for structured data processing.
  • Use built-in Numeric tools (calculator, statistics) for computation.
  • Use built-in IO tools (file read, directory list) for local data access.
  • Execute agent tasks with AgentExecutor and stream color-coded output.
  • Conduct multi-turn analysis where the agent remembers context from previous queries.

Why a Local Data Analyst with LM-Kit.NET?

  • Data never leaves your machine: analyze sensitive financial, HR, or customer data without cloud exposure.
  • Built-in tools ecosystem: demonstrates the Data, Numeric, and IO tool categories working together.
  • Natural language queries: ask questions about your data in plain English.
  • Systematic analysis: ReAct planning ensures thorough, step-by-step analysis.

πŸ‘₯ Who Should Use This Demo

  • Business Analysts: explore datasets with natural language instead of writing SQL or Python.
  • Data Scientists: quick local data exploration without spinning up notebooks.
  • Finance Teams: analyze sensitive financial data with full data sovereignty.
  • HR Departments: process employee data locally without compliance concerns.
  • Developers: learn how to combine built-in tools from multiple categories in a single agent.

πŸš€ What Problem It Solves

  • Data privacy: analyze confidential data without uploading to cloud AI services.
  • Technical barrier: non-technical users can query data with natural language.
  • Quick exploration: get insights from CSV/JSON files without writing code.
  • Tool ecosystem demo: showcases built-in tools from three categories working together.
  • Reproducible analysis: the agent explains its methodology and shows supporting numbers.

πŸ’» Demo Application Overview

Console app that:

  • Lets you choose from multiple models optimized for tool-calling and reasoning.
  • Downloads models if needed, with live progress updates.
  • Creates an Agent with ReAct planning and registered built-in tools.
  • Enters an interactive analysis loop where you can:
    • Point the agent at local data files (CSV, JSON, XML, text).
    • Ask analytical questions in natural language.
    • Watch the agent reason through analyses (blue), call tools (magenta), and present results (white).
    • Ask follow-up questions that build on previous analysis.
  • Displays execution statistics (tool calls, duration, inferences).
  • Loops until you type q.

Key Features

  • Built-In Tools: File I/O, CSV/JSON/XML parsing, calculator, statistics.
  • ReAct Planning: Systematic data exploration and analysis.
  • Multi-Turn Context: Ask follow-up questions about the same data.
  • Color-Coded Output: Reasoning (blue), tool calls (magenta), results (white).
  • Zero Configuration: No API keys, no cloud accounts, no external dependencies.

πŸ—οΈ Architecture

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚              User Query                          β”‚
  β”‚  "Analyze sales.csv and find the top regions"    β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚           ReAct Planning Loop                    β”‚
  β”‚                                                  β”‚
  β”‚   Think β†’ Act β†’ Observe β†’ Think β†’ ...           β”‚
  β”‚                                                  β”‚
  β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
  β”‚   β”‚ IO Tools β”‚  β”‚Data Toolsβ”‚  β”‚ Numeric  β”‚     β”‚
  β”‚   β”‚          β”‚  β”‚          β”‚  β”‚  Tools   β”‚     β”‚
  β”‚   β”‚ fs_read  β”‚  β”‚csv_parse β”‚  β”‚calculatorβ”‚     β”‚
  β”‚   β”‚ fs_list  β”‚  β”‚json_parseβ”‚  β”‚statisticsβ”‚     β”‚
  β”‚   β”‚          β”‚  β”‚xml_parse β”‚  β”‚          β”‚     β”‚
  β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
  β”‚                                                  β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β–Ό
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚            Structured Insights                   β”‚
  β”‚  Key metrics, trends, anomalies, and summary    β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Built-In Tools

Tool Category Description
filesystem_read IO Read file contents from local disk
filesystem_list IO List directory contents
csv_parse Data Parse CSV into structured rows and columns
json_parse Data Parse JSON documents
xml_parse Data Parse XML documents
calculator Numeric Arithmetic, percentages, ratios
statistics Numeric Descriptive statistics (mean, median, min, max, std dev)

Agent Configuration

using LMKit.Agents;
using LMKit.Agents.Tools.BuiltIn;
using LMKit.Model;

LM model = LM.LoadFromModelID("qwen3:8b");

var agent = Agent.CreateBuilder(model)
    .WithPersona("Data Analyst Assistant")
    .WithInstruction("You are an expert data analyst...")
    .WithPlanning(PlanningStrategy.ReAct)
    .WithTools(tools =>
    {
        // IO tools: read files and list directories
        tools.Register(BuiltInTools.FileSystemRead);
        tools.Register(BuiltInTools.FileSystemList);
        // Data tools: parse structured formats
        tools.Register(BuiltInTools.CsvParse);
        tools.Register(BuiltInTools.JsonParse);
        tools.Register(BuiltInTools.XmlParse);
        // Numeric tools: compute and analyze
        tools.Register(BuiltInTools.Calculator);
        tools.Register(BuiltInTools.Statistics);
    })
    .WithMaxIterations(15)
    .Build();

var executor = new AgentExecutor();
var result = executor.Execute(agent, "Analyze sales.csv", cancellationToken);

Example Use Cases

  • Sales analysis: "Read sales_q4.csv and tell me which region grew the fastest"
  • Financial data: "Parse budget.json and compute the total expenses by department"
  • Data discovery: "List all CSV files in C:\data and describe what each contains"
  • Statistical analysis: "Compute mean, median, and standard deviation of response times in metrics.csv"
  • Comparative analysis: "Compare this quarter's revenue numbers against last quarter from the two CSV files"

βš™οΈ Getting Started

Prerequisites

  • .NET 8.0 or later
  • Sufficient VRAM for the selected model (6-18 GB depending on model choice)
  • Data files to analyze (CSV, JSON, XML, or text)

Download

git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/agents/data_analyst_agent

Run

dotnet build
dotnet run

Then:

  1. Select a model from the menu, or paste a custom model URI.
  2. Wait for the model to download (first run) and load.
  3. Enter a data analysis query (include file paths).
  4. Watch the agent reason, read files, parse data, and compute in real-time.
  5. Receive structured insights with supporting metrics.
  6. Type q to exit.

πŸ”§ Troubleshooting

  • "File not found" errors

    • Use full absolute paths (e.g., C:\data\file.csv).
    • Check file permissions.
  • Agent doesn't parse data correctly

    • Ensure CSV files use standard delimiters (comma, semicolon).
    • For complex JSON, try a larger model (14B+).
  • Slow analysis with large files

    • Large files may exceed the model's context window.
    • Consider splitting large datasets before analysis.
    • Use a model with longer context (GPT OSS 20B supports 131k tokens).
  • Inaccurate calculations

    • The agent uses built-in calculator/statistics tools for exact computation.
    • If results seem wrong, check that the agent is using the right columns/fields.

πŸš€ Extend the Demo

  • Add spreadsheet support: register built-in tools for XLSX parsing.
  • Visualization: export results to CSV for charting in Excel or other tools.
  • Scheduled analysis: run automated daily/weekly reports on data files.
  • Database connectivity: combine with Qdrant or other connectors for vector-augmented analysis.
  • Permission policies: restrict file access to specific directories using ToolPermissionPolicy.
  • Report generation: pipe analysis results into a Content Creation Pipeline for formatted reports.

πŸ“š Additional Resources

Share