Adds LoopConfig.MaxToolResultLen with the same config > env > default precedence as the existing MaxToolConcurrency / MaxAgentDepth knobs: 1. Runtime.AgentLoop.MaxToolResultLen (>0) — config wins 2. HARNESS_MAX_TOOL_RESULT_LEN env (>0) — env fallback 3. defaultMaxToolResultLen (4000) — unchanged for back-compat The previous 4000-char cap was conservative for agents doing real engineering work (read_file, web_fetch, browser, bash output). Setting MaxToolResultLen to 16000-25000 lets a typical source file or test run land in-context without hitting spillover; spill remains the safety net for genuinely large outputs. No behaviour change for callers that don't set the field.
28 lines
859 B
Go
28 lines
859 B
Go
package runtime
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
// maxToolResultLen returns the per-result truncation cap (chars) for tool
|
|
// results in the in-context message history. Precedence:
|
|
// 1. Runtime.AgentLoop.MaxToolResultLen (>0) — config wins.
|
|
// 2. HARNESS_MAX_TOOL_RESULT_LEN env var (>0) — env fallback.
|
|
// 3. defaultMaxToolResultLen (4000).
|
|
//
|
|
// Tool results longer than this are truncated (or spilled to disk via
|
|
// spillConfig when supplied). 4000 is conservative; engineering-style
|
|
// agents that read source files and run tests typically want 16000-25000.
|
|
func (r *Runtime) maxToolResultLen() int {
|
|
if r.AgentLoop.MaxToolResultLen > 0 {
|
|
return r.AgentLoop.MaxToolResultLen
|
|
}
|
|
if v := os.Getenv("HARNESS_MAX_TOOL_RESULT_LEN"); v != "" {
|
|
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
|
return n
|
|
}
|
|
}
|
|
return defaultMaxToolResultLen
|
|
}
|