diff --git a/coderd/x/chatd/subagent.go b/coderd/x/chatd/subagent.go index ead50983cc8..5e91fcb2064 100644 --- a/coderd/x/chatd/subagent.go +++ b/coderd/x/chatd/subagent.go @@ -793,8 +793,10 @@ func (p *Server) subagentTools( "wait_agent", "Wait for a spawned child agent to finish and return its response "+ "and status. Returns immediately when the agent finishes, even if "+ - "a longer timeout is set. A timeout does not stop the agent; call "+ - "wait_agent again or use list_agents to check its status.", + "a longer timeout is set. A timeout does not stop the child; it "+ + "still owns its task. Wait again or check its status with "+ + "list_agents; do not take over its work without an acknowledged "+ + "handoff.", func(ctx context.Context, args waitAgentArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { if currentChat == nil { return fantasy.NewTextErrorResponse("subagent callbacks are not configured"), nil @@ -941,11 +943,16 @@ func (p *Server) subagentTools( "message_agent", "Send a follow-up message to a previously spawned child "+ "agent. If the agent is idle, it resumes work on the "+ - "message. If the agent is busy, the message is queued and "+ - "processed after current work. Set interrupt to true to "+ - "stop the agent's current work; the message is queued and "+ - "processed next, after any already-queued messages. "+ - "After sending, use wait_agent to retrieve the response.", + "message. If it is busy, the message is queued behind its "+ + "current work and any earlier queued messages; set interrupt "+ + "to true for corrections, changed scope, or a handoff that "+ + "returns the child's task to you, so its current work stops "+ + "first. Interrupting does not clear earlier queued messages, "+ + "and the tool result does not confirm the child has stopped. "+ + "Use wait_agent to collect the child's response. A handoff is "+ + "acknowledged only when wait_agent returns the child's response "+ + "to your handoff message; a message_agent result or an "+ + "interrupting status is not an acknowledgment.", func(ctx context.Context, args messageAgentArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { if currentChat == nil { return fantasy.NewTextErrorResponse("subagent callbacks are not configured"), nil diff --git a/coderd/x/chatd/subagent_catalog.go b/coderd/x/chatd/subagent_catalog.go index b7b445ae422..1776c3c2a1b 100644 --- a/coderd/x/chatd/subagent_catalog.go +++ b/coderd/x/chatd/subagent_catalog.go @@ -21,21 +21,10 @@ const ( subagentTypeExplore = "explore" subagentTypeComputerUse = "computer_use" - defaultSystemPromptPlanningGuidance = "1. Use " + spawnAgentToolName + - " and wait_agent when delegation helps gather context. Prefer type=\"" + - subagentTypeGeneral + - "\" for substantial delegated research, analysis, reasoning, review, " + - "planning support, or implementation. Use type=\"" + subagentTypeGeneral + - "\" even for read-only work when the task is open-ended, multi-step, " + - "parallel, requires synthesis, or may later need edits. When planning, " + - "type=\"" + subagentTypeGeneral + - "\" remains non-mutating until implementation is approved. Use type=\"" + - subagentTypeExplore + - "\" only for narrow repository-local read-only code discovery or code " + - "tracing, such as locating files, callsites, or a bounded existing flow. " + - "Do not use type=\"" + subagentTypeExplore + - "\" for generic research, broad architecture analysis, planning synthesis, " + - "external or web research, parallel research, or tasks that may need edits." + defaultSystemPromptPlanningGuidance = "1. Delegate context gathering with " + + spawnAgentToolName + " when it helps, only after defining the question or " + + "deliverable, scope, available inputs, and completion criteria. Follow the " + + spawnAgentToolName + " description for agent selection and ownership." ) // unbilledSubagentToolNames excludes parent-side orchestration because @@ -308,8 +297,10 @@ func buildSpawnAgentDescription( currentChat database.Chat, ) string { availableDefs := availableSubagentDefinitions(ctx, p, currentChat) - description := "Spawn a delegated child subagent to work on a clearly scoped, " + - "independent task in parallel. Use the type field to choose " + + description := "Assign a clearly scoped, independent task to a child agent, " + + "including the criteria that complete it. Spawn only once you can define " + + "the assignment; gather missing context first rather than investigating " + + "alongside the child. Use the type field to choose " + "the right specialist. Available type values: " + formatSubagentDefinitionsWithDescriptionOverrides(availableDefs, nil) + ". Do not use this for " + "simple or quick operations you can handle directly with execute, " + @@ -324,19 +315,26 @@ func buildSpawnAgentDescription( "Do not use type=\"" + subagentTypeExplore + "\" for generic research, broad architecture analysis, planning " + "synthesis, external or web research, parallel research, or tasks that " + - "may need edits. Be careful when running parallel subagents: if two " + - "subagents modify the same files they will conflict with each other, " + - "so ensure parallel subagent tasks are independent. The child agent " + - "receives the same workspace tools but cannot spawn its own subagents. " + + "may need edits. Each delegated task has one owner until its result " + + "is returned or a handoff is acknowledged. While a child owns a task, do " + + "only work independent of it; do not investigate, implement, or edit that " + + "task yourself. Separate files do not make tasks independent when they " + + "depend on an unresolved shared contract. Independent work that itself " + + "qualifies for delegation is another assignment, not your own. When your " + + "next step depends on a child's result, or its report will answer the " + + "question, use wait_agent rather than doing that work yourself. Treat a " + + "report's findings and cited locations as read context; re-check only a " + + "specific gap, contradiction, suspected change, or the exact content an " + + "edit needs. The child cannot spawn its own subagents; its tools depend " + + "on its type and mode. " + "You may optionally set model_config_id (a model config UUID from " + listSubagentModelsToolName + ") to run the child on a specific model " + "instead of the configured default, and reasoning_effort to pin the " + "child's reasoning effort; both apply only to type \"" + subagentTypeGeneral + "\" and type \"" + subagentTypeExplore + "\". " + - "After spawning, use wait_agent to retrieve the result. Agents persist " + - "after completion; reuse an agent via message_agent for follow-up work " + - "when it already has relevant context. Spawned agents are your " + - "responsibility: do not abandon one in a working state (running); " + + "Agents persist after completion; reuse an agent via message_agent for " + + "follow-up work when it already has relevant context. Spawned agents are " + + "your responsibility: do not abandon one in a working state (running); " + "retrieve its result, redirect it with message_agent, or stop " + "it with interrupt_agent." if currentChat.PlanMode.Valid && currentChat.PlanMode.ChatPlanMode == database.ChatPlanModePlan { diff --git a/coderd/x/chatd/subagent_internal_test.go b/coderd/x/chatd/subagent_internal_test.go index b56be701f91..9f91bac2d24 100644 --- a/coderd/x/chatd/subagent_internal_test.go +++ b/coderd/x/chatd/subagent_internal_test.go @@ -2604,17 +2604,6 @@ func TestSpawnAgent_ExploreFallsBackWhenOverrideCredentialsAreUnavailable(t *tes require.Equal(t, currentTurnModel.ID, childChat.LastModelConfigID) } -func TestDefaultSystemPromptPlanningGuidance_SteersSubagentSelection(t *testing.T) { - t.Parallel() - - require.Contains(t, defaultSystemPromptPlanningGuidance, `Prefer type="general" for substantial delegated research, analysis, reasoning, review, planning support, or implementation`) - require.Contains(t, defaultSystemPromptPlanningGuidance, `Use type="general" even for read-only work when the task is open-ended, multi-step, parallel, requires synthesis, or may later need edits`) - require.Contains(t, defaultSystemPromptPlanningGuidance, `Use type="explore" only for narrow repository-local read-only code discovery or code tracing`) - require.Contains(t, defaultSystemPromptPlanningGuidance, `Do not use type="explore" for generic research, broad architecture analysis, planning synthesis, external or web research, parallel research, or tasks that may need edits`) - require.NotContains(t, defaultSystemPromptPlanningGuidance, "research the codebase") - require.NotContains(t, defaultSystemPromptPlanningGuidance, "Reserve type=\"general\" for writable delegated work") -} - func TestSpawnAgent_DescriptionListsAllAvailableTypes(t *testing.T) { t.Parallel() @@ -4204,8 +4193,6 @@ func TestWaitAgentToolSchema(t *testing.T) { require.True(t, ok) assert.Equal(t, "integer", timeoutSeconds["type"]) assert.Equal(t, "Defaults to 5 minutes.", timeoutSeconds["description"]) - assert.Contains(t, tool.Info().Description, "Returns immediately when the agent finishes") - assert.Contains(t, tool.Info().Description, "A timeout does not stop the agent") } func TestWaitAgentTimeoutReturnsInformationalPayload(t *testing.T) {