Plot
PlotTool
dataclass
Tool responsible for generating and saving visualization charts based on SRAG data.
Unlike a generic plotting tool, this is highly specialized. It executes pre-defined
SQL aggregations to guarantee correct statistical representation for specific
chart types (trend_30d and history_12m).
Dual Output Strategy:
- Visual: Saves a PNG file to disk.
- Semantic: Returns a text summary (growth rates, peaks, totals) to the LLM. This allows the Agent to "see" the data and describe the chart accurately in the report.
Attributes:
| Name | Type | Description |
|---|---|---|
output_dir |
Path
|
The directory where PNG files will be saved. |
Source code in api/src/tools/plot.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 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 | |
__call__(ctx, chart_type)
Generates the requested chart and returns a status message with data insights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
RunContext
|
The context containing the database connection. |
required |
chart_type
|
str
|
The type of chart to generate ('trend_30d' or 'history_12m'). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A system note containing the file path of the generated chart AND a statistical summary of the data plotted (e.g., "Growth: +15%"). |
Source code in api/src/tools/plot.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 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 | |
create_plot_tool(output_dir)
Factory to create the Plot Tool instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path
|
The target directory for saving chart images. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tool |
Tool[AgentDeps]
|
The Pydantic AI Tool wrapping the PlotTool class. |
Source code in api/src/tools/plot.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |