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

Method createChildSubagentChatWithOptions

coderd/x/chatd/subagent.go:929–1118  ·  view source on GitHub ↗
(
	ctx context.Context,
	parent database.Chat,
	prompt string,
	title string,
	opts childSubagentChatOptions,
)

Source from the content-addressed store, hash-verified

927}
928
929func (p *Server) createChildSubagentChatWithOptions(
930 ctx context.Context,
931 parent database.Chat,
932 prompt string,
933 title string,
934 opts childSubagentChatOptions,
935) (database.Chat, error) {
936 if parent.ParentChatID.Valid {
937 return database.Chat{}, xerrors.New("delegated chats cannot create child subagents")
938 }
939
940 prompt = strings.TrimSpace(prompt)
941 if prompt == "" {
942 return database.Chat{}, xerrors.New("prompt is required")
943 }
944
945 title = strings.TrimSpace(title)
946 if title == "" {
947 title = subagentFallbackChatTitle(prompt)
948 }
949
950 rootChatID := parent.ID
951 if parent.RootChatID.Valid {
952 rootChatID = parent.RootChatID.UUID
953 }
954
955 modelConfigID := parent.LastModelConfigID
956 if opts.modelConfigIDOverride != nil {
957 modelConfigID = *opts.modelConfigIDOverride
958 }
959 if modelConfigID == uuid.Nil {
960 return database.Chat{}, xerrors.New("model config is required")
961 }
962 childAPIKeyID, err := p.delegatedAPIKeyIDForSubagent(ctx)
963 if err != nil {
964 return database.Chat{}, err
965 }
966
967 childPlanMode := parent.PlanMode
968 if opts.planModeOverride != nil {
969 childPlanMode = *opts.planModeOverride
970 }
971
972 mcpServerIDs := parent.MCPServerIDs
973 if isExploreSubagentMode(opts.chatMode) {
974 mcpServerIDs = slices.Clone(opts.inheritedMCPServerIDs)
975 }
976 if mcpServerIDs == nil {
977 mcpServerIDs = []uuid.UUID{}
978 }
979
980 labelsJSON, err := json.Marshal(database.StringMap{})
981 if err != nil {
982 return database.Chat{}, xerrors.Errorf("marshal labels: %w", err)
983 }
984 childSystemPrompt := SanitizePromptText(opts.systemPrompt)
985 // Resolve the deployment prompt before opening the transaction so
986 // child chat creation does not hold one DB connection while waiting

Calls 15

checkUsageLimitMethod · 0.95
signalWakeMethod · 0.95
MarshalPartsFunction · 0.92
ChatMessageTextFunction · 0.92
isExploreSubagentModeFunction · 0.85
SanitizePromptTextFunction · 0.85
appendChatMessageFunction · 0.85
newChatMessageFunction · 0.85