@rlynjb/aptkit-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +9 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/README.md +13 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/categories.d.ts +11 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/categories.js +100 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/fixture-provider.d.ts +10 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/fixture-provider.js +18 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/index.d.ts +6 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/index.js +6 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/monitoring-agent.d.ts +32 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/monitoring-agent.js +88 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/schema-summary.d.ts +2 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/schema-summary.js +7 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/types.d.ts +32 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/types.js +1 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/validate.d.ts +9 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/validate.js +34 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/fixtures/promoted/sp-revenue-monitoring-fixture-promoted-2026-06-18-18-37-26.json +229 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/fixtures/sp-revenue-monitoring.json +136 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/package.json +33 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/README.md +11 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/diagnostic-agent.d.ts +27 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/diagnostic-agent.js +95 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/fixture-provider.d.ts +10 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/fixture-provider.js +18 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/index.d.ts +5 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/index.js +5 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/schema-summary.d.ts +1 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/schema-summary.js +1 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/types.d.ts +37 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/types.js +1 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/validate.d.ts +10 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/validate.js +49 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/fixtures/promoted/sp-revenue-diagnostic-fixture-promoted-2026-06-18-19-04-28.json +230 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/fixtures/sp-revenue-diagnostic.json +148 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/package.json +33 -0
- package/node_modules/@aptkit/agent-query/README.md +11 -0
- package/node_modules/@aptkit/agent-query/dist/src/fixture-provider.d.ts +10 -0
- package/node_modules/@aptkit/agent-query/dist/src/fixture-provider.js +18 -0
- package/node_modules/@aptkit/agent-query/dist/src/index.d.ts +6 -0
- package/node_modules/@aptkit/agent-query/dist/src/index.js +6 -0
- package/node_modules/@aptkit/agent-query/dist/src/intent.d.ts +6 -0
- package/node_modules/@aptkit/agent-query/dist/src/intent.js +23 -0
- package/node_modules/@aptkit/agent-query/dist/src/query-agent.d.ts +27 -0
- package/node_modules/@aptkit/agent-query/dist/src/query-agent.js +81 -0
- package/node_modules/@aptkit/agent-query/dist/src/schema-summary.d.ts +1 -0
- package/node_modules/@aptkit/agent-query/dist/src/schema-summary.js +1 -0
- package/node_modules/@aptkit/agent-query/dist/src/types.d.ts +5 -0
- package/node_modules/@aptkit/agent-query/dist/src/types.js +1 -0
- package/node_modules/@aptkit/agent-query/dist/src/validate.d.ts +7 -0
- package/node_modules/@aptkit/agent-query/dist/src/validate.js +9 -0
- package/node_modules/@aptkit/agent-query/fixtures/promoted/revenue-by-state-query-fixture-promoted-2026-06-18-19-29-11.json +138 -0
- package/node_modules/@aptkit/agent-query/fixtures/revenue-by-state-query.json +79 -0
- package/node_modules/@aptkit/agent-query/package.json +33 -0
- package/node_modules/@aptkit/agent-recommendation/README.md +109 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/fixture-provider.d.ts +10 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/fixture-provider.js +18 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/index.d.ts +4 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/index.js +4 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/recommendation-agent.d.ts +30 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/recommendation-agent.js +85 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/schema-summary.d.ts +1 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/schema-summary.js +1 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/types.d.ts +68 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/types.js +3 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/validate.d.ts +3 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/validate.js +54 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/electronics-spike.json +84 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/promoted/voucher-dropoff-w10-on-openai-promoted-2026-06-18-16-53-02.json +166 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/promoted/voucher-dropoff-w10-on-openai-promoted-2026-06-18-17-20-55.json +157 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/sp-revenue-drop.json +83 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/voucher-dropoff.json +84 -0
- package/node_modules/@aptkit/agent-recommendation/package.json +34 -0
- package/node_modules/@aptkit/context/README.md +15 -0
- package/node_modules/@aptkit/context/dist/src/index.d.ts +2 -0
- package/node_modules/@aptkit/context/dist/src/index.js +2 -0
- package/node_modules/@aptkit/context/dist/src/workspace-descriptor.d.ts +25 -0
- package/node_modules/@aptkit/context/dist/src/workspace-descriptor.js +1 -0
- package/node_modules/@aptkit/context/dist/src/workspace-summary.d.ts +9 -0
- package/node_modules/@aptkit/context/dist/src/workspace-summary.js +38 -0
- package/node_modules/@aptkit/context/package.json +24 -0
- package/node_modules/@aptkit/evals/dist/src/assertions.d.ts +13 -0
- package/node_modules/@aptkit/evals/dist/src/assertions.js +351 -0
- package/node_modules/@aptkit/evals/dist/src/detection-scorer.d.ts +25 -0
- package/node_modules/@aptkit/evals/dist/src/detection-scorer.js +72 -0
- package/node_modules/@aptkit/evals/dist/src/index.d.ts +3 -0
- package/node_modules/@aptkit/evals/dist/src/index.js +3 -0
- package/node_modules/@aptkit/evals/dist/src/replay-runner.d.ts +29 -0
- package/node_modules/@aptkit/evals/dist/src/replay-runner.js +72 -0
- package/node_modules/@aptkit/evals/dist/src/structural-diff.d.ts +50 -0
- package/node_modules/@aptkit/evals/dist/src/structural-diff.js +143 -0
- package/node_modules/@aptkit/evals/package.json +27 -0
- package/node_modules/@aptkit/prompts/README.md +7 -0
- package/node_modules/@aptkit/prompts/dist/src/diagnostic.d.ts +3 -0
- package/node_modules/@aptkit/prompts/dist/src/diagnostic.js +85 -0
- package/node_modules/@aptkit/prompts/dist/src/index.d.ts +5 -0
- package/node_modules/@aptkit/prompts/dist/src/index.js +5 -0
- package/node_modules/@aptkit/prompts/dist/src/monitoring.d.ts +3 -0
- package/node_modules/@aptkit/prompts/dist/src/monitoring.js +57 -0
- package/node_modules/@aptkit/prompts/dist/src/query.d.ts +3 -0
- package/node_modules/@aptkit/prompts/dist/src/query.js +86 -0
- package/node_modules/@aptkit/prompts/dist/src/recommendation.d.ts +3 -0
- package/node_modules/@aptkit/prompts/dist/src/recommendation.js +110 -0
- package/node_modules/@aptkit/prompts/dist/src/types.d.ts +21 -0
- package/node_modules/@aptkit/prompts/dist/src/types.js +6 -0
- package/node_modules/@aptkit/prompts/package.json +24 -0
- package/node_modules/@aptkit/runtime/dist/src/events.d.ts +44 -0
- package/node_modules/@aptkit/runtime/dist/src/events.js +3 -0
- package/node_modules/@aptkit/runtime/dist/src/index.d.ts +6 -0
- package/node_modules/@aptkit/runtime/dist/src/index.js +6 -0
- package/node_modules/@aptkit/runtime/dist/src/json-output.d.ts +10 -0
- package/node_modules/@aptkit/runtime/dist/src/json-output.js +32 -0
- package/node_modules/@aptkit/runtime/dist/src/model-provider.d.ts +49 -0
- package/node_modules/@aptkit/runtime/dist/src/model-provider.js +1 -0
- package/node_modules/@aptkit/runtime/dist/src/ndjson-stream.d.ts +43 -0
- package/node_modules/@aptkit/runtime/dist/src/ndjson-stream.js +128 -0
- package/node_modules/@aptkit/runtime/dist/src/run-agent-loop.d.ts +42 -0
- package/node_modules/@aptkit/runtime/dist/src/run-agent-loop.js +138 -0
- package/node_modules/@aptkit/runtime/dist/src/usage-ledger.d.ts +29 -0
- package/node_modules/@aptkit/runtime/dist/src/usage-ledger.js +61 -0
- package/node_modules/@aptkit/runtime/package.json +23 -0
- package/node_modules/@aptkit/tools/dist/src/coverage-gate.d.ts +32 -0
- package/node_modules/@aptkit/tools/dist/src/coverage-gate.js +43 -0
- package/node_modules/@aptkit/tools/dist/src/index.d.ts +3 -0
- package/node_modules/@aptkit/tools/dist/src/index.js +3 -0
- package/node_modules/@aptkit/tools/dist/src/tool-policy.d.ts +9 -0
- package/node_modules/@aptkit/tools/dist/src/tool-policy.js +11 -0
- package/node_modules/@aptkit/tools/dist/src/tool-registry.d.ts +27 -0
- package/node_modules/@aptkit/tools/dist/src/tool-registry.js +25 -0
- package/node_modules/@aptkit/tools/package.json +26 -0
- package/package.json +53 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "sp-revenue-diagnostic-fixture-promoted",
|
|
3
|
+
"description": "Promoted deterministic diagnostic fixture from fixture replay artifact. Source fixture: sp-revenue-diagnostic. Replay created at: 2026-06-18T19:04:28.139Z.",
|
|
4
|
+
"workspace": {
|
|
5
|
+
"projectId": "olist",
|
|
6
|
+
"projectName": "Olist Brazilian ecommerce fixture",
|
|
7
|
+
"events": [
|
|
8
|
+
{
|
|
9
|
+
"name": "purchase",
|
|
10
|
+
"properties": [
|
|
11
|
+
"state",
|
|
12
|
+
"category",
|
|
13
|
+
"total_price"
|
|
14
|
+
],
|
|
15
|
+
"eventCount": 50000
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "session_start",
|
|
19
|
+
"properties": [
|
|
20
|
+
"utm_source"
|
|
21
|
+
],
|
|
22
|
+
"eventCount": 80000
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "checkout",
|
|
26
|
+
"properties": [
|
|
27
|
+
"state"
|
|
28
|
+
],
|
|
29
|
+
"eventCount": 35000
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "view_item",
|
|
33
|
+
"properties": [
|
|
34
|
+
"category"
|
|
35
|
+
],
|
|
36
|
+
"eventCount": 120000
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"customerProperties": [
|
|
40
|
+
"state",
|
|
41
|
+
"city"
|
|
42
|
+
],
|
|
43
|
+
"catalogs": [],
|
|
44
|
+
"totalCustomers": 125000,
|
|
45
|
+
"totalEvents": 285000,
|
|
46
|
+
"oldestTimestamp": 1764547200000,
|
|
47
|
+
"dataHorizon": {
|
|
48
|
+
"from": "2025-12-01",
|
|
49
|
+
"to": "2026-06-01",
|
|
50
|
+
"durationDays": 182
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"anomaly": {
|
|
54
|
+
"metric": "revenue",
|
|
55
|
+
"category": "revenue_drop",
|
|
56
|
+
"scope": [
|
|
57
|
+
"state:SP"
|
|
58
|
+
],
|
|
59
|
+
"change": {
|
|
60
|
+
"value": 30,
|
|
61
|
+
"direction": "down",
|
|
62
|
+
"baseline": "recent 4w vs prior 12w"
|
|
63
|
+
},
|
|
64
|
+
"severity": "critical",
|
|
65
|
+
"impact": "Sao Paulo revenue is down about 30% while nearby states are stable.",
|
|
66
|
+
"evidence": [
|
|
67
|
+
{
|
|
68
|
+
"tool": "get_anomaly_context",
|
|
69
|
+
"result": {
|
|
70
|
+
"segment": "SP",
|
|
71
|
+
"pct_change": -0.300245,
|
|
72
|
+
"anomaly_value": 28550000,
|
|
73
|
+
"baseline_avg": 40800000
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"tools": [
|
|
79
|
+
{
|
|
80
|
+
"name": "get_anomaly_context",
|
|
81
|
+
"description": "Return context for a selected anomaly window and baseline.",
|
|
82
|
+
"inputSchema": {
|
|
83
|
+
"type": "object",
|
|
84
|
+
"properties": {
|
|
85
|
+
"metric": {
|
|
86
|
+
"type": "string"
|
|
87
|
+
},
|
|
88
|
+
"dimension": {
|
|
89
|
+
"type": "string"
|
|
90
|
+
},
|
|
91
|
+
"segment": {
|
|
92
|
+
"type": "string"
|
|
93
|
+
},
|
|
94
|
+
"anomaly_window": {
|
|
95
|
+
"type": "object"
|
|
96
|
+
},
|
|
97
|
+
"baseline_window": {
|
|
98
|
+
"type": "object"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"required": [
|
|
102
|
+
"metric",
|
|
103
|
+
"dimension",
|
|
104
|
+
"segment"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"result": {
|
|
108
|
+
"anomaly_summary": {
|
|
109
|
+
"metric": "revenue",
|
|
110
|
+
"segment": "SP",
|
|
111
|
+
"anomaly_value": 28550000,
|
|
112
|
+
"baseline_avg": 40800000,
|
|
113
|
+
"pct_change": -0.300245
|
|
114
|
+
},
|
|
115
|
+
"related_segments": [
|
|
116
|
+
{
|
|
117
|
+
"name": "RJ",
|
|
118
|
+
"pct_change": -0.02
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"name": "MG",
|
|
122
|
+
"pct_change": 0.01
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
"sample_orders": [
|
|
126
|
+
{
|
|
127
|
+
"order_id": "sp-101",
|
|
128
|
+
"purchase_ts": "2026-05-10",
|
|
129
|
+
"status": "delivered",
|
|
130
|
+
"price_brl": 42000
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"order_id": "sp-102",
|
|
134
|
+
"purchase_ts": "2026-05-23",
|
|
135
|
+
"status": "delivered",
|
|
136
|
+
"price_brl": 31000
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"name": "get_metric_timeseries",
|
|
143
|
+
"description": "Return metric timeseries for an optional dimension.",
|
|
144
|
+
"inputSchema": {
|
|
145
|
+
"type": "object",
|
|
146
|
+
"properties": {
|
|
147
|
+
"metric": {
|
|
148
|
+
"type": "string"
|
|
149
|
+
},
|
|
150
|
+
"dimension": {
|
|
151
|
+
"type": "string"
|
|
152
|
+
},
|
|
153
|
+
"filter": {
|
|
154
|
+
"type": "object"
|
|
155
|
+
},
|
|
156
|
+
"time_range": {
|
|
157
|
+
"type": "object"
|
|
158
|
+
},
|
|
159
|
+
"granularity": {
|
|
160
|
+
"type": "string"
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"required": [
|
|
164
|
+
"metric",
|
|
165
|
+
"time_range"
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
"result": {
|
|
169
|
+
"points": [
|
|
170
|
+
{
|
|
171
|
+
"ts": "2026-05-04",
|
|
172
|
+
"segment": "SP",
|
|
173
|
+
"value": 7400000
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"ts": "2026-05-11",
|
|
177
|
+
"segment": "SP",
|
|
178
|
+
"value": 7200000
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"ts": "2026-05-18",
|
|
182
|
+
"segment": "SP",
|
|
183
|
+
"value": 7050000
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"ts": "2026-05-25",
|
|
187
|
+
"segment": "SP",
|
|
188
|
+
"value": 6900000
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
"totalCount": 4200
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
],
|
|
195
|
+
"modelResponses": [
|
|
196
|
+
{
|
|
197
|
+
"content": [
|
|
198
|
+
{
|
|
199
|
+
"type": "text",
|
|
200
|
+
"text": "```json\n{\n \"conclusion\": \"The SP revenue drop is isolated to Sao Paulo and is best explained by a regional demand or operations issue rather than broad marketplace seasonality. SP revenue fell about 30% versus baseline while RJ and MG were nearly flat, and the weekly series shows a steady slide through May.\",\n \"evidence\": [\n \"get_anomaly_context reported SP revenue of 28,550,000 against a 40,800,000 baseline average, a -30.0245% change.\",\n \"Related segments did not move with SP: RJ was -2% and MG was +1%.\",\n \"The SP weekly revenue series declined from 7,400,000 to 6,900,000 across the anomaly window.\"\n ],\n \"hypothesesConsidered\": [\n {\n \"hypothesis\": \"Broad marketplace seasonality\",\n \"supported\": false,\n \"reasoning\": \"Related state segments were nearly flat, so the pattern is not broad.\"\n },\n {\n \"hypothesis\": \"Sao Paulo-specific demand or operations issue\",\n \"supported\": true,\n \"reasoning\": \"The magnitude is concentrated in SP and persists across the anomaly weeks.\"\n },\n {\n \"hypothesis\": \"One-week reporting gap\",\n \"supported\": false,\n \"reasoning\": \"The timeseries shows a gradual weekly slide rather than a sudden zero or missing week.\"\n }\n ],\n \"timeSeries\": [\n {\n \"day\": \"w-3\",\n \"value\": 7400000\n },\n {\n \"day\": \"w-2\",\n \"value\": 7200000\n },\n {\n \"day\": \"w-1\",\n \"value\": 7050000\n },\n {\n \"day\": \"this week\",\n \"value\": 6900000\n }\n ],\n \"confidence\": \"high\"\n}\n```"
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
"usage": {
|
|
204
|
+
"inputTokens": 2920,
|
|
205
|
+
"outputTokens": 425,
|
|
206
|
+
"estimated": true
|
|
207
|
+
},
|
|
208
|
+
"model": "promoted-fixture-replay"
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
"expectations": {
|
|
212
|
+
"requiredEvidenceText": [
|
|
213
|
+
"get_anomaly_context reported SP revenue of 28",
|
|
214
|
+
"Related segments did not move with",
|
|
215
|
+
"The SP weekly revenue series declined"
|
|
216
|
+
],
|
|
217
|
+
"requiredSupportedHypothesisText": [
|
|
218
|
+
"Sao Paulo-specific demand or operations issue"
|
|
219
|
+
]
|
|
220
|
+
},
|
|
221
|
+
"promotion": {
|
|
222
|
+
"sourceArtifact": "artifacts/replays/2026-06-18T19-04-28-139Z-sp-revenue-diagnostic-fixture-studio.json",
|
|
223
|
+
"sourceProvider": {
|
|
224
|
+
"id": "fixture",
|
|
225
|
+
"model": "fixture-model"
|
|
226
|
+
},
|
|
227
|
+
"promotedAt": "2026-06-18T19:12:30.863Z",
|
|
228
|
+
"note": "This fixture captures the final diagnostic replay answer deterministically; it does not reconstruct the live provider tool loop."
|
|
229
|
+
}
|
|
230
|
+
}
|
package/node_modules/@aptkit/agent-diagnostic-investigation/fixtures/sp-revenue-diagnostic.json
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "sp-revenue-diagnostic",
|
|
3
|
+
"description": "Diagnose the seeded SP revenue drop from deterministic Olist-style context and timeseries tools.",
|
|
4
|
+
"workspace": {
|
|
5
|
+
"projectId": "olist",
|
|
6
|
+
"projectName": "Olist Brazilian ecommerce fixture",
|
|
7
|
+
"events": [
|
|
8
|
+
{ "name": "purchase", "properties": ["state", "category", "total_price"], "eventCount": 50000 },
|
|
9
|
+
{ "name": "session_start", "properties": ["utm_source"], "eventCount": 80000 },
|
|
10
|
+
{ "name": "checkout", "properties": ["state"], "eventCount": 35000 },
|
|
11
|
+
{ "name": "view_item", "properties": ["category"], "eventCount": 120000 }
|
|
12
|
+
],
|
|
13
|
+
"customerProperties": ["state", "city"],
|
|
14
|
+
"catalogs": [],
|
|
15
|
+
"totalCustomers": 125000,
|
|
16
|
+
"totalEvents": 285000,
|
|
17
|
+
"oldestTimestamp": 1764547200000,
|
|
18
|
+
"dataHorizon": { "from": "2025-12-01", "to": "2026-06-01", "durationDays": 182 }
|
|
19
|
+
},
|
|
20
|
+
"anomaly": {
|
|
21
|
+
"metric": "revenue",
|
|
22
|
+
"category": "revenue_drop",
|
|
23
|
+
"scope": ["state:SP"],
|
|
24
|
+
"change": { "value": 30, "direction": "down", "baseline": "recent 4w vs prior 12w" },
|
|
25
|
+
"severity": "critical",
|
|
26
|
+
"impact": "Sao Paulo revenue is down about 30% while nearby states are stable.",
|
|
27
|
+
"evidence": [
|
|
28
|
+
{
|
|
29
|
+
"tool": "get_anomaly_context",
|
|
30
|
+
"result": {
|
|
31
|
+
"segment": "SP",
|
|
32
|
+
"pct_change": -0.300245,
|
|
33
|
+
"anomaly_value": 28550000,
|
|
34
|
+
"baseline_avg": 40800000
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"tools": [
|
|
40
|
+
{
|
|
41
|
+
"name": "get_anomaly_context",
|
|
42
|
+
"description": "Return context for a selected anomaly window and baseline.",
|
|
43
|
+
"inputSchema": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"properties": {
|
|
46
|
+
"metric": { "type": "string" },
|
|
47
|
+
"dimension": { "type": "string" },
|
|
48
|
+
"segment": { "type": "string" },
|
|
49
|
+
"anomaly_window": { "type": "object" },
|
|
50
|
+
"baseline_window": { "type": "object" }
|
|
51
|
+
},
|
|
52
|
+
"required": ["metric", "dimension", "segment"]
|
|
53
|
+
},
|
|
54
|
+
"result": {
|
|
55
|
+
"anomaly_summary": {
|
|
56
|
+
"metric": "revenue",
|
|
57
|
+
"segment": "SP",
|
|
58
|
+
"anomaly_value": 28550000,
|
|
59
|
+
"baseline_avg": 40800000,
|
|
60
|
+
"pct_change": -0.300245
|
|
61
|
+
},
|
|
62
|
+
"related_segments": [
|
|
63
|
+
{ "name": "RJ", "pct_change": -0.02 },
|
|
64
|
+
{ "name": "MG", "pct_change": 0.01 }
|
|
65
|
+
],
|
|
66
|
+
"sample_orders": [
|
|
67
|
+
{ "order_id": "sp-101", "purchase_ts": "2026-05-10", "status": "delivered", "price_brl": 42000 },
|
|
68
|
+
{ "order_id": "sp-102", "purchase_ts": "2026-05-23", "status": "delivered", "price_brl": 31000 }
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "get_metric_timeseries",
|
|
74
|
+
"description": "Return metric timeseries for an optional dimension.",
|
|
75
|
+
"inputSchema": {
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {
|
|
78
|
+
"metric": { "type": "string" },
|
|
79
|
+
"dimension": { "type": "string" },
|
|
80
|
+
"filter": { "type": "object" },
|
|
81
|
+
"time_range": { "type": "object" },
|
|
82
|
+
"granularity": { "type": "string" }
|
|
83
|
+
},
|
|
84
|
+
"required": ["metric", "time_range"]
|
|
85
|
+
},
|
|
86
|
+
"result": {
|
|
87
|
+
"points": [
|
|
88
|
+
{ "ts": "2026-05-04", "segment": "SP", "value": 7400000 },
|
|
89
|
+
{ "ts": "2026-05-11", "segment": "SP", "value": 7200000 },
|
|
90
|
+
{ "ts": "2026-05-18", "segment": "SP", "value": 7050000 },
|
|
91
|
+
{ "ts": "2026-05-25", "segment": "SP", "value": 6900000 }
|
|
92
|
+
],
|
|
93
|
+
"totalCount": 4200
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"modelResponses": [
|
|
98
|
+
{
|
|
99
|
+
"content": [
|
|
100
|
+
{
|
|
101
|
+
"type": "tool_use",
|
|
102
|
+
"id": "diag-tool-1",
|
|
103
|
+
"name": "get_anomaly_context",
|
|
104
|
+
"input": {
|
|
105
|
+
"metric": "revenue",
|
|
106
|
+
"dimension": "state",
|
|
107
|
+
"segment": "SP",
|
|
108
|
+
"anomaly_window": { "from": "2026-05-04", "to": "2026-06-01" },
|
|
109
|
+
"baseline_window": { "from": "2026-02-09", "to": "2026-05-04" }
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"usage": { "inputTokens": 980, "outputTokens": 80 },
|
|
114
|
+
"model": "fixture-model"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"content": [
|
|
118
|
+
{
|
|
119
|
+
"type": "tool_use",
|
|
120
|
+
"id": "diag-tool-2",
|
|
121
|
+
"name": "get_metric_timeseries",
|
|
122
|
+
"input": {
|
|
123
|
+
"metric": "revenue",
|
|
124
|
+
"filter": { "dimension": "state", "value": "SP" },
|
|
125
|
+
"time_range": { "from": "2026-05-04", "to": "2026-06-01" },
|
|
126
|
+
"granularity": "week"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
"usage": { "inputTokens": 820, "outputTokens": 85 },
|
|
131
|
+
"model": "fixture-model"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"content": [
|
|
135
|
+
{
|
|
136
|
+
"type": "text",
|
|
137
|
+
"text": "```json\n{\"conclusion\":\"The SP revenue drop is isolated to Sao Paulo and is best explained by a regional demand or operations issue rather than broad marketplace seasonality. SP revenue fell about 30% versus baseline while RJ and MG were nearly flat, and the weekly series shows a steady slide through May.\",\"evidence\":[\"get_anomaly_context reported SP revenue of 28,550,000 against a 40,800,000 baseline average, a -30.0245% change.\",\"Related segments did not move with SP: RJ was -2% and MG was +1%.\",\"The SP weekly revenue series declined from 7,400,000 to 6,900,000 across the anomaly window.\"],\"hypothesesConsidered\":[{\"hypothesis\":\"Broad marketplace seasonality\",\"supported\":false,\"reasoning\":\"Related state segments were nearly flat, so the pattern is not broad.\"},{\"hypothesis\":\"Sao Paulo-specific demand or operations issue\",\"supported\":true,\"reasoning\":\"The magnitude is concentrated in SP and persists across the anomaly weeks.\"},{\"hypothesis\":\"One-week reporting gap\",\"supported\":false,\"reasoning\":\"The timeseries shows a gradual weekly slide rather than a sudden zero or missing week.\"}],\"timeSeries\":[{\"day\":\"w-3\",\"value\":7400000},{\"day\":\"w-2\",\"value\":7200000},{\"day\":\"w-1\",\"value\":7050000},{\"day\":\"this week\",\"value\":6900000}]}\n```"
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
"usage": { "inputTokens": 1120, "outputTokens": 260 },
|
|
141
|
+
"model": "fixture-model"
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"expectations": {
|
|
145
|
+
"requiredEvidenceText": ["-30.0245%", "RJ", "weekly"],
|
|
146
|
+
"requiredSupportedHypothesisText": ["Sao Paulo"]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aptkit/agent-diagnostic-investigation",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/src/index.js",
|
|
6
|
+
"types": "./dist/src/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"README.md",
|
|
9
|
+
"dist/src",
|
|
10
|
+
"fixtures"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/src/index.d.ts",
|
|
15
|
+
"import": "./dist/src/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"test": "npm run build && node --test dist/test/*.test.js",
|
|
21
|
+
"replay:fixture": "npm run build && node dist/scripts/replay-fixture.js",
|
|
22
|
+
"replay:promoted": "npm run build && node ../../../scripts/replay-promoted-fixtures.mjs --count diagnosisPresent --empty \"no promoted diagnostic fixtures found\""
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@aptkit/context": "0.0.0",
|
|
26
|
+
"@aptkit/prompts": "0.0.0",
|
|
27
|
+
"@aptkit/runtime": "0.0.0",
|
|
28
|
+
"@aptkit/tools": "0.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^20.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Query Agent
|
|
2
|
+
|
|
3
|
+
Extracted from the Blooming Insights free-form query agent as a reusable AptKit capability.
|
|
4
|
+
|
|
5
|
+
This package answers a natural-language workspace question by using a `ToolRegistry`, then returning grounded prose instead of a structured JSON object.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { QueryAgent } from '@aptkit/agent-query';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The first fixture covers revenue by state over an Olist-style ecommerce workspace.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModelProvider, ModelRequest, ModelResponse } from '@aptkit/runtime';
|
|
2
|
+
export declare class FixtureModelProvider implements ModelProvider {
|
|
3
|
+
private readonly responses;
|
|
4
|
+
readonly id = "fixture";
|
|
5
|
+
readonly defaultModel = "fixture-model";
|
|
6
|
+
readonly requests: ModelRequest[];
|
|
7
|
+
private index;
|
|
8
|
+
constructor(responses: ModelResponse[]);
|
|
9
|
+
complete(request: ModelRequest): Promise<ModelResponse>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class FixtureModelProvider {
|
|
2
|
+
responses;
|
|
3
|
+
id = 'fixture';
|
|
4
|
+
defaultModel = 'fixture-model';
|
|
5
|
+
requests = [];
|
|
6
|
+
index = 0;
|
|
7
|
+
constructor(responses) {
|
|
8
|
+
this.responses = responses;
|
|
9
|
+
}
|
|
10
|
+
async complete(request) {
|
|
11
|
+
this.requests.push(request);
|
|
12
|
+
const response = this.responses[this.index];
|
|
13
|
+
this.index += 1;
|
|
14
|
+
if (!response)
|
|
15
|
+
throw new Error(`fixture model exhausted after ${this.index - 1} responses`);
|
|
16
|
+
return response;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ModelProvider } from '@aptkit/runtime';
|
|
2
|
+
import type { Intent } from './types.js';
|
|
3
|
+
export declare function parseIntent(raw: string): Intent;
|
|
4
|
+
export declare function classifyIntent(model: ModelProvider, query: string, options?: {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}): Promise<Intent>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function parseIntent(raw) {
|
|
2
|
+
const text = raw.trim().toLowerCase();
|
|
3
|
+
if (text.includes('monitoring'))
|
|
4
|
+
return 'monitoring';
|
|
5
|
+
if (text.includes('recommendation'))
|
|
6
|
+
return 'recommendation';
|
|
7
|
+
if (text.includes('diagnostic'))
|
|
8
|
+
return 'diagnostic';
|
|
9
|
+
return 'diagnostic';
|
|
10
|
+
}
|
|
11
|
+
export async function classifyIntent(model, query, options = {}) {
|
|
12
|
+
const response = await model.complete({
|
|
13
|
+
system: 'Classify the user query as exactly one word: monitoring (what changed / what is new), diagnostic (why did something happen), or recommendation (what should I do). Reply with ONLY the one word.',
|
|
14
|
+
messages: [{ role: 'user', content: query }],
|
|
15
|
+
maxTokens: 16,
|
|
16
|
+
signal: options.signal,
|
|
17
|
+
});
|
|
18
|
+
const text = response.content
|
|
19
|
+
.filter((block) => block.type === 'text')
|
|
20
|
+
.map((block) => block.text)
|
|
21
|
+
.join('');
|
|
22
|
+
return parseIntent(text);
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CapabilityTraceSink, type ModelProvider } from '@aptkit/runtime';
|
|
2
|
+
import { type ToolRegistry } from '@aptkit/tools';
|
|
3
|
+
import type { Intent, WorkspaceDescriptor } from './types.js';
|
|
4
|
+
export declare const QUERY_CAPABILITY_ID = "query-agent";
|
|
5
|
+
/** Least-privilege tool grant for answering free-form workspace questions. */
|
|
6
|
+
export declare const queryToolPolicy: {
|
|
7
|
+
capabilityId: string;
|
|
8
|
+
allowedTools: readonly ["list_dashboards", "get_dashboard", "list_trends", "get_trend", "list_funnels", "get_funnel", "list_running_aggregates", "get_running_aggregate", "list_reports", "get_report", "execute_analytics", "execute_analytics_eql", "get_customer_prediction_score", "get_event_segmentation", "list_customers", "list_customer_events", "list_customers_in_segment", "list_segmentations", "list_email_campaigns", "list_sms_campaigns", "list_in_app_messages", "list_banners", "list_experiments", "list_scenarios", "list_catalog_items", "get_catalog_item", "get_scenario", "list_initiatives", "get_initiative_items", "list_recommendations", "get_recommendation", "list_voucher_pools", "get_frequency_policies", "get_metric_timeseries", "get_segments", "get_anomaly_context"];
|
|
9
|
+
};
|
|
10
|
+
export type QueryAgentOptions = {
|
|
11
|
+
model: ModelProvider;
|
|
12
|
+
tools: ToolRegistry;
|
|
13
|
+
workspace: WorkspaceDescriptor;
|
|
14
|
+
trace?: CapabilityTraceSink;
|
|
15
|
+
prompt?: string;
|
|
16
|
+
};
|
|
17
|
+
export type QueryRunOptions = {
|
|
18
|
+
intent?: Intent;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
};
|
|
21
|
+
export declare class QueryAgent {
|
|
22
|
+
private readonly options;
|
|
23
|
+
private readonly prompt;
|
|
24
|
+
constructor(options: QueryAgentOptions);
|
|
25
|
+
/** Answers a natural-language question by using only the supplied model and allowed tools. */
|
|
26
|
+
answer(question: string, runOptions?: QueryRunOptions): Promise<string>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { buildSynthesisInstruction, runAgentLoop } from '@aptkit/runtime';
|
|
2
|
+
import { queryPromptPackage, renderPromptTemplate } from '@aptkit/prompts';
|
|
3
|
+
import { filterToolsForPolicy } from '@aptkit/tools';
|
|
4
|
+
import { schemaSummary } from './schema-summary.js';
|
|
5
|
+
export const QUERY_CAPABILITY_ID = 'query-agent';
|
|
6
|
+
/** Least-privilege tool grant for answering free-form workspace questions. */
|
|
7
|
+
export const queryToolPolicy = {
|
|
8
|
+
capabilityId: QUERY_CAPABILITY_ID,
|
|
9
|
+
allowedTools: [
|
|
10
|
+
'list_dashboards',
|
|
11
|
+
'get_dashboard',
|
|
12
|
+
'list_trends',
|
|
13
|
+
'get_trend',
|
|
14
|
+
'list_funnels',
|
|
15
|
+
'get_funnel',
|
|
16
|
+
'list_running_aggregates',
|
|
17
|
+
'get_running_aggregate',
|
|
18
|
+
'list_reports',
|
|
19
|
+
'get_report',
|
|
20
|
+
'execute_analytics',
|
|
21
|
+
'execute_analytics_eql',
|
|
22
|
+
'get_customer_prediction_score',
|
|
23
|
+
'get_event_segmentation',
|
|
24
|
+
'list_customers',
|
|
25
|
+
'list_customer_events',
|
|
26
|
+
'list_customers_in_segment',
|
|
27
|
+
'list_segmentations',
|
|
28
|
+
'list_email_campaigns',
|
|
29
|
+
'list_sms_campaigns',
|
|
30
|
+
'list_in_app_messages',
|
|
31
|
+
'list_banners',
|
|
32
|
+
'list_experiments',
|
|
33
|
+
'list_scenarios',
|
|
34
|
+
'list_catalog_items',
|
|
35
|
+
'get_catalog_item',
|
|
36
|
+
'get_scenario',
|
|
37
|
+
'list_initiatives',
|
|
38
|
+
'get_initiative_items',
|
|
39
|
+
'list_recommendations',
|
|
40
|
+
'get_recommendation',
|
|
41
|
+
'list_voucher_pools',
|
|
42
|
+
'get_frequency_policies',
|
|
43
|
+
'get_metric_timeseries',
|
|
44
|
+
'get_segments',
|
|
45
|
+
'get_anomaly_context',
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
const FALLBACK_ANSWER = 'I was unable to find enough data to answer that question.';
|
|
49
|
+
export class QueryAgent {
|
|
50
|
+
options;
|
|
51
|
+
prompt;
|
|
52
|
+
constructor(options) {
|
|
53
|
+
this.options = options;
|
|
54
|
+
this.prompt = options.prompt ?? queryPromptPackage.system;
|
|
55
|
+
}
|
|
56
|
+
/** Answers a natural-language question by using only the supplied model and allowed tools. */
|
|
57
|
+
async answer(question, runOptions = {}) {
|
|
58
|
+
const allTools = await this.options.tools.listTools();
|
|
59
|
+
const toolSchemas = filterToolsForPolicy(allTools, queryToolPolicy);
|
|
60
|
+
const intent = runOptions.intent ?? 'diagnostic';
|
|
61
|
+
const system = renderPromptTemplate(this.prompt, {
|
|
62
|
+
schema: schemaSummary(this.options.workspace),
|
|
63
|
+
project_id: this.options.workspace.projectId,
|
|
64
|
+
intent,
|
|
65
|
+
});
|
|
66
|
+
const { finalText } = await runAgentLoop({
|
|
67
|
+
capabilityId: QUERY_CAPABILITY_ID,
|
|
68
|
+
model: this.options.model,
|
|
69
|
+
tools: this.options.tools,
|
|
70
|
+
system,
|
|
71
|
+
userPrompt: question,
|
|
72
|
+
toolSchemas,
|
|
73
|
+
trace: this.options.trace,
|
|
74
|
+
signal: runOptions.signal,
|
|
75
|
+
maxTurns: 8,
|
|
76
|
+
maxToolCalls: 6,
|
|
77
|
+
synthesisInstruction: buildSynthesisInstruction('Now answer the user question directly and concisely in plain prose, citing the key numbers you found.'),
|
|
78
|
+
});
|
|
79
|
+
return finalText.trim() || FALLBACK_ANSWER;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { schemaSummary } from '@aptkit/context';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { schemaSummary } from '@aptkit/context';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function validateQueryAnswer(answer) {
|
|
2
|
+
if (typeof answer !== 'string')
|
|
3
|
+
return { ok: false, error: 'answer must be a string' };
|
|
4
|
+
if (answer.trim().length === 0)
|
|
5
|
+
return { ok: false, error: 'answer must not be empty' };
|
|
6
|
+
if (answer.trim().length < 20)
|
|
7
|
+
return { ok: false, error: 'answer is too short to be useful' };
|
|
8
|
+
return { ok: true };
|
|
9
|
+
}
|