Skip to content

Latest commit

 

History

History
76 lines (58 loc) · 2.13 KB

File metadata and controls

76 lines (58 loc) · 2.13 KB

Data Agent

The Data Agent is responsible for processing and transforming data in the atomic agents framework. It supports various input and output formats and can apply transformations to the data.

Features

  • Multiple Input Formats: Support for various input formats including DataFrames, dictionaries, lists, CSV, and JSON
  • Data Transformations: Apply filters, sorting, grouping, and other transformations to the data
  • Configurable Output: Convert data to different formats based on configuration

Usage

The Data Agent can be configured through the configuration file:

data_agent_1:
  type: "data"
  output_format: "dataframe"  # Output format (dataframe, dict, json, csv, list)
  transformations:
    - type: "filter"
      column: "status"
      condition: "equals"
      value: "active"
    - type: "sort"
      column: "created_at"
      ascending: false

Implementation

The Data Agent is implemented in data_agent.py and inherits from the BaseAgent class. It overrides the process method to handle data processing and transformation.

Key methods:

  • process(input_data): Process the input data and apply transformations
  • _convert_to_dataframe(data): Convert input data to a pandas DataFrame
  • _apply_transformations(df): Apply transformations to the DataFrame
  • _convert_from_dataframe(df, output_format): Convert DataFrame to the desired output format

Example

from agents.data-agent.data_agent import DataAgent

# Create a data agent
agent = DataAgent("data_agent_1", {
    "output_format": "dict",
    "transformations": [
        {
            "type": "filter",
            "column": "status",
            "condition": "equals",
            "value": "active"
        }
    ]
})

# Initialize the agent
await agent.initialize()

# Process data
result = await agent.process([
    {"id": 1, "name": "Item 1", "status": "active"},
    {"id": 2, "name": "Item 2", "status": "inactive"},
    {"id": 3, "name": "Item 3", "status": "active"}
])

# Result will be:
# [{"id": 1, "name": "Item 1", "status": "active"},
#  {"id": 3, "name": "Item 3", "status": "active"}]

Dependencies

  • pandas
  • numpy