Skip to content

Analytics Agent

The Analytics Agent is designed to handle data analytics tasks by searching for a data product, constructing and executing a query, and/or generating a chart to address a user’s request.

The agent follows this workflow:

  1. Receives a natural language question from the user
  2. Uses the Get Data Schema tool to understand available tables and columns
  3. Generates and executes SQL queries using the SQL Execution tool
  4. Analyzes results and may refine queries as needed
  5. If visualization is requested, generates a chart using the Chart Generation tool
  6. Returns the final consolidated results

Required:

  • message (string): The natural language question or request to send to the agent
  • marketplace_id (string): The ID of the marketplace to search for data products

The agent produces a series of thinking, tool call, tool return, and text blocks as it works through the user request. The final message, assuming no errors, is a string which addresses the user’s request. The chart(s) generated are available as html and json vega configs with successful charting tool return blocks.

The agent is configured with 4 tools:

Searches for data products in the specified marketplace relevant to the user’s question.

Key parameters:

  • marketplace_id: The marketplace to search, which is passed to the tool based from the input parameters.

Retrieves the schema for tables in the data product. Optionally supports semantic search of sample values.

Key parameters:

  • data_product_id: The data product to get schema for
  • query: Optional semantic search query for sample values

Executes SQL queries against the data product’s database. The tool automatically handles result serialization and may limit rows/columns for very large results.

Key parameters:

  • data_product_id: The data product to query
  • sql: The SQL query to execute
  • result_table_name: A semantic name for the result table

Generates visualizations using Altair and Python. Takes a SQL query and Python code snippet to create interactive charts.

Key parameters:

  • data_product_id: The data product to query
  • sql: SQL query to generate data for the chart
  • chart_code_snippet: Python function using Altair to create the chart
  • image_title: Title for the chart
  • The agent always uses result tables from executed queries to answer questions (never synthesizes data)
  • For complex questions, the agent may execute multiple queries to explore the dataset or obtain intermediate results
  • When generating charts, it returns the first reasonable visualization without excessive iteration
  • Charts are generated using Altair and returned as JSON representations