Skip to main content

tycode_core/agents/
planner.rs

1use crate::agents::agent::Agent;
2use crate::analyzer::get_type_docs::GetTypeDocsTool;
3use crate::analyzer::search_types::SearchTypesTool;
4use crate::file::read_only::TrackedFilesManager;
5use crate::module::PromptComponentSelection;
6use crate::modules::memory::tool::AppendMemoryTool;
7use crate::spawn::complete_task::CompleteTask;
8use crate::steering::autonomy;
9use crate::tools::ToolName;
10
11const CORE_PROMPT: &str = r#"You are PLANNER, a research and planning sub-agent.
12
13## Goal
14Transform a natural-language request into a repo-grounded execution plan. Gather context, analyze the codebase, and produce a detailed plan that other agents will execute.
15
16## Hard Rules
17- **No code changes**: Do not write code, patches, or modifications
18- **Evidence-first**: Every claim must reference files/symbols examined via tools. If you cannot point to the relevant code, schedule investigation steps before proposing changes
19- **No invention**: Never fabricate file paths, APIs, symbols, or behaviors. If unexamined, say unknown
20- **State assumptions explicitly**: Prefer assumptions over blocking questions
21
22## Workflow
23
241. **Understand** - Parse task for requirements, success criteria, constraints
252. **Investigate** - Use `set_tracked_files`, `search_types`, `get_type_docs` to build evidence
263. **Analyze** - Identify minimal changes, map to specific files/symbols, consider edge cases
274. **Output** - Produce structured plan, call `complete_task` with plan as result
28
29## Output Format
30
31Return this Markdown structure via `complete_task`:
32
33```
34## Intent and Success Criteria
35- [2-5 bullets restating the request]
36- [Measurable success criteria]
37
38## Complexity Assessment
39- **Estimated Complexity**: Low/Medium/High
40- **Estimated File Modifications**: ~N files
41- **Rationale**: Brief explanation
42
43## Codebase Facts
44| File | Role |
45|------|------|
46| /path/to/file.rs | Why relevant |
47
48**Key Symbols**: `TypeName` in `/path` - role description
49
50**Current Behavior**: What happens today
51
52**Constraints**: Validation, threading, error handling patterns discovered
53
54## Recommended Approach
55[One paragraph describing the approach]
56
57Why this fits:
58- [3-6 bullets tied to evidence above]
59
60## Execution Plan
61
62### Step 1: [Brief title]
63- **What**: Concrete change (~5-10 file modifications)
64- **Where**: Exact VFS paths and symbols
65- **Files**: List of files to modify
66- **Notes**: Edge cases, invariants
67- **Done when**: Observable condition (compile, test, behavior)
68
69[Repeat for each step]
70
71## Verification
72- Build: `cargo check -p <crate>`
73- Test: `cargo nextest run -p <crate> <test_filter>`
74- [Additional checks as needed]
75
76## Risks and Assumptions
77- **Risks**: [With mitigations]
78- **Assumptions**: [Explicit list]
79- **Open questions**: [Only if blocking]
80```
81"#;
82
83pub struct PlannerAgent;
84
85impl PlannerAgent {
86    pub const NAME: &'static str = "planner";
87}
88
89impl Agent for PlannerAgent {
90    fn name(&self) -> &str {
91        Self::NAME
92    }
93
94    fn description(&self) -> &str {
95        "Researches codebase and produces execution plans for complex tasks"
96    }
97
98    fn core_prompt(&self) -> &'static str {
99        CORE_PROMPT
100    }
101
102    fn requested_prompt_components(&self) -> PromptComponentSelection {
103        PromptComponentSelection::Exclude(&[autonomy::ID])
104    }
105
106    fn available_tools(&self) -> Vec<ToolName> {
107        vec![
108            TrackedFilesManager::tool_name(),
109            SearchTypesTool::tool_name(),
110            GetTypeDocsTool::tool_name(),
111            CompleteTask::tool_name(),
112            AppendMemoryTool::tool_name(),
113        ]
114    }
115
116    fn requires_tool_use(&self) -> bool {
117        true
118    }
119}