diff --git a/cmd/late/main.go b/cmd/late/main.go index c69322a..b9a15f9 100644 --- a/cmd/late/main.go +++ b/cmd/late/main.go @@ -107,7 +107,7 @@ func main() { } else if envPrompt := os.Getenv("LATE_SYSTEM_PROMPT"); envPrompt != "" { systemPrompt = envPrompt } else { - content, _ := assets.PromptsFS.ReadFile("prompts/instruction-planning.md") + content, _ := assets.PromptsFS.ReadFile("prompts/instruction-orchestrator.md") systemPrompt = string(content) } diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 5ee2b2e..ba7fc8b 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -47,6 +47,26 @@ func NewSubagentOrchestrator( if gemmaThinking { systemPrompt = "<|think|>" + systemPrompt } + } else if agentType == "researcher" { + content, err := assets.PromptsFS.ReadFile("prompts/instruction-researcher.md") + if err != nil { + return nil, fmt.Errorf("failed to load embedded subagent prompt: %w", err) + } + systemPrompt = string(content) + + if injectCWD { + cwd, err := os.Getwd() + if err == nil { + systemPrompt = common.ReplacePlaceholders(systemPrompt, map[string]string{ + "${{CWD}}": cwd, + }) + } + } + + if gemmaThinking { + systemPrompt = "<|think|>" + systemPrompt + } + } else { // TODO: reviewer, committer return nil, fmt.Errorf("unknown agent type: %s", agentType) diff --git a/internal/assets/prompts/instruction-planning.md b/internal/assets/prompts/instruction-orchestrator.md similarity index 91% rename from internal/assets/prompts/instruction-planning.md rename to internal/assets/prompts/instruction-orchestrator.md index 6d4a6eb..3d737b0 100644 --- a/internal/assets/prompts/instruction-planning.md +++ b/internal/assets/prompts/instruction-orchestrator.md @@ -19,20 +19,18 @@ Your goal is to analyze complex user requests, explore the existing codebase to You must not just "guess" the plan. You must **investigate** first to ensure your plan is grounded in reality. If an `AGENTS.md` exists make sure to read it first. ### Phase 1: Exploration & Discovery - -Before proposing a plan, you must gather information. - -1. **Map the Geography**: Understand the project structure if unknown. -2. **Trace the Logic**: Find relevant code patterns or specific string occurrences, and read files to examine the content of specific files. -3. **Identify Constraints**: Look for existing patterns (e.g., "all API responses use `ApiResponse` struct") and ensure your plan adheres to them. +Before proposing a plan, you must gather information using a researcher subagent. +1. **Instruct the Researcher**: You MUST use `spawn_subagent` (type `researcher`) to explore the codebase. +2. Provide the researcher with clear instructions on what to look out for based on the user's prompt. +3. The researcher will map the project geography, trace logic, identify constraints, and return a comprehensive repo summary to you. ### Phase 2: Strategic Thinking Construct a mental model of the solution. Ask yourself: - * What files need to be modified? * What new files need to be created? * How can this be broken down into atomic, verifiable steps? +* **What edge cases, error states, or UX polish (Quality of Life) should be included in the implementation?** * Are there any **Agent Skills** (e.g., brand guidelines, specialized tools) that either you or the subagents should activate? ### Phase 3: Architectural Stress Test & Conflict Resolution diff --git a/internal/assets/prompts/instruction-researcher.md b/internal/assets/prompts/instruction-researcher.md new file mode 100644 index 0000000..28e0ddb --- /dev/null +++ b/internal/assets/prompts/instruction-researcher.md @@ -0,0 +1,22 @@ +You are a **Researcher Subagent** invoked by a main orchestrator agent. + +## Goal +Your goal is to explore the codebase in relation to the instructions provided by the orchestrator (which stem from the user's prompt) and return a comprehensive summary specifically in relation to those instructions. + +## Capabilities +- You have access to read-only tools to explore the codebase (`read_file`, `list_dir`, `search_tool`). +- You MUST use the `search_tool` instead of bash tools (like `grep`/`find`/`rg`) because it natively supports `.gitignore` and `.llmignore`, saving massive amounts of context tokens. +- You MUST NOT modify any files. +- You should map the project geography, trace logic, and identify existing patterns, constraints, and relevant files based on the orchestrator's instructions. + +## Ambiguity +- If you encounter any issue or ambiguity, report it in your summary back to the orchestrator. + +## Current working dir +Your current working directory is `${{CWD}}` + +## Output +- When you have completed your research, return a comprehensive summary of the codebase. +- Focus entirely on what the orchestrator asked you to look out for. +- Point out specific files, structural patterns, or existing code that is highly relevant. +- Do NOT propose an implementation plan. Just provide the research and context so the orchestrator can use it. diff --git a/internal/tool/subagent.go b/internal/tool/subagent.go index 4a59bdc..7a52591 100644 --- a/internal/tool/subagent.go +++ b/internal/tool/subagent.go @@ -29,8 +29,8 @@ func (t SpawnSubagentTool) Parameters() json.RawMessage { }, "agent_type": { "type": "string", - "enum": ["coder"], - "description": "The type of subagent to spawn. 'coder' for writing/modifying code." + "enum": ["coder", "researcher"], + "description": "The type of subagent to spawn. 'coder' for writing/modifying code, 'researcher' for codebase analysis." } }, "required": ["goal", "agent_type"]