MCPcopy Index your code
hub / github.com/coder/coder / generateTurnStatusLabel

Method generateTurnStatusLabel

coderd/x/chatd/quickgen.go:827–898  ·  view source on GitHub ↗

generateTurnStatusLabel calls a cheap model to produce a short status label from the chat title, current state, and last assistant message text. It follows the same candidate-selection strategy as title generation: try preferred lightweight models first, then fall back to the provided model. Returns

(
	ctx context.Context,
	chat database.Chat,
	status database.ChatStatus,
	assistantText string,
	fallbackProvider string,
	fallbackModelName string,
	fallbackModel fantasy.LanguageModel,
	fallbackRoute resolvedModelRoute,
	keys chatprovider.ProviderAPIKeys,
	modelOpts modelBuildOptions,
	logger slog.Logger,
	debugSvc *chatdebug.Service,
	triggerMessageID int64,
	historyTipMessageID int64,
)

Source from the content-addressed store, hash-verified

825// as title generation: try preferred lightweight models first, then
826// fall back to the provided model. Returns "" on any failure.
827func (p *Server) generateTurnStatusLabel(
828 ctx context.Context,
829 chat database.Chat,
830 status database.ChatStatus,
831 assistantText string,
832 fallbackProvider string,
833 fallbackModelName string,
834 fallbackModel fantasy.LanguageModel,
835 fallbackRoute resolvedModelRoute,
836 keys chatprovider.ProviderAPIKeys,
837 modelOpts modelBuildOptions,
838 logger slog.Logger,
839 debugSvc *chatdebug.Service,
840 triggerMessageID int64,
841 historyTipMessageID int64,
842) string {
843 debugEnabled := debugSvc != nil && debugSvc.IsEnabled(ctx, chat.ID, chat.OwnerID)
844
845 labelCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
846 defer cancel()
847
848 assistantText = truncateRunes(assistantText, maxConversationContextRunes)
849 input := "Current chat state: " + turnStatusLabelStateContext(status) +
850 "\nChat title: " + chat.Title +
851 "\n\nAgent's latest message:\n" + assistantText
852
853 candidates := p.preferredShortTextCandidates(chat, keys)
854 candidates = append(candidates, shortTextCandidate{
855 provider: fallbackProvider,
856 model: fallbackModelName,
857 route: fallbackRoute,
858 lm: fallbackModel,
859 })
860
861 statusSeedSummary := chatdebug.SeedSummary("Turn status label")
862
863 for _, candidate := range candidates {
864 candidateCtx := labelCtx
865 candidateModel := candidate.lm
866 finishDebugRun := func(error) {}
867 if debugEnabled {
868 candidateCtx, candidateModel, finishDebugRun = p.prepareQuickgenDebugCandidate(
869 labelCtx,
870 chat,
871 debugSvc,
872 candidate,
873 modelOpts,
874 chatdebug.KindQuickgen,
875 triggerMessageID,
876 historyTipMessageID,
877 statusSeedSummary,
878 logger,
879 )
880 }
881
882 generatedLabel, err := generateStructuredTurnStatusLabel(
883 candidateCtx,
884 candidateModel,

Callers 1

Calls 8

SeedSummaryFunction · 0.92
IsEnabledMethod · 0.80
truncateRunesFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected