Skip to content

Commit 5c6ed00

Browse files
committed
Redesign RLM perception loop as flow-state REPL
1 parent 3dd45f9 commit 5c6ed00

5 files changed

Lines changed: 386 additions & 91 deletions

File tree

crates/dspy-rs/src/modules/rlm/exec.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,9 @@ fn truncate_capture_output(text: &str, max_chars: usize) -> String {
287287

288288
let head: String = text.chars().take(head_len).collect();
289289
let tail: String = text.chars().skip(total.saturating_sub(tail_len)).collect();
290+
let truncation_notice = format!("... [STDOUT TRUNCATED: Exceeded {max_chars} char threshold]");
290291

291-
format!(
292-
"{head}\n[output truncated at {max_chars} chars - full content in variable. pass to llm_query() to analyze]\n{tail}"
293-
)
292+
format!("{head}\n{tail}\n{truncation_notice}")
294293
}
295294

296295
#[cfg(test)]
@@ -342,11 +341,10 @@ mod tests {
342341
let globals = PyDict::new(py).unbind();
343342
let output = execute_repl_code(py, &globals, "print('abcdefghijklmnopqrstuvwxyz')", 10)
344343
.expect("exec");
345-
assert!(output.contains(
346-
"[output truncated at 10 chars - full content in variable. pass to llm_query() to analyze]"
347-
));
344+
assert!(output.contains("... [STDOUT TRUNCATED: Exceeded 10 char threshold]"));
348345
assert!(output.starts_with("abcde"));
349-
assert!(output.ends_with("wxyz\n"));
346+
assert!(output.contains("wxyz\n"));
347+
assert!(output.ends_with("... [STDOUT TRUNCATED: Exceeded 10 char threshold]"));
350348
});
351349
}
352350

@@ -434,9 +432,7 @@ mod tests {
434432
)
435433
.expect_err("should fail");
436434

437-
assert!(err.contains(
438-
"[output truncated at 20 chars - full content in variable. pass to llm_query() to analyze]"
439-
));
435+
assert!(err.contains("... [STDOUT TRUNCATED: Exceeded 20 char threshold]"));
440436
assert!(err.chars().count() > 20);
441437
});
442438
}
@@ -446,7 +442,7 @@ mod tests {
446442
let text = "😀".repeat(40);
447443
let truncated = truncate_capture_output(&text, 9);
448444

449-
assert!(truncated.contains("[output truncated at 9 chars"));
445+
assert!(truncated.contains("... [STDOUT TRUNCATED: Exceeded 9 char threshold]"));
450446
assert!(truncated.is_char_boundary(truncated.len()));
451447
assert!(truncated.contains('😀'));
452448
}

0 commit comments

Comments
 (0)