Support long-running agent turns
This commit is contained in:
39
src/agent.rs
39
src/agent.rs
@@ -988,6 +988,37 @@ pub(crate) fn system_prompt(model: ModelChoice, extra: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn system_prompt_reminder(model: ModelChoice, extra: &str) -> String {
|
||||
format!(
|
||||
"[System prompt reminder follows.]\n{}\n[End system prompt reminder.]",
|
||||
system_prompt(model, extra)
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn prompt_reminder_due(used: u32, last: u32) -> bool {
|
||||
used.saturating_sub(last) >= 50_000
|
||||
}
|
||||
|
||||
pub(crate) fn datetime_context() -> String {
|
||||
let when = Command::new("/bin/date")
|
||||
.arg("+%Y-%m-%d %H:%M:%S %Z")
|
||||
.output()
|
||||
.ok()
|
||||
.filter(|output| output.status.success())
|
||||
.map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned())
|
||||
.filter(|output| !output.is_empty())
|
||||
.unwrap_or_else(|| {
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs()
|
||||
.to_string()
|
||||
});
|
||||
format!(
|
||||
"Current local date and time at session start: {when}. Use this only when date or time matters."
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn try_tool_result(active: &ActiveTools) -> Result<Option<String>, String> {
|
||||
match active.results.try_recv() {
|
||||
Ok(result) => Ok(Some(result)),
|
||||
@@ -1224,6 +1255,14 @@ mod tests {
|
||||
assert!(prompt.contains(&format!("\"name\":\"{name}\"")));
|
||||
}
|
||||
assert!(prompt.ends_with("extra"));
|
||||
assert!(
|
||||
system_prompt_reminder(ModelChoice::DeepSeekV4Flash, "extra")
|
||||
.contains("[System prompt reminder follows.]")
|
||||
);
|
||||
assert!(datetime_context().starts_with("Current local date and time at session start:"));
|
||||
assert!(!prompt_reminder_due(49_999, 0));
|
||||
assert!(prompt_reminder_due(50_000, 0));
|
||||
assert!(!prompt_reminder_due(80_000, 50_000));
|
||||
|
||||
let text = "done<tool_call>read<arg_key>path</arg_key><arg_value>src/main.rs</arg_value></tool_call>";
|
||||
let (visible, calls) = parse_tool_calls(ModelChoice::Glm52, text).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user