L2 Hub
Pontus
agents
Data Analysis with Chart

L2 Construct: data_analysis_with_chart

data ai agent

Description

Data Analysis With Charts Agent is an AI-powered tool for performing data analysis tasks on tabular data to generate a plotted chart.

It takes a task description and a set of input tables, and returns the processed result table, a plotted chart, and the steps (iterations) taken to achieve the result.

Input:

  • task: A string describing the data analysis task to be performed.
  • tables: A map of table names to Table structures, representing the input data.

Output:

  • success: A boolean indicating whether the operation was successful.
  • iterations: An array of steps taken to achieve the result.
  • result_table: The final processed Table structure after performing the data analysis task.
  • chart_output: A byte array containing the plotted chart in PNG form.

The agent uses to break down complex data analysis tasks into a series of simpler operations, using tools like Join, Filter, GroupBy, Chart, and Finish to manipulate the data and create charts.

L2 Data

  1. Provider: pontus
  2. Module: agents
  3. Action: data_analysis_with_chart

Example Step

{
  "name": "insert-your-step-name",
  "type": "l2",
  "l2_data": {
    "provider": "pontus",
    "module": "agents",
    "action": "data_analysis_with_chart"
  }
}
 

Input

Example

{
  "task": "Join sales and product tables, then calculate total sales by department and create a bar chart",
  "tables": [
    {
      "name": "sales",
      "description": "All sales for the store",
      "headers": ["date", "product_id", "sale_amount"],
      "rows": [["2023-05-01", "P001", 100.5], ["2023-05-02", "P002", 200.75]]
    },
    {
      "name": "products",
      "description": "Available products for purchase in the store by department",
      "headers": ["product_id", "product_name", "department"],
      "rows": [
        ["P001", "Widget A", "Electronics"],
        ["P002", "Gadget B", "Electronics"]
      ]
    }
  ]
}
 

Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pontus.bpa/pkgs/l2/pontus/agents/charting-agent-input",
  "$ref": "#/$defs/ChartingAgentInput",
  "$defs": {
    "ChartingAgentInput": {
      "properties": {
        "task": {
          "type": "string"
        },
        "tables": {
          "items": {
            "$ref": "#/$defs/Table"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["task", "tables"]
    },
    "Table": {
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "headers": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "rows": {
          "items": {
            "items": true,
            "type": "array"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["headers", "rows"]
    }
  }
}
 

Output

Example

{
  "success": true,
  "iterations": [
    {
      "user_input": "Task: Join the sales and products tables, group by category and date, sum the sales, and create a line chart of total sales over time for each category.",
      "observation": "We need to join tables, group data, and then create a chart.",
      "thought": "Let's start by joining the sales and products tables.",
      "action": {
        "tool": "Join",
        "input": "{\"left_dataframe_name\": \"sales\", \"right_dataframe_name\": \"products\", \"left_on\": \"product_id\", \"right_on\": \"product_id\", \"how\": \"inner\"}"
      }
    },
    {
      "user_input": "Action1[{\"columns\":[\"date\",\"product_id\",\"sale_amount\",\"customer_id\",\"product_name\",\"category\"],\"types\":[\"string\",\"string\",\"float64\",\"string\",\"string\",\"string\"],\"records\":[[\"2023-05-01\",\"P001\",100.50,\"C001\",\"Widget A\",\"Electronics\"]...]]",
      "observation": "We have successfully joined the sales and products data.",
      "thought": "Now we need to group by category and date, and sum the sales.",
      "action": {
        "tool": "GroupBy",
        "input": "{\"dataframe_name\": \"Action1\", \"group_by_columns\": [\"category\", \"date\"], \"aggregation_columns\": [\"sale_amount\"], \"aggregation_functions\": [\"sum\"]}"
      }
    },
    {
      "user_input": "Action2[{\"columns\":[\"category\",\"date\",\"sale_amount_SUM\"],\"types\":[\"string\",\"string\",\"float64\"],\"records\":[[\"Electronics\",\"2023-05-01\",500.75],[\"Clothing\",\"2023-05-01\",300.25]...]]",
      "observation": "We have grouped the data by category and date, and calculated the total sales.",
      "thought": "Now we can create a line chart of total sales over time for each category.",
      "action": {
        "tool": "CreateChart",
        "input": "{\"dataframe_name\": \"Action2\", \"chart_type\": \"line\", \"domain_column_name\": \"date\", \"range_column_name\": \"sale_amount_SUM\"}"
      }
    },
    {
      "user_input": "Action3[byte array representing an image]",
      "observation": "We have successfully created a line chart of total sales over time for each category.",
      "thought": "The task is complete. We should finish the process and return the chart.",
      "action": {
        "tool": "Finish",
        "input": "{\"final_dataframe_name\": \"Action2\", \"chart_name\": \"Action3\"}"
      }
    }
  ],
  "result_table": {
    "headers": ["department", "total_sales"],
    "rows": [["Electronics", 301.25]]
  },
  "chart_output": "AQID"
}
 

Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pontus.bpa/pkgs/l2/pontus/agents/charting-agent-output",
  "$ref": "#/$defs/ChartingAgentOutput",
  "$defs": {
    "Action": {
      "properties": {
        "tool": {
          "type": "string"
        },
        "input": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["tool", "input"]
    },
    "ChartingAgentOutput": {
      "properties": {
        "success": {
          "type": "boolean"
        },
        "iterations": {
          "items": {
            "$ref": "#/$defs/ReactIteration"
          },
          "type": "array"
        },
        "result_table": {
          "$ref": "#/$defs/Table"
        },
        "chart_output": {
          "type": "string",
          "contentEncoding": "base64"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["success", "iterations", "result_table", "chart_output"]
    },
    "ReactIteration": {
      "properties": {
        "user_input": {
          "type": "string"
        },
        "observation": {
          "type": "string"
        },
        "thought": {
          "type": "string"
        },
        "action": {
          "$ref": "#/$defs/Action"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["user_input", "observation", "thought", "action"]
    },
    "Table": {
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "headers": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "rows": {
          "items": {
            "items": true,
            "type": "array"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": ["headers", "rows"]
    }
  }
}