MCPcopy Create free account
hub / github.com/rilldata/rill / systemPrompt

Method systemPrompt

runtime/ai/analyst_agent.go:208–495  ·  view source on GitHub ↗
(ctx context.Context, metricsViewNames []string, args *AnalystAgentArgs)

Source from the content-addressed store, hash-verified

206}
207
208func (t *AnalystAgent) systemPrompt(ctx context.Context, metricsViewNames []string, args *AnalystAgentArgs) (string, error) {
209 // Prepare template data.
210 // NOTE: All the template properties are optional and may be empty.
211 session := GetSession(ctx)
212
213 instance, err := t.Runtime.Instance(ctx, session.InstanceID())
214 if err != nil {
215 return "", fmt.Errorf("failed to get instance: %w", err)
216 }
217 instanceCfg, err := instance.Config()
218 if err != nil {
219 return "", fmt.Errorf("failed to get instance config: %w", err)
220 }
221
222 ff, err := t.Runtime.FeatureFlags(ctx, session.InstanceID(), session.Claims())
223 if err != nil {
224 return "", fmt.Errorf("failed to get feature flags: %w", err)
225 }
226
227 if args.DisableCharts {
228 ff["chat_charts"] = false
229 }
230
231 metricsViewsQuoted := make([]string, len(metricsViewNames))
232 for i, mv := range metricsViewNames {
233 metricsViewsQuoted[i] = fmt.Sprintf("`%s`", mv)
234 }
235
236 dimensionsQuoted := make([]string, len(args.Dimensions))
237 for i, dim := range args.Dimensions {
238 dimensionsQuoted[i] = fmt.Sprintf("`%s`", dim)
239 }
240
241 measuresQuoted := make([]string, len(args.Measures))
242 for i, measure := range args.Measures {
243 measuresQuoted[i] = fmt.Sprintf("`%s`", measure)
244 }
245
246 data := map[string]any{
247 "ai_instructions": session.ProjectInstructions(),
248 "is_prompt": args.Prompt != "",
249 "metrics_views": strings.Join(metricsViewsQuoted, ", "),
250 "explore": args.Explore,
251 "canvas": args.Canvas,
252 "canvas_component": args.CanvasComponent,
253 "dimensions": strings.Join(dimensionsQuoted, ", "),
254 "measures": strings.Join(measuresQuoted, ", "),
255 "feature_flags": ff,
256 "forked": session.Forked(),
257 "is_report": args.IsReport,
258 "now": time.Now(),
259 "max_query_limit": instanceCfg.AIMaxQueryLimit,
260 }
261
262 if !args.TimeStart.IsZero() && !args.TimeEnd.IsZero() {
263 data["time_start"] = args.TimeStart.Format(time.RFC3339)
264 data["time_end"] = args.TimeEnd.Format(time.RFC3339)
265 }

Callers 1

HandlerMethod · 0.95

Calls 13

ExpressionToSQLFunction · 0.92
GetSessionFunction · 0.85
InstanceMethod · 0.80
InstanceIDMethod · 0.80
FeatureFlagsMethod · 0.80
ProjectInstructionsMethod · 0.80
ForkedMethod · 0.80
executeTemplateFunction · 0.70
ErrorfMethod · 0.65
ConfigMethod · 0.65
ClaimsMethod · 0.65
FormatMethod · 0.65

Tested by

no test coverage detected