feat: enhance memory section guide and improve search tool descriptions for clarity

This commit is contained in:
xiaoxixi 2026-05-11 18:01:25 +08:00
parent ac2c1e0fe0
commit 1e69fa3bd1
3 changed files with 35 additions and 9 deletions

View File

@ -300,7 +300,7 @@ impl PromptSection for RuntimeSection {
}
}
/// Injects relevant knowledge memories into the system prompt.
/// Injects memory system guide and relevant knowledge memories into the system prompt.
pub struct MemorySection;
impl PromptSection for MemorySection {
@ -309,11 +309,28 @@ impl PromptSection for MemorySection {
}
fn build(&self, ctx: &PromptContext<'_>) -> String {
let guide = r#"## 记忆系统
###
- **Knowledge**
- **Timeline线** timeline_recall
###
- **memory_recall** query
- **timeline_recall** session_id
###
使 `memory_store`
-
- 使
-
"#;
match ctx.memory_context {
Some(context) if !context.is_empty() => {
format!("## 记忆上下文\n\n{}", context)
format!("{}\n\n### 记忆上下文\n\n{}", guide, context)
}
_ => String::new(),
_ => guide.to_string(),
}
}
}

View File

@ -59,7 +59,7 @@ impl Tool for ContentSearchTool {
}
fn description(&self) -> &str {
"Search file contents by regex or text pattern. Uses ripgrep (rg) if available, falls back to grep, then pure Rust."
"Search file contents by regex or text pattern. Internally uses ripgrep (rg) for fast searching — if rg is not available, falls back to grep, then pure Rust. Supports context lines, file filtering, and case-sensitivity options."
}
fn parameters_schema(&self) -> serde_json::Value {

View File

@ -56,7 +56,7 @@ impl Tool for FileSearchTool {
}
fn description(&self) -> &str {
"Search for files by glob pattern (e.g. '*.rs', 'test_*.rs'). Uses fd if available, falls back to find, then pure Rust."
"Search for files by glob pattern (e.g. '*.rs', 'test_*.rs'). Internally uses fd (fast find) for efficient searching — if fd is not available, falls back to the find command, then pure Rust glob matching."
}
fn parameters_schema(&self) -> serde_json::Value {
@ -130,11 +130,19 @@ impl FileSearchTool {
case_sensitive: bool,
max_results: usize,
) -> anyhow::Result<Vec<String>> {
if which::which("fd").is_ok() {
match self.search_with_fd(pattern, dir, case_sensitive, max_results).await {
let fd_cmd = if which::which("fd").is_ok() {
"fd"
} else if which::which("fdfind").is_ok() {
"fdfind"
} else {
""
};
if !fd_cmd.is_empty() {
match self.search_with_fd(pattern, dir, case_sensitive, max_results, fd_cmd).await {
Ok(lines) if !lines.is_empty() => return Ok(lines),
Ok(_) => {},
Err(e) => tracing::warn!("fd failed: {}, falling back", e),
Err(e) => tracing::warn!("{} failed: {}, falling back", fd_cmd, e),
}
}
@ -156,8 +164,9 @@ impl FileSearchTool {
dir: &str,
case_sensitive: bool,
max_results: usize,
fd_cmd: &str,
) -> anyhow::Result<Vec<String>> {
let mut cmd = Command::new("fd");
let mut cmd = Command::new(fd_cmd);
cmd.arg("--search-path").arg(dir)
.arg("--glob").arg(pattern)
.arg("--color").arg("never")