Documentation
¶
Overview ¶
Package codemode is the experimental "code mode" spike (issue #325): the model sends one execute_code call holding a short JavaScript program, the program calls upstream tools and filters their results inside a sandbox, and only its final value goes back into the context window.
It is a throw-away prototype, not a shipped feature (see docs/design/code-mode.md for the design, the measurements and the go / no-go recommendation):
- The sandbox (sandbox.go, worker.go) and its JavaScript runtime (goja) are only compiled with `-tags codemode`. The default binary contains only this file and available_off.go, so its size and behavior do not change.
- Even in a codemode build it stays off until `code_mode.enabled: true`.
- Every tool call a program makes is sent back through the proxy's full middleware pipeline (pkg/mcp/middleware_codemode.go): policy, tool pinning, redaction, injection guard, response governor, telemetry.
This file holds the `code_mode:` config block, which has no build tag so pkg/migrate can parse and validate it in every build.
Index ¶
Constants ¶
const ( // DefaultTimeout bounds one execute_code call, wall clock, tool calls // included. The sandbox process is killed when it runs out. DefaultTimeout = 30 * time.Second // DefaultCPUTime bounds the CPU time of the sandbox process (the // kernel's RLIMIT_CPU on Unix). Time spent waiting for tool calls is // not CPU time. DefaultCPUTime = 5 * time.Second // DefaultMaxMemoryMB is the sandbox process's memory limit. DefaultMaxMemoryMB = 256 // DefaultMaxCalls caps the tool calls of one program. DefaultMaxCalls = 32 // DefaultMaxConcurrentCalls caps the tool calls of one program in // flight at once (Promise.all). DefaultMaxConcurrentCalls = 4 // DefaultMaxOutputBytes caps the program's result (what reaches the // model): 64 KiB, about 16k tokens. DefaultMaxOutputBytes = 64 << 10 // DefaultMaxCodeBytes caps the program's source. DefaultMaxCodeBytes = 64 << 10 // DefaultMaxCallResultBytes caps one tool result handed to the // program. DefaultMaxCallResultBytes = 4 << 20 // MinMaxMemoryMB is the smallest memory limit: below it the Go // runtime of the sandbox process itself does not fit. MinMaxMemoryMB = 64 // MaxTimeout is the largest timeout accepted. MaxTimeout = 10 * time.Minute )
Defaults of the `code_mode:` block.
const Available = false
Available reports whether this binary was built with `-tags codemode`, i.e. whether it contains the sandbox. It does not: a `code_mode:` block is parsed and validated, then ignored.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Enabled lists the execute_code tool and serves it. Off by default.
Enabled bool `yaml:"enabled"`
// Timeout bounds one execute_code call (a Go duration). Unset means
// DefaultTimeout.
Timeout string `yaml:"timeout,omitempty"`
// CPUTime bounds the sandbox's CPU time (a Go duration, whole
// seconds on Unix). Unset means DefaultCPUTime.
CPUTime string `yaml:"cpu_time,omitempty"`
// MaxMemoryMB is the sandbox's memory limit in MiB. Unset (0) means
// DefaultMaxMemoryMB.
MaxMemoryMB int `yaml:"max_memory_mb,omitempty"`
// MaxCalls caps the tool calls of one program. Unset (0) means
// DefaultMaxCalls.
MaxCalls int `yaml:"max_calls,omitempty"`
// MaxConcurrentCalls caps the tool calls in flight at once. Unset (0)
// means DefaultMaxConcurrentCalls.
MaxConcurrentCalls int `yaml:"max_concurrent_calls,omitempty"`
// MaxOutputBytes caps the program's result. Unset (0) means
// DefaultMaxOutputBytes.
MaxOutputBytes int `yaml:"max_output_bytes,omitempty"`
}
Config is the `code_mode:` block. Off by default; a binary built without `-tags codemode` ignores it (with a warning when enabled).
type Limits ¶
type Limits struct {
Timeout time.Duration `json:"timeout"`
CPUTime time.Duration `json:"cpu_time"`
MaxMemoryMB int `json:"max_memory_mb"`
MaxCalls int `json:"max_calls"`
MaxConcurrentCalls int `json:"max_concurrent_calls"`
MaxOutputBytes int `json:"max_output_bytes"`
MaxCodeBytes int `json:"max_code_bytes"`
MaxCallResultBytes int `json:"max_call_result_bytes"`
}
Limits are the effective limits of one execute_code call.