Skip to main content

gproxy_protocol/transform/openai/compact/
utils.rs

1pub const COMPACT_MAX_OUTPUT_TOKENS: u64 = 16_384;
2
3pub const COMPACT_SYSTEM_INSTRUCTION_PREFIX: &str = "You are performing context compaction. Produce a concise, loss-minimized compacted state that preserves facts, decisions, constraints, tool outcomes, and unresolved tasks.";
4
5pub const CLAUDE_COMPACT_SYSTEM_INSTRUCTION_PREFIX: &str = "Claude has native compaction support. Prefer Claude-native compaction behavior and preserve compaction semantics.";
6
7fn prepend_prefix(prefix: &str, text: Option<String>) -> String {
8    match text {
9        Some(text) if !text.is_empty() => format!("{prefix}\n\n{text}"),
10        _ => prefix.to_string(),
11    }
12}
13
14pub fn compact_system_instruction(text: Option<String>) -> String {
15    prepend_prefix(COMPACT_SYSTEM_INSTRUCTION_PREFIX, text)
16}
17
18pub fn claude_compact_system_instruction(text: Option<String>) -> String {
19    let text = compact_system_instruction(text);
20    prepend_prefix(CLAUDE_COMPACT_SYSTEM_INSTRUCTION_PREFIX, Some(text))
21}