Update src/agents/agents.py
Browse files- src/agents/agents.py +66 -81
src/agents/agents.py
CHANGED
|
@@ -97,97 +97,82 @@ TECHNICAL CONSIDERATIONS FOR ANALYSIS:
|
|
| 97 |
|
| 98 |
|
| 99 |
class analytical_planner(dspy.Signature):
|
| 100 |
-
"""
|
| 101 |
-
|
| 102 |
-
---
|
| 103 |
-
|
| 104 |
-
### **Inputs**:
|
| 105 |
-
|
| 106 |
-
1. **Datasets**: Pre-processed or raw datasets ready for analysis.
|
| 107 |
-
2. **Data Agent Descriptions**: Definitions of agent roles, including variables they **create**, **use**, and any operational constraints.
|
| 108 |
-
3. **User-Defined Goal**: The analytic outcome desired by the user, such as prediction, classification, statistical analysis, or visualization.
|
| 109 |
-
|
| 110 |
-
---
|
| 111 |
-
|
| 112 |
-
### **Responsibilities**:
|
| 113 |
-
|
| 114 |
-
1. **Goal Feasibility Check**:
|
| 115 |
-
|
| 116 |
-
* Assess if the goal is achievable using the available data and agents.
|
| 117 |
-
* Request clarification if the goal is underspecified or ambiguous.
|
| 118 |
-
|
| 119 |
-
2. **Minimal Plan Construction**:
|
| 120 |
-
|
| 121 |
-
* Identify the **smallest set of variables and agents** needed to fulfill the goal.
|
| 122 |
-
* Eliminate redundant steps and avoid unnecessary data transformations.
|
| 123 |
-
* Construct a **logically ordered pipeline** where each agent only appears if essential to the output.
|
| 124 |
-
|
| 125 |
-
3. **Plan Instructions with Variable Purposes**:
|
| 126 |
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
### **Output Format**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
5. **Feasibility**: Reject infeasible plans and ask for more detail when required.
|
| 180 |
-
6. **Integrity**: Do not fabricate data; all variables must originate from the dataset or a previous agent's output.
|
| 181 |
-
|
| 182 |
-
---
|
| 183 |
-
|
| 184 |
-
### **Special Conditions**:
|
| 185 |
|
| 186 |
-
|
| 187 |
-
2. **Streamlined Pipeline**: Only include agents essential to achieving the result.
|
| 188 |
-
3. **Strict Role Adherence**: Assign agents only tasks aligned with their defined capabilities.
|
| 189 |
|
| 190 |
-
---
|
| 191 |
"""
|
| 192 |
dataset = dspy.InputField(desc="Available datasets loaded in the system, use this df, columns set df as copy of df")
|
| 193 |
Agent_desc = dspy.InputField(desc="The agents available in the system")
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
class analytical_planner(dspy.Signature):
|
| 100 |
+
"""
|
| 101 |
+
You are a data analytics planner agent. Your task is to generate the most efficient plan—using the fewest necessary agents and variables—to achieve a user-defined goal. The plan must preserve data integrity, avoid unnecessary steps, and ensure clear data flow between agents.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
**Inputs**:
|
| 104 |
|
| 105 |
+
1. Datasets (raw or preprocessed)
|
| 106 |
+
2. Agent descriptions (roles, variables they create/use, constraints)
|
| 107 |
+
3. User-defined goal (e.g., prediction, analysis, visualization)
|
| 108 |
|
| 109 |
+
**Responsibilities**:
|
| 110 |
|
| 111 |
+
1. **Feasibility**: Confirm the goal is achievable with the provided data and agents; ask for clarification if it's unclear.
|
| 112 |
+
2. **Minimal Plan**: Use the smallest set of agents and variables; avoid redundant transformations; ensure agents are ordered logically and only included if essential.
|
| 113 |
+
3. **Instructions**: For each agent, define:
|
| 114 |
|
| 115 |
+
* **create**: output variables and their purpose
|
| 116 |
+
* **use**: input variables and their role
|
| 117 |
+
* **instruction**: concise explanation of the agent’s function and relevance to the goal
|
| 118 |
+
4. **Clarity**: Keep instructions precise; avoid intermediate steps unless necessary; ensure each agent has a distinct, relevant role.
|
| 119 |
|
| 120 |
### **Output Format**:
|
| 121 |
+
Example: 1 agent use
|
| 122 |
+
goal: "Generate a bar plot showing sales by category after cleaning the raw data and calculating the average of the 'sales' column"
|
| 123 |
+
Output:
|
| 124 |
+
plan: planner_data_viz_agent
|
| 125 |
+
{
|
| 126 |
+
"planner_data_viz_agent": {
|
| 127 |
+
"create": [
|
| 128 |
+
"cleaned_data: DataFrame - cleaned version of df (pd.Dataframe) after removing null values"
|
| 129 |
+
],
|
| 130 |
+
"use": [
|
| 131 |
+
"df: DataFrame - unprocessed dataset (pd.Dataframe) containing sales and category information"
|
| 132 |
+
],
|
| 133 |
+
"instruction": "Clean df by removing null values, calculate the average sales, and generate a bar plot showing sales by category."
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
|
| 137 |
+
Example 3 Agent
|
| 138 |
+
goal:"Clean the dataset, run a linear regression to model the relationship between marketing budget and sales, and visualize the regression line with confidence intervals."
|
| 139 |
+
plan: planner_preprocessing_agent -> planner_statistical_analytics_agent -> planner_data_viz_agent
|
| 140 |
+
|
| 141 |
+
{
|
| 142 |
+
"planner_preprocessing_agent": {
|
| 143 |
+
"create": [
|
| 144 |
+
"cleaned_data: DataFrame - cleaned version of df with missing values handled and proper data types inferred"
|
| 145 |
+
],
|
| 146 |
+
"use": [
|
| 147 |
+
"df: DataFrame - dataset containing marketing budgets and sales figures"
|
| 148 |
+
],
|
| 149 |
+
"instruction": "Clean df by handling missing values and converting column types (e.g., dates). Output cleaned_data for modeling."
|
| 150 |
+
},
|
| 151 |
+
|
| 152 |
+
"planner_statistical_analytics_agent": {
|
| 153 |
+
"create": [
|
| 154 |
+
"regression_results: dict - model summary including coefficients, p-values, R², and confidence intervals"
|
| 155 |
+
],
|
| 156 |
+
"use": [
|
| 157 |
+
"cleaned_data: DataFrame - preprocessed dataset ready for regression"
|
| 158 |
+
],
|
| 159 |
+
"instruction": "Perform linear regression using cleaned_data to model sales as a function of marketing budget. Return regression_results including coefficients and confidence intervals."
|
| 160 |
+
},
|
| 161 |
+
|
| 162 |
+
"planner_data_viz_agent": {
|
| 163 |
+
"create": [
|
| 164 |
+
"regression_plot: PlotlyFigure - visual plot showing regression line with confidence intervals"
|
| 165 |
+
],
|
| 166 |
+
"use": [
|
| 167 |
+
"cleaned_data: DataFrame - original dataset for plotting",
|
| 168 |
+
"regression_results: dict - output of linear regression"
|
| 169 |
+
],
|
| 170 |
+
"instruction": "Generate a Plotly regression plot using cleaned_data and regression_results. Show the fitted line, scatter points, and 95% confidence intervals."
|
| 171 |
+
}
|
| 172 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
+
Keep it as simple as possible, unless user specifies indepth query!
|
|
|
|
|
|
|
| 175 |
|
|
|
|
| 176 |
"""
|
| 177 |
dataset = dspy.InputField(desc="Available datasets loaded in the system, use this df, columns set df as copy of df")
|
| 178 |
Agent_desc = dspy.InputField(desc="The agents available in the system")
|