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.
- 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
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: falseThe 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
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"}]- pandas
- numpy