updates
ober
b4594816b4af6057ca09e88cdbe4dee1bd529df8
--- a/src/jcode/core/agent.ss +++ b/src/jcode/core/agent.ss @@ -297,7 +297,7 @@ Be concise. Prefer edit over write for modifying existing files. (def *max-tool-rounds* 100) (def *max-tool-lines* 2000) (def *max-tool-bytes* 51200) ;; 50KB -(def *local-max-tool-bytes* 2048) +(def *local-max-tool-bytes* 768) (def (refresh-system-prompt messages) "Replace the leading system message (if any) with a fresh one reflecting --- a/src/jcode/core/compaction.ss +++ b/src/jcode/core/compaction.ss @@ -72,20 +72,28 @@ (def (effective-compaction-budget win) "Return the message-history budget after reserving fixed prompt overhead. - Small local tool-calling models spend part of every request on the system - prompt, JSON envelope, and tool schemas; message-only estimates must leave - room for that overhead or compaction fires too late." + Small local tool-calling models spend most of every request on the system + prompt, JSON envelope, and tool schemas. Reserve that fixed overhead so + message-history compaction fires before local prefill crosses the working + window." (cond - ((and win (<= win 4096)) (max 1024 (- win 1000))) + ((and win (<= win 4096)) (max 512 (- win 2500))) (else win))) (def (should-compact? messages model-id) - (let ((auto (compaction-config 'auto)) - (pct (compaction-config 'trigger_pct)) - (win (effective-compaction-budget (model-context-window model-id))) - (est (estimate-message-tokens messages))) - (and auto win pct (> est 0) - (>= (* 100 est) (* pct win))))) + (let* ((auto (compaction-config 'auto)) + (pct (compaction-config 'trigger_pct)) + (win (effective-compaction-budget (model-context-window model-id))) + (est (estimate-message-tokens messages)) + (yes? (and auto win pct (> est 0) + (>= (* 100 est) (* pct win))))) + (when yes? + (log-info logger "trigger" + `((model . ,model-id) + (estimate . ,est) + (budget . ,win) + (trigger_pct . ,pct)))) + yes?)) (def (compact-messages messages) "Return a new message list with older bulky content stubbed out. Safe --- a/test/run.ss +++ b/test/run.ss @@ -767,8 +767,22 @@ ;; ── compaction strategies (Phase 4) ──────────────────────────────── (section "=== compaction strategies ===") -(check! "effective budget small reserves overhead" (effective-compaction-budget 3072) 2072) +(check! "effective budget small reserves overhead" (effective-compaction-budget 3072) 572) (check! "effective budget large unchanged" (effective-compaction-budget 128000) 128000) +(check! "small compaction stays off for fresh prompt" + (should-compact? + (list (make-system-message (make-string 1600 #\s)) + (make-user-message "find bugs")) + "/Users/user/models/qwen3-coder-next-mlx") + #f) +(check! "small compaction triggers after one bulky tool result" + (should-compact? + (list (make-system-message (make-string 1600 #\s)) + (make-user-message "find bugs") + (make-assistant-message "" (list (make-tool-call "read" "{}"))) + (make-tool-result "read-1" (make-string 768 #\r))) + "/Users/user/models/qwen3-coder-next-mlx") + #t) (define (asst-tc content) (make-assistant-message content (list (make-tool-call "read" "{}"))))