Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,22 @@ pub(crate) mod tests {
c
}

#[test]
fn web_search_notice_only_in_daily_mode_when_enabled_but_missing() {
let dir = tempfile::tempdir().unwrap();
let sessions = dir.path().join("sessions");
let mut cfg = test_config("http://127.0.0.1:9/v1");
// An unknown provider never registers, whatever keys this machine has.
cfg.web_search.provider = "nope".into();
let mut agent = Agent::new(cfg, dir.path(), &sessions).unwrap();
assert!(crate::commands::web_search_missing_notice(&agent).is_none());
agent.set_daily_mode(true);
let n = crate::commands::web_search_missing_notice(&agent).unwrap();
assert!(n.contains("\"nope\""));
agent.config.web_search.enabled = false;
assert!(crate::commands::web_search_missing_notice(&agent).is_none());
}

#[tokio::test]
async fn full_turn_with_tool_call_and_resume() {
let dir = tempfile::tempdir().unwrap();
Expand Down
24 changes: 24 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ pub fn daily_toggle_notice(enabled: bool) -> &'static str {
}
}

/// Why `web_search` is missing in daily mode, or None when it is registered
/// or the user turned it off (`[web_search] enabled = false`).
///
/// The tool is left out quietly when no DeepSeek key resolves, and a daily
/// session without search falls back to guessing or to `web_fetch` on URLs
/// it already knows, so say it once where the user can see it.
pub fn web_search_missing_notice(agent: &crate::agent::Agent) -> Option<String> {
let s = &agent.config.web_search;
if !agent.daily_mode() || !s.enabled || agent.registry.get("web_search").is_some() {
return None;
}
Some(if s.provider != "deepseek" {
format!(
"web_search 未启用:不支持的 provider \"{}\"(目前只支持 deepseek)",
s.provider
)
} else {
"web_search 未启用:找不到 DeepSeek API key。在 ~/.limbo/config.toml 的 [web_search] 里设 \
api_key,或 `limbo auth` 登录 deepseek,或设置 DEEPSEEK_API_KEY;不需要搜索可设 \
[web_search] enabled = false"
.to_string()
})
}

pub fn daily_only_notice(command: &str) -> String {
format!("{command} 只在 daily 模式可用(/daily-mode on 开启)")
}
Expand Down
10 changes: 9 additions & 1 deletion src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,12 @@ impl Repl {
},
"daily-mode" => match parse_toggle(arg, agent.daily_mode()) {
None => self.p.line(cmds::DAILY_USAGE),
Some(on) if agent.set_daily_mode(on) => self.p.line(cmds::daily_toggle_notice(on)),
Some(on) if agent.set_daily_mode(on) => {
self.p.line(cmds::daily_toggle_notice(on));
if let Some(n) = cmds::web_search_missing_notice(agent) {
self.p.line(&n);
}
}
Some(on) => self.p.line(&cmds::unchanged_notice("Daily mode ", on)),
},
"memory" | "learn" if !agent.daily_mode() => {
Expand Down Expand Up @@ -779,6 +784,9 @@ pub async fn run_repl(agent: Agent, json_mode: bool) -> i32 {
if let Some(g) = pump::live_goal(a) {
println!("🎯 goal:{}({})", g.text, g.status);
}
if let Some(n) = cmds::web_search_missing_notice(a) {
println!("{n}");
}
}
}
let (line_tx, mut lines) = mpsc::unbounded_channel::<Option<String>>();
Expand Down
3 changes: 2 additions & 1 deletion src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ impl MemorySnapshot {
}
Some(format!(
"\n\n<memory>\nPersistent memory from earlier sessions (a snapshot taken when this session started; \
facts the user states now take precedence):\n\n{}\n</memory>\n",
facts the user states now take precedence). Apply each entry where it fits the current request; a \
preference about how to run work tasks does not turn a plain question into a task:\n\n{}\n</memory>\n",
sections.join("\n\n")
))
}
Expand Down
33 changes: 31 additions & 2 deletions src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ const GUIDELINES_TAIL: &str = "- Use read to examine files before editing\n- Use
(edits[].old_text must match exactly)\n- Use write only for new files or complete rewrites\n- Be concise in your \
responses\n- Show file paths clearly when working with files";

