| Crates.io | kowalski-data-agent |
| lib.rs | kowalski-data-agent |
| version | 0.5.0 |
| created_at | 2025-06-28 21:34:28.207783+00 |
| updated_at | 2025-06-28 21:34:28.207783+00 |
| description | Kowalski Date Agent: A Rust-based agent for interacting with Ollama models |
| homepage | https://github.com/yarenty/kowalski |
| repository | https://github.com/yarenty/kowalski |
| max_upload_size | |
| id | 1730144 |
| size | 123,832 |
A specialized AI agent for data analysis and processing tasks, built on top of the Kowalski framework. The Data Agent provides intelligent, conversational data analysis capabilities with support for structured data formats like CSV files.
The Data Agent is a sophisticated AI-powered data analysis tool that combines the power of large language models with specialized data processing tools. It's designed to help users analyze, understand, and extract insights from structured data through natural language conversations.
The Data Agent performs several key functions:
use kowalski_data_agent::DataAgent;
use kowalski_core::config::Config;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the data agent
let config = Config::default();
let mut data_agent = DataAgent::new(config).await?;
// Start a conversation
let conversation_id = data_agent.start_conversation("llama3.2");
// Sample CSV data
let csv_data = r#"name,age,city,salary,department
John Doe,30,New York,75000,Engineering
Jane Smith,28,San Francisco,85000,Marketing
Bob Johnson,35,Chicago,65000,Sales"#;
// Process the CSV data
let analysis_result = data_agent.process_csv(csv_data).await?;
// Get AI analysis
let analysis_prompt = format!(
"Please analyze this CSV data and provide insights:\n\n{}\n\nAnalysis results:\n{}",
csv_data,
serde_json::to_string_pretty(&analysis_result.summary)?
);
let response = data_agent
.chat_with_history(&conversation_id, &analysis_prompt, None)
.await?;
// Process streaming response...
Ok(())
}
use kowalski_core::role::{Audience, Preset, Role};
// Create a specialized role for business analysis
let role = Role::new(
"Business Data Analyst",
"You are an expert business analyst specializing in HR and financial data.",
)
.with_audience(Audience::new(
"HR Manager",
"You are speaking to an HR manager who needs actionable insights for decision-making.",
))
.with_preset(Preset::new(
"Strategic Analysis",
"Focus on strategic implications and actionable recommendations.",
));
// Use the role in analysis
let response = data_agent
.chat_with_history(&conversation_id, &analysis_prompt, Some(role))
.await?;
// Ask specific follow-up questions
let follow_up = "What are the key insights about salary distribution across departments?";
let follow_up_response = data_agent
.chat_with_history(&conversation_id, follow_up, None)
.await?;
The Data Agent is designed with extensibility in mind and can be enhanced in several ways:
// Add support for JSON, XML, Excel files
pub struct ExtendedDataAgent {
agent: DataAgent,
json_tool: JsonTool,
excel_tool: ExcelTool,
xml_tool: XmlTool,
}
// Integrate with statistical libraries
use statrs::statistics::Statistics;
pub struct AdvancedDataAgent {
agent: DataAgent,
correlation_analyzer: CorrelationAnalyzer,
outlier_detector: OutlierDetector,
trend_analyzer: TrendAnalyzer,
}
// Add ML capabilities for predictive analysis
pub struct MLDataAgent {
agent: DataAgent,
prediction_engine: PredictionEngine,
clustering_analyzer: ClusteringAnalyzer,
anomaly_detector: AnomalyDetector,
}
// Generate charts and graphs
pub struct VisualDataAgent {
agent: DataAgent,
chart_generator: ChartGenerator,
plot_creator: PlotCreator,
dashboard_builder: DashboardBuilder,
}
// Connect to databases for live data analysis
pub struct DatabaseDataAgent {
agent: DataAgent,
sql_connector: SqlConnector,
nosql_connector: NoSqlConnector,
query_optimizer: QueryOptimizer,
}
// Handle streaming data sources
pub struct StreamingDataAgent {
agent: DataAgent,
stream_processor: StreamProcessor,
window_analyzer: WindowAnalyzer,
alert_system: AlertSystem,
}
The CSV tool can be easily extended to support other data formats or additional analysis features.
The example successfully:
Running /opt/ml/kowalski/target/debug/examples/csv_analysis
📊 Starting CSV Analysis... Data Agent Conversation ID: 9bed7077-5a3d-4eae-a5f4-5f52efac9c3c
📈 Processing CSV Data:
name,age,city,salary,department
John Doe,30,New York,75000,Engineering
Jane Smith,28,San Francisco,85000,Marketing
Bob Johnson,35,Chicago,65000,Sales
Alice Brown,32,Boston,70000,Engineering
Charlie Wilson,29,Seattle,80000,Engineering
Diana Davis,31,Austin,72000,Marketing
Eve Miller,27,Denver,68000,Sales
Frank Garcia,33,Portland,75000,Engineering
Grace Lee,26,Atlanta,65000,Marketing
Henry Taylor,34,Dallas,78000,Engineering
📊 CSV Analysis Results:
Headers: ["name", "age", "city", "salary", "department"]
Total Rows: 10
Total Columns: 5
Summary: {
"column_count": 5,
"columns": {
"age": {
"average": 30.5,
"count": 10,
"max": 35.0,
"min": 26.0,
"sum": 305.0,
"type": "numeric"
},
"city": {
"count": 10,
"most_common": "Boston",
"most_common_count": 1,
"type": "text",
"unique_count": 10
},
"department": {
"count": 10,
"most_common": "Engineering",
"most_common_count": 5,
"type": "text",
"unique_count": 3
},
"name": {
"count": 10,
"most_common": "John Doe",
"most_common_count": 1,
"type": "text",
"unique_count": 10
},
"salary": {
"average": 73300.0,
"count": 10,
"max": 85000.0,
"min": 65000.0,
"sum": 733000.0,
"type": "numeric"
}
},
"row_count": 10
}
🤖 AI Analysis: Comprehensive Analysis of the CSV Data
After analyzing the provided CSV data, I have identified several key insights and recommendations.
Summary Statistics:
The dataset contains a total of 10 records, each representing an employee's information. The summary statistics for each column are as follows:
Insights:
Based on these summary statistics and the data itself, several insights can be drawn:
Recommendations:
Based on these insights, several recommendations can be made:
Future Analysis:
To further analyze this data, several options can be considered:
By exploring these additional analysis options, further insights can be gained into the organization's dynamics and inform data-driven decisions. ✅ Analysis complete!
🔍 Follow-up Analysis: Salary Distribution Across Departments: Key Insights
Analyzing the salary data reveals some interesting patterns:
Key Observations:
Recommendations:
Future Analysis:
To further explore salary distribution across departments, consider the following:
By analyzing these additional metrics, deeper insights can be gained into the complex relationships between departmental variables and salary distributions.