tycode_core/agents/
coder.rs1use crate::agents::agent::Agent;
2use crate::analyzer::get_type_docs::GetTypeDocsTool;
3use crate::analyzer::search_types::SearchTypesTool;
4use crate::file::modify::delete_file::DeleteFileTool;
5use crate::file::modify::replace_in_file::ReplaceInFileTool;
6use crate::file::modify::write_file::WriteFileTool;
7use crate::file::read_only::TrackedFilesManager;
8use crate::module::PromptComponentSelection;
9use crate::modules::execution::RunBuildTestTool;
10use crate::modules::memory::tool::AppendMemoryTool;
11use crate::skills::tool::InvokeSkillTool;
12use crate::spawn::complete_task::CompleteTask;
13use crate::spawn::SpawnAgent;
14use crate::steering::autonomy;
15use crate::tools::ToolName;
16
17const CORE_PROMPT: &str = r#"You are a Tycode sub-agent responsible for executing assigned coding tasks. Follow this workflow to execute the task:
18
191. Understand the task and determine files to modify. If the task is not clear, use the 'complete_task' tool to fail the task and request clarification. If more context is needed use tools such as 'set_tracked_files' to read files
202. Use 'set_tracked_files' to read files, 'write_file' to create new files, and 'modify_file' to apply a patch to an existing file. Ensure that all changes comply with the style mandates; your changes may be rejected by another agent specifically focused on ensuring compliance with the style mandates so it is critical that you follow the style mandates.
213. After each change, re-read the entire modified file to ensure your change applied as you expected and that all style mandates have been obeyed. Correct any style mandate compliance failures in lines you have modified.
224. Once all changes are complete, use the 'complete_task' tool to indicate success. If you cannot complete the task for any reason use the 'complete_task' tool to fail the task.
23
24## It is okay to fail
25- It is ok to fail. If you cannot complete the task as instructed, fail the task. This will let the parent agent (with more context) figure out what to do and how to recover. The parent agent may need to make a new plan based on your discovery!
26- You can fail a task be using the complete_task tool with success = false. Give a detailed description of why you failed in the complete_task tool call so the parent agent can understand the issue.
27- You are an automated agent and will not be able to interact with the user or ask for help; do your best or fail.
28- Critical: Never deviate from the assigned task or plan. Do not change implementation approaches. Changing implementation approaches will cause signficant harm. Failing a task is harmless.
29
30## Debugging
31- It is critical that you never make conjectures or attempt to fix an "unproven" bug. For example, if you theorize there is a race condition but cannot write an irrefutable proof, do not attempt to fix it.
32- You have access to a debugging agent. Any bug that is not immediately obvious should be delegated to the debugging agent.
33- Spawn the debugging agent with a detailed description of the bug and any steps or hints to reproduce it. The debug agent will attempt to root cause the bug and give back a detailed root cause"#;
34
35pub struct CoderAgent;
36
37impl CoderAgent {
38 pub const NAME: &'static str = "coder";
39
40 pub fn new() -> Self {
41 Self
42 }
43}
44
45impl Agent for CoderAgent {
46 fn name(&self) -> &str {
47 Self::NAME
48 }
49
50 fn description(&self) -> &str {
51 "Executes assigned coding tasks, applying patches and managing files"
52 }
53
54 fn core_prompt(&self) -> &'static str {
55 CORE_PROMPT
56 }
57
58 fn requested_prompt_components(&self) -> PromptComponentSelection {
59 PromptComponentSelection::Exclude(&[autonomy::ID])
60 }
61
62 fn available_tools(&self) -> Vec<ToolName> {
63 vec![
64 TrackedFilesManager::tool_name(),
65 WriteFileTool::tool_name(),
66 ReplaceInFileTool::tool_name(),
67 DeleteFileTool::tool_name(),
68 SpawnAgent::tool_name(),
69 RunBuildTestTool::tool_name(),
70 CompleteTask::tool_name(),
71 SearchTypesTool::tool_name(),
72 GetTypeDocsTool::tool_name(),
73 AppendMemoryTool::tool_name(),
74 InvokeSkillTool::tool_name(),
75 ]
76 }
77
78 fn requires_tool_use(&self) -> bool {
79 true
80 }
81}