vxcontrol/pentagi · error

failed to create assistant: %w

Error message

failed to create assistant: %w

What it means

Wrap in CreateAssistant when NewAssistantWorker fails to construct the assistant worker after the flow worker is resolved. NewAssistantWorker wires up provider, functions, resources and flow context; failures there (provider resolution, function binding, resource setup) are wrapped with %w.

Source

Thrown at backend/pkg/controller/flows.go:320

	if fw == nil { // just double check, this should never happen
		return nil, fmt.Errorf("unexpected error: flow %d not found", flowID)
	}

	aw, err := NewAssistantWorker(ctx, newAssistantWorkerCtx{
		userID:        userID,
		flowID:        flowID,
		input:         input,
		prvname:       prvname,
		prvtype:       prvtype,
		useAgents:     useAgents,
		functions:     functions,
		resources:     resources,
		fw:            fw,
		flowWorkerCtx: flowWorkerCtx,
	})
	if err != nil {
		return nil, fmt.Errorf("failed to create assistant: %w", err)
	}

	if err = fw.AddAssistant(ctx, aw); err != nil {
		return nil, fmt.Errorf("failed to add assistant to flow: %w", err)
	}

	return aw, nil
}

func (fc *flowController) ListFlows(ctx context.Context) []FlowWorker {
	fc.mx.Lock()
	defer fc.mx.Unlock()

	flows := make([]FlowWorker, 0)
	for _, flow := range fc.flows {
		flows = append(flows, flow)
	}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Read the wrapped root cause and address it directly (provider, functions, or DB).
  2. Verify provider configuration (API keys, server URL) for prvname/prvtype.
  3. Ensure the tools.Functions set is built and registered for the selected provider/model.
  4. Check that the referenced user resources exist and are readable.
  5. Confirm DB connectivity and that migrations are current.

Example fix

// before
funcs built for Anthropic passed with prvtype=OpenAI -> NewAssistantWorker fails
// after
funcs, err := tools.BuildFunctions(ctx, provs, prvtype)
aw, err := ctl.CreateAssistant(ctx, userID, flowID, input, true, prvname, prvtype, funcs, resources)
Defensive patterns

Strategy: validation

Validate before calling

// pre-check provider availability for the assistant's provider
if !providerRegistry.IsConfigured(prvname, prvtype) {
    return fmt.Errorf("provider %s/%s is not configured", prvname, prvtype)
}
if functions == nil {
    return fmt.Errorf("functions required")
}

Try / catch

aw, err := ctl.CreateAssistant(...)
if err != nil {
    if strings.Contains(err.Error(), "failed to create assistant") {
        log.Errorf("assistant init: %v", err) // unwrap for root cause
    }
    return err
}

Prevention

When it happens

Trigger: CreateAssistant reached the NewAssistantWorker call (flow resolved fine) but construction failed — e.g. the provider cannot be instantiated for prvname/prvtype, functions is incompatible with the provider, or initializing assistant state in the DB fails.

Common situations: Provider credentials missing at assistant-creation time, functions/tool set not registered for the chosen model, invalid user resources referenced, or a DB error while persisting the assistant record.

Related errors


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