{"record":{"id":"3920be6d7a2e6e00","repo":"vxcontrol/pentagi","slug":"failed-to-create-assistant-w","errorCode":null,"errorMessage":"failed to create assistant: %w","messagePattern":"failed to create assistant: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/flows.go","lineNumber":320,"sourceCode":"\n\tif fw == nil { // just double check, this should never happen\n\t\treturn nil, fmt.Errorf(\"unexpected error: flow %d not found\", flowID)\n\t}\n\n\taw, err := NewAssistantWorker(ctx, newAssistantWorkerCtx{\n\t\tuserID:        userID,\n\t\tflowID:        flowID,\n\t\tinput:         input,\n\t\tprvname:       prvname,\n\t\tprvtype:       prvtype,\n\t\tuseAgents:     useAgents,\n\t\tfunctions:     functions,\n\t\tresources:     resources,\n\t\tfw:            fw,\n\t\tflowWorkerCtx: flowWorkerCtx,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create assistant: %w\", err)\n\t}\n\n\tif err = fw.AddAssistant(ctx, aw); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to add assistant to flow: %w\", err)\n\t}\n\n\treturn aw, nil\n}\n\nfunc (fc *flowController) ListFlows(ctx context.Context) []FlowWorker {\n\tfc.mx.Lock()\n\tdefer fc.mx.Unlock()\n\n\tflows := make([]FlowWorker, 0)\n\tfor _, flow := range fc.flows {\n\t\tflows = append(flows, flow)\n\t}\n","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/flows.go#L302-L338","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the wrapped root cause and address it directly (provider, functions, or DB).","Verify provider configuration (API keys, server URL) for prvname/prvtype.","Ensure the tools.Functions set is built and registered for the selected provider/model.","Check that the referenced user resources exist and are readable.","Confirm DB connectivity and that migrations are current."],"exampleFix":"// before\nfuncs built for Anthropic passed with prvtype=OpenAI -> NewAssistantWorker fails\n// after\nfuncs, err := tools.BuildFunctions(ctx, provs, prvtype)\naw, err := ctl.CreateAssistant(ctx, userID, flowID, input, true, prvname, prvtype, funcs, resources)","handlingStrategy":"validation","validationCode":"// pre-check provider availability for the assistant's provider\nif !providerRegistry.IsConfigured(prvname, prvtype) {\n    return fmt.Errorf(\"provider %s/%s is not configured\", prvname, prvtype)\n}\nif functions == nil {\n    return fmt.Errorf(\"functions required\")\n}","typeGuard":null,"tryCatchPattern":"aw, err := ctl.CreateAssistant(...)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to create assistant\") {\n        log.Errorf(\"assistant init: %v\", err) // unwrap for root cause\n    }\n    return err\n}","preventionTips":["Build tools.Functions against the same provider type passed to CreateAssistant.","Validate user resources exist before referencing them in an assistant.","Keep provider credentials present for the lifetime of flows.","Ensure migrations and DB are healthy before creating assistants."],"tags":["go","assistant-worker","provider-config","wrapped-error"],"backgroundTag":"assistant-creation-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}