const DAILY_GUIDELINES_TAIL: &str = "- For current facts, search (web_search) and read the sources (web_fetch) \
before answering; cite the URLs you relied on\n- Save substantial outputs (notes, reports, drafts) as files in the \
/// Daily mode answers a lot of plain questions. Without this line, models
/// with a shell treat "explain X" as "prove X on this machine" and spend a
/// tool call per claim before replying.
const DAILY_ANSWER_DIRECTLY: &str = "- Answer questions you can answer from your own knowledge (concepts, \
explanations, opinions, comparisons) directly, without tools. Use tools only when the answer depends on the user's \
files, this machine, the web or current facts, or when the user asks you to check or run something\n- When you do \
use tools, make independent calls together in one step instead of one call per step";

const DAILY_GUIDELINES_TAIL: &str = "- Save substantial outputs (notes, reports, drafts) as files in the \
working directory and give their paths\n- Reply in the user's language; lead with the answer and keep it concise";

pub fn first_sentence(d: &str) -> &str {
Expand Down Expand Up @@ -84,6 +91,16 @@ pub fn build_system_prompt_with(
if has("task") {
s.push_str("\n- Delegate self-contained research or side work to a subagent with task; run several in parallel when they are independent");
}
if daily {
s.push('\n');
s.push_str(DAILY_ANSWER_DIRECTLY);
// Only name web_search when it is registered (it needs a provider key).
s.push_str(if has("web_search") {
"\n- For current facts, search (web_search) and read the sources (web_fetch) before answering; cite the URLs you relied on"
} else {
"\n- For current facts, read the sources (web_fetch) before answering; cite the URLs you relied on"
});
}
s.push('\n');
s.push_str(if daily {
DAILY_GUIDELINES_TAIL
Expand Down Expand Up @@ -150,5 +167,17 @@ mod tests {
let p = build_system_prompt(&reg, Path::new("/nonexistent"));
assert!(p.contains("- read: Read the contents of a file"));
assert!(!p.contains("- bash:"));
assert!(!p.contains("without tools"));
}

#[test]
fn daily_prompt_answers_directly_and_names_only_registered_search() {
let mut reg = ToolRegistry::core(true);
reg.daily_mode = true;
let p = build_system_prompt(&reg, Path::new("/nonexistent"));
assert!(p.contains("directly, without tools"));
assert!(p.contains("independent calls together in one step"));
assert!(!p.contains("web_search"));
assert!(p.contains("read the sources (web_fetch)"));
}
}
3 changes: 2 additions & 1 deletion src/tools/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const DESCRIPTION: &str = "Save durable facts to persistent memory that survives
injected into every future session, so keep entries compact and high-signal. Writes take effect from the next \
session.\n\nHOW: make all changes to one target in ONE call via 'operations' (each item: {action, content?, \
old_text?}). The batch applies atomically and the character limit is checked only on the final result, so one \
call can remove or patch stale entries to free room and add new ones.\n\nWHEN: only for facts that hold in every \
call can remove or patch stale entries to free room and add new ones. When an entry on the same subject exists, patch it instead of adding a \
near-duplicate.\n\nWHEN: only for facts that hold in every \
session regardless of task: who the user is, their preferences and style, stable environment facts, standing \
conventions, corrections the user made.\n\nSKIP: trivial or easily re-discovered facts, raw data, task progress, \
completed-work logs, temporary TODOs. Reusable procedures belong in a skill.\n\nTARGETS: 'user' = who the user is \
Expand Down
7 changes: 7 additions & 0 deletions src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ impl App {
),
);
}
if let Some(n) = app.agent.as_ref().and_then(cmds::web_search_missing_notice) {
app.notice(NoticeKind::Warn, n);
}
if !app.steer.is_empty() {
app.notice(
NoticeKind::Info,
Expand Down Expand Up @@ -1790,6 +1793,7 @@ impl App {
Some(on) if a.set_daily_mode(on) => {
self.skills_scope = (a.workdir.clone(), on);
self.skills = discover_skills(&a.workdir, on);
let search_missing = cmds::web_search_missing_notice(a);
self.notice(
NoticeKind::Info,
if on {
Expand All @@ -1799,6 +1803,9 @@ impl App {
},
);
self.notice(NoticeKind::Info, cmds::daily_toggle_notice(on));
if let Some(n) = search_missing {
self.notice(NoticeKind::Warn, n);
}
}
Some(on) => self.toast(cmds::unchanged_notice("Daily mode ", on)),
}
Expand Down
Loading