> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brighthive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Analysis Agent

> The Analyst Agent queries your data, runs statistical analysis, and generates insights — all from natural language questions.

## Overview

The Analyst Agent lets you explore your data through conversation. Ask a question in plain English, and it executes code against your data in a secure **AWS Bedrock sandbox**, performs statistical analysis, and delivers insights — often accompanied by interactive visualizations you can explore further.

## What You Can Ask

* *"What are our top 10 customers by revenue this quarter?"*
* *"Find correlation between marketing spend and revenue growth"*
* *"Identify seasonal trends in sales data over the past 2 years"*
* *"Segment customers based on purchasing behavior"*
* *"Compare this month's performance to last month"*
* *"Detect anomalies in transaction patterns"*

## How It Works

```mermaid theme={null}
graph TD
    A[Your Question] --> B[BrightAgent]
    B -->|Delegates task| C[Analyst Agent]
    C --> D[Reads Data Assets from S3]
    D --> E[Executes Code in Bedrock Sandbox]
    E --> F{Satisfied with Results?}
    F -->|No| E
    F -->|Yes| G[Generate Visualization]
    G --> H[Return Insights + Chart]
```

1. **BrightAgent delegates** — The orchestrator identifies an analysis task and passes your question along with discovered data assets to the Analyst Agent.
2. **Reads your data** — The agent accesses data files from your organization's S3 storage, loading them into a secure analysis environment.
3. **Executes analysis** — Runs Python code in an **AWS Bedrock Code Interpreter** — a fully isolated sandbox with no access beyond your data.
4. **Iterates until satisfied** — The agent evaluates its own results and refines the analysis if needed, typically completing in 3–5 iterations.
5. **Generates visualizations** — When a chart would help, it creates an interactive **Vega-Lite** visualization rendered directly in BrightAgent.
6. **Delivers insights** — Returns a clear summary with key findings, supporting data, and any charts produced.

## Capabilities

<CardGroup cols={2}>
  <Card title="Secure Code Execution" icon="shield-check">
    All analysis runs in an **AWS Bedrock sandbox** — fully isolated, stateless, and time-limited. Your data never leaves the secure environment.
  </Card>

  <Card title="Statistical Analysis" icon="chart-simple">
    Descriptive statistics, distributions, hypothesis testing, correlation analysis, and anomaly detection — all from natural language.
  </Card>

  <Card title="Trend Detection" icon="arrow-trend-up">
    Identifies patterns, seasonality, and changes over time. Compares periods, segments data, and highlights what's changing.
  </Card>

  <Card title="Interactive Visualizations" icon="chart-line">
    Auto-generates **Vega-Lite** charts with tooltips, responsive layouts, and intelligent chart type selection based on your data.
  </Card>
</CardGroup>

## Visualization Pipeline

When your question calls for a chart, the Analyst Agent coordinates with a two-phase visualization process:

```mermaid theme={null}
graph TD
    A[Analysis Results] --> B[Data Characteristics Analyzed]
    B --> C["Phase 1: Plan — Select chart type + columns"]
    C --> D["Phase 2: Generate — Create Vega-Lite spec"]
    D --> E[Validate Against Schema]
    E -->|Invalid| D
    E -->|Valid| F[Interactive Chart Rendered]
```

The agent automatically selects the best chart type based on your data:

| Data Pattern          | Chart Type            |
| --------------------- | --------------------- |
| Categories + numbers  | Bar chart             |
| Time series           | Line or area chart    |
| Two numeric variables | Scatter plot          |
| Part-of-whole         | Arc / pie chart       |
| Distributions         | Histogram or box plot |
| Correlation matrices  | Heatmap               |

Charts include tooltips, responsive layouts, and proper formatting — rendered directly in the BrightAgent interface using a **ChartViewer** component.

## Data Access

The Analyst Agent works with data that's already been discovered and prepared:

* **S3 files** — Downloads data from your organization's S3 storage using secure, scoped access
* **Retrieval Agent output** — Receives query results that the Retrieval Agent has already fetched from your warehouse
* **Filesystem** — Reads and writes files in a thread-scoped virtual filesystem backed by S3

The agent does **not** query your warehouse directly — that's the Retrieval Agent's job. The Analyst focuses purely on analysis and insight generation.

## Works With Other Agents

The Analyst Agent frequently collaborates with other agents:

* **Retrieval Agent** finds the right data assets and executes SQL queries before analysis begins.
* **Visualization Agent** handles complex or standalone chart requests.
* **Governance Agent** ensures data access follows your organization's policies.

<Callout type="info">
  The Analyst Agent is part of the [BrightAgent architecture](/brightagent/architecture). See [capabilities](/brightagent/capabilities) for the full list of what BrightAgent can do.
</Callout>
