feat: enhance memory section guide and improve search tool descriptions for clarity
This commit is contained in:
parent
ac2c1e0fe0
commit
1e69fa3bd1
@ -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;
|
pub struct MemorySection;
|
||||||
|
|
||||||
impl PromptSection for MemorySection {
|
impl PromptSection for MemorySection {
|
||||||
@ -309,11 +309,28 @@ impl PromptSection for MemorySection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn build(&self, ctx: &PromptContext<'_>) -> String {
|
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 {
|
match ctx.memory_context {
|
||||||
Some(context) if !context.is_empty() => {
|
Some(context) if !context.is_empty() => {
|
||||||
format!("## 记忆上下文\n\n{}", context)
|
format!("{}\n\n### 记忆上下文\n\n{}", guide, context)
|
||||||
}
|
}
|
||||||
_ => String::new(),
|
_ => guide.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ impl Tool for ContentSearchTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> &str {
|
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 {
|
fn parameters_schema(&self) -> serde_json::Value {
|
||||||
|
|||||||
@ -56,7 +56,7 @@ impl Tool for FileSearchTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> &str {
|
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 {
|
fn parameters_schema(&self) -> serde_json::Value {
|
||||||
@ -130,11 +130,19 @@ impl FileSearchTool {
|
|||||||
case_sensitive: bool,
|
case_sensitive: bool,
|
||||||
max_results: usize,
|
max_results: usize,
|
||||||
) -> anyhow::Result<Vec<String>> {
|
) -> anyhow::Result<Vec<String>> {
|
||||||
if which::which("fd").is_ok() {
|
let fd_cmd = if which::which("fd").is_ok() {
|
||||||
match self.search_with_fd(pattern, dir, case_sensitive, max_results).await {
|
"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(lines) if !lines.is_empty() => return Ok(lines),
|
||||||
Ok(_) => {},
|
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,
|
dir: &str,
|
||||||
case_sensitive: bool,
|
case_sensitive: bool,
|
||||||
max_results: usize,
|
max_results: usize,
|
||||||
|
fd_cmd: &str,
|
||||||
) -> anyhow::Result<Vec<String>> {
|
) -> anyhow::Result<Vec<String>> {
|
||||||
let mut cmd = Command::new("fd");
|
let mut cmd = Command::new(fd_cmd);
|
||||||
cmd.arg("--search-path").arg(dir)
|
cmd.arg("--search-path").arg(dir)
|
||||||
.arg("--glob").arg(pattern)
|
.arg("--glob").arg(pattern)
|
||||||
.arg("--color").arg("never")
|
.arg("--color").arg("never")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user