vxcontrol/pentagi · error

failed to get assistant system prompt: %w

Error message

failed to get assistant system prompt: %w

What it means

PrepareAgentChain of the assistant provider failed while fetching the assistant agent's system prompt (ap.getAssistantSystemPrompt). The prompt template is stored/config-backed; failure here aborts building the assistant message chain, and the error is wrapped after being logged.

Source

Thrown at backend/pkg/providers/assistant.go:117

func (ap *assistantProvider) SetFlowWorker(flowWorker FlowWorker) {
	ap.flowWorker = flowWorker
}

func (ap *assistantProvider) PrepareAgentChain(ctx context.Context) (int64, error) {
	ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "providers.flowProvider.PrepareAssistantChain")
	defer span.End()

	logger := logrus.WithContext(ctx).WithFields(logrus.Fields{
		"provider":     ap.fp.Type(),
		"assistant_id": ap.id,
		"flow_id":      ap.fp.ID(),
	})

	systemPrompt, err := ap.getAssistantSystemPrompt(ctx)
	if err != nil {
		logger.WithError(err).Error("failed to get assistant system prompt")
		return 0, fmt.Errorf("failed to get assistant system prompt: %w", err)
	}

	optAgentType := pconfig.OptionsTypeAssistant
	msgChainType := database.MsgchainTypeAssistant
	ap.msgChainID, _, err = ap.fp.restoreChain(
		ctx, nil, nil, optAgentType, msgChainType, systemPrompt, "",
	)
	if err != nil {
		logger.WithError(err).Error("failed to restore assistant msg chain")
		return 0, fmt.Errorf("failed to restore assistant msg chain: %w", err)
	}

	return ap.msgChainID, nil
}

func (ap *assistantProvider) PerformAgentChain(ctx context.Context) error {
	ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "providers.assistantProvider.PerformAgentChain")
	defer span.End()

View on GitHub (pinned to ea665308ba)

Solutions

  1. Check the wrapped cause: DB error vs not-found
  2. Verify prompt settings in the UI (Settings → Prompts) — restore/create the assistant prompt
  3. Confirm goose migrations ran (backend/migrations/sql) and the prompts table is seeded
  4. Check database connectivity from the backend container

Example fix

// before
systemPrompt, err := ap.getAssistantSystemPrompt(ctx)
if err != nil { return 0, err }
// after
systemPrompt, err := ap.getAssistantSystemPrompt(ctx)
if err != nil {
    if errors.Is(err, sql.ErrNoRows) {
        systemPrompt = defaultAssistantPrompt // seed fallback
    } else {
        return 0, fmt.Errorf("failed to get assistant system prompt: %w", err)
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before creating the flow, ensure the assistant prompt exists
// SELECT count(*) FROM prompts WHERE type='assistant'

Try / catch

id, err := ap.PrepareAgentChain(ctx)
if err != nil {
    if strings.Contains(err.Error(), "failed to get assistant system prompt") {
        // re-seed default prompts or surface a settings error to the user
    }
    return err
}

Prevention

When it happens

Trigger: getAssistantSystemPrompt returns an error: the assistant prompt record is missing from the database (prompt settings table), the DB query fails (connection down, migration not applied), or the context is cancelled during the fetch.

Common situations: Fresh deployment where the default prompts were never seeded; user deleted the 'assistant' prompt in Settings UI; database migrations incomplete; Postgres outage.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/9fcaf74c05db29be. Report an issue: GitHub.