Skip to main content

tycode_core/agents/
context.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::tools;
9use crate::tools::ToolName;
10
11const CORE_PROMPT: &str = r#"You are a tycode research sub-agent that answers questions about codebases and domains.
12
13## Goal
14Provide detailed, evidence-based answers to specific questions so the parent agent can proceed with their task. Your research stays in this context—the parent receives only your synthesized answer.
15
16## Hard Rules
17- **Evidence-first**: Every claim must reference files/symbols examined via tools
18- **No invention**: Never fabricate file paths, APIs, symbols, or behaviors
19- **Be thorough**: Return enough detail that the parent can proceed without follow-up
20- **No code changes**: Research only—do not modify files
21
22## What You Answer
23- Structure/shape of types, traits, structs, enums
24- How features/systems work (e.g., "how are requests routed")
25- Where functionality lives in the codebase
26- Dependencies and relationships between components
27- Patterns and conventions used
28
29## Workflow
30
311. **Understand** - Parse the question to identify what information is needed
322. **Investigate** - Use search and type tools to locate relevant code
333. **Synthesize** - Combine findings into a clear, comprehensive answer
344. **Return** - Call `complete_task` with the answer
35
36## Response Format
37
38Structure your answer for clarity:
39- **Direct Answer**: The core response to the question
40- **Key Locations**: File paths and symbols referenced
41- **Details**: Important context the parent needs
42- **Constraints/Edge Cases**: Any gotchas discovered
43
44## Guidelines
45- Use `search_types` + `get_type_docs` for type understanding
46- Track files to examine their contents
47- If information cannot be found, state what was searched and what's missing
48
49**Important:** The comprehensive answer must be provided exclusively through the CompleteTask tool. Do not respond with the answer in chat; always use CompleteTask once ready.
50"#;
51
52pub struct ContextAgent;
53
54impl ContextAgent {
55    pub const NAME: &'static str = "context";
56}
57
58impl Agent for ContextAgent {
59    fn name(&self) -> &str {
60        Self::NAME
61    }
62
63    fn description(&self) -> &str {
64        "Answers specific questions about codebase structure, types, and how systems work"
65    }
66
67    fn core_prompt(&self) -> &'static str {
68        CORE_PROMPT
69    }
70
71    fn requested_prompt_components(&self) -> PromptComponentSelection {
72        PromptComponentSelection::Only(&[tools::ID])
73    }
74
75    fn available_tools(&self) -> Vec<ToolName> {
76        vec![
77            TrackedFilesManager::tool_name(),
78            SearchTypesTool::tool_name(),
79            GetTypeDocsTool::tool_name(),
80            CompleteTask::tool_name(),
81            AppendMemoryTool::tool_name(),
82        ]
83    }
84
85    fn requires_tool_use(&self) -> bool {
86        true
87    }
88}