Agent tools
Token-cheap code tools for agents: view, search, repo map, patch, diagnostics and the tool cache.
Every method shows the same operation in each SDK; pick a language once and every tab on the site follows it.
AgentTools
Section titled “AgentTools”sandbox.tools. cwd is where relative paths start (the guest’s default working directory when None). With a cache (a ToolCache, which forks can share) the tools it names answer from it; each method’s cache argument overrides that.
Properties
Section titled “Properties”Python exposes these as methods; see below.
TypeScript exposes these as methods; see below.
Go exposes these as methods; see below.
Ruby exposes these as methods; see below.
| Property | Type | Description |
|---|---|---|
DIRECTORY |
String |
|
MAX_BUDGET |
int |
|
MIN_BUDGET |
int |
|
VERIFY_TIMEOUT |
int |
Seconds the driver gives an applyPatch verify command. |
VERSION |
String |
apply_patch()
Section titled “apply_patch()”def apply_patch(self, patch: str | None=None, *, edits: list[dict[str, Any]] | None=None, dry_run: bool=False, diagnostics: bool=False, verify: str | None=None, budget: int | None=None, cwd: str | None=None, cache: bool | None=None) -> ToolResultApply a unified diff, or edits ({path, old, new} replaces text that occurs once; {path, content} creates a file; {path, delete: True} removes one). All or nothing: on any conflict no file changes and text reports each problem with the closest text in the file. diagnostics=True then runs the language server on each changed file it knows. verify (a test or build command, e.g. "pytest -q") then runs in cwd and its failures are appended, so an edit and its check are one call; the patch stays applied whatever it says, and data["verify"] holds its exit code, summary and failed tests.
| Parameter | Type | Default |
|---|---|---|
patch |
str | None |
None |
edits |
list[dict[str, Any]] | None |
None |
dry_run |
bool |
False |
diagnostics |
bool |
False |
verify |
str | None |
None |
budget |
int | None |
None |
cwd |
str | None |
None |
cache |
bool | None |
None |
Returns ToolResult
sdk/python/svm/agent_tools.py:175applyPatch(patch?: string, o: PatchOptions = {}): Promise<ToolResult>Apply a unified diff, or edits. All or nothing: on any conflict no file changes and text reports each problem with the closest text in the file. diagnostics: true then runs the language server on each changed file it knows.
| Parameter | Type | Default |
|---|---|---|
patch |
string |
optional |
o |
PatchOptions |
{} |
Returns Promise<ToolResult>
sdk/typescript/src/agent-tools.ts:169func (t *AgentTools) ApplyPatch(ctx context.Context, patch string, edits []map[string]any, dryRun, diagnostics bool, verify string, c ToolCall) (ToolResult, error)ApplyPatch applies a unified diff, or edits ({path, old, new} replaces text that occurs once; {path, content} creates a file; {path, delete: true} removes one). All or nothing: on any conflict no file changes and Text reports each problem. diagnostics then runs the language server on each changed file it knows. verify (a test or build command, “” for none) then runs in the working directory and its failures are appended, so an edit and its check are one call; the patch stays applied whatever it says, and Data[“verify”] holds its exit code, summary and failed tests.
| Parameter | Type | Default |
|---|---|---|
ctx |
context.Context |
|
patch |
string |
|
edits |
[]map[string]any |
|
dryRun |
bool |
|
diagnostics |
bool |
|
verify |
string |
|
c |
ToolCall |
Returns (ToolResult, error)
sdk/go/agent_tools.go:313def apply_patch(patch = nil, edits: nil, dry_run: false, diagnostics: false, verify: nil, budget: nil, cwd: nil, cache: nil)Applies a unified diff, or edits ({path:, old:, new:} replaces text that occurs once; {path:, content:} creates a file; {path:, delete: true} removes one). All or nothing: on any conflict no file changes and text reports each problem. diagnostics then runs the language server on each changed file it knows. verify (a test or build command) then runs in cwd and its failures are appended, so an edit and its check are one call; the patch stays applied whatever it says, and data[“verify”] holds its exit code, summary and failed tests.
| Parameter | Type | Default |
|---|---|---|
patch |
nil |
|
edits |
nil |
|
dry_run |
false |
|
diagnostics |
false |
|
verify |
nil |
|
budget |
nil |
|
cwd |
nil |
|
cache |
nil |
sdk/ruby/lib/svm/agent_tools.rb:102public Result applyPatch(String patch, List<Map<String, Object>> edits, boolean dryRun, boolean diagnostics, String verify, Integer budget)Applies a unified diff, or edits ({path, old, new} replaces text that occurs once; {path, content} creates a file; {path, delete: true} removes one); all or nothing. verify (a test or build command, or null) then runs and its failures are appended, so an edit and its check are one call; the patch stays applied whatever it says, and data.verify holds its exit code, summary and failed tests.
| Parameter | Type | Default |
|---|---|---|
patch |
String |
|
edits |
List<Map<String, Object>> |
|
dryRun |
boolean |
|
diagnostics |
boolean |
|
verify |
String |
|
budget |
Integer |
Returns Result
sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:162command()
Section titled “command()”def command(self, command: str, *, pure: bool=False, env: dict[str, str] | None=None, cwd: str | None=None, timeout_seconds: int=600, budget: int | None=None) -> ToolResultRun a shell command. text is the exit code, what a test runner or compiler reported (summary, failed tests, error locations, and what changed since the last run of the same command here), then the output cut to the budget with the end of the log and the lines that report errors kept first. pure=True declares that its output depends only on the files under the cache root, the command and env (no network, clock or randomness), so with a cache it answers from it; a pure command that changes the tree is not stored. data holds exit_code, stdout and stderr (each up to 1 MiB: the start and the end of a longer stream), and runner, summary, failed and errors.
| Parameter | Type | Default |
|---|---|---|
command |
str |
|
pure |
bool |
False |
env |
dict[str, str] | None |
None |
cwd |
str | None |
None |
timeout_seconds |
int |
600 |
budget |
int | None |
None |
Returns ToolResult
sdk/python/svm/agent_tools.py:198command(command: string, o: CommandOptions = {}): Promise<ToolResult>Run a shell command. text is the exit code, what a test runner or compiler reported (summary, failed tests, error locations, and what changed since the last run of the same command here), then the output cut to the budget with the end of the log and the lines that report errors kept first. With pure: true and a cache it answers from the cache; a pure command that changes the tree is not stored. data holds exit_code, stdout and stderr (each up to 1 MiB: the start and the end of a longer stream), and runner, summary, failed and errors.
| Parameter | Type | Default |
|---|---|---|
command |
string |
|
o |
CommandOptions |
{} |
Returns Promise<ToolResult>
sdk/typescript/src/agent-tools.ts:193func (t *AgentTools) Command(ctx context.Context, command string, pure bool, env map[string]string, timeoutSeconds int, c ToolCall) (ToolResult, error)Command runs a shell command. pure declares that its output depends only on the files under the cache root, the command and env (no network, clock or randomness), so with a cache it answers from it; a pure command that changes the tree is not stored. Data holds exit_code, stdout and stderr; Text is the exit code and output, cut to the budget.
| Parameter | Type | Default |
|---|---|---|
ctx |
context.Context |
|
command |
string |
|
pure |
bool |
|
env |
map[string]string |
|
timeoutSeconds |
int |
|
c |
ToolCall |
Returns (ToolResult, error)
sdk/go/agent_tools.go:367def command(command, pure: false, env: nil, cwd: nil, timeout_seconds: 600, budget: nil)Runs a shell command. text is the exit code, what a test runner or compiler reported (summary, failed tests, error locations, and what changed since the last run of the same command here), then the output cut to the budget with the end of the log and the lines that report errors kept first. pure declares that its output depends only on the files under the cache root, the command and env (no network, clock or randomness), so with a cache it answers from it; a pure command that changes the tree is not stored. data holds exit_code, stdout and stderr (each up to 1 MiB: the start and the end of a longer stream), and runner, summary, failed and errors.
| Parameter | Type | Default |
|---|---|---|
command |
||
pure |
false |
|
env |
nil |
|
cwd |
nil |
|
timeout_seconds |
600 |
|
budget |
nil |
sdk/ruby/lib/svm/agent_tools.rb:125public Result command(String command, boolean pure, Map<String, String> env, int timeoutSeconds, Integer budget)Runs a shell command. pure declares that its output depends only on the files under the cache root, the command and env (no network, clock or randomness), so with a cache it answers from it; a pure command that changes the tree is not stored.
| Parameter | Type | Default |
|---|---|---|
command |
String |
|
pure |
boolean |
|
env |
Map<String, String> |
|
timeoutSeconds |
int |
|
budget |
Integer |
Returns Result
sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:188constructor()
Section titled “constructor()”Not in the Python SDK’s AgentTools.
constructor(private readonly sandbox: GuestSandbox, private readonly cwd?: string, private readonly cache?: ToolCache)| Parameter | Type | Default |
|---|---|---|
sandbox |
GuestSandbox |
|
cwd |
string |
optional |
cache |
ToolCache |
optional |
sdk/typescript/src/agent-tools.ts:85Not in the Go SDK’s AgentTools.
Not in the Ruby SDK’s AgentTools.
Not in the Java SDK’s AgentTools.
diagnostics()
Section titled “diagnostics()”def diagnostics(self, path: str, *, language: str | None=None, budget: int | None=None, cwd: str | None=None, timeout: int=60, cache: bool | None=None) -> ToolResultErrors first, then warnings, for one file, from the language server for language (guessed from the extension).
| Parameter | Type | Default |
|---|---|---|
path |
str |
|
language |
str | None |
None |
budget |
int | None |
None |
cwd |
str | None |
None |
timeout |
int |
60 |
cache |
bool | None |
None |
Returns ToolResult
sdk/python/svm/agent_tools.py:189async diagnostics(path: string, o: DiagnosticsOptions = {}): Promise<ToolResult>Errors first, then warnings, for one file, from the language server for language (guessed from the extension).
| Parameter | Type | Default |
|---|---|---|
path |
string |
|
o |
DiagnosticsOptions |
{} |
Returns Promise<ToolResult>
sdk/typescript/src/agent-tools.ts:178func (t *AgentTools) Diagnostics(ctx context.Context, file, language string, timeoutSeconds int, c ToolCall) (ToolResult, error)Diagnostics returns errors first, then warnings, for one file, from the language server for language (guessed from the extension when empty).
| Parameter | Type | Default |
|---|---|---|
ctx |
context.Context |
|
file |
string |
|
language |
string |
|
timeoutSeconds |
int |
|
c |
ToolCall |
Returns (ToolResult, error)
sdk/go/agent_tools.go:345def diagnostics(path, language: nil, budget: nil, cwd: nil, timeout: 60, cache: nil)Errors first, then warnings, for one file, from the language server for language (guessed from the extension).
| Parameter | Type | Default |
|---|---|---|
path |
||
language |
nil |
|
budget |
nil |
|
cwd |
nil |
|
timeout |
60 |
|
cache |
nil |
sdk/ruby/lib/svm/agent_tools.rb:112public Result diagnostics(String path, String language, Integer budget, int timeout)Errors first, then warnings, for one file, from the language server for language (guessed from the extension when null).
| Parameter | Type | Default |
|---|---|---|
path |
String |
|
language |
String |
|
budget |
Integer |
|
timeout |
int |
Returns Result
sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:175initialize()
Section titled “initialize()”Not in the Python SDK’s AgentTools.
Not in the TypeScript SDK’s AgentTools.
Not in the Go SDK’s AgentTools.
def initialize(sandbox, cwd: nil, cache: nil)cwd is where relative paths start (the guest’s default working directory when nil). With a cache (a ToolCache, which forks can share) the tools it names answer from it; each method’s cache argument overrides that.
| Parameter | Type | Default |
|---|---|---|
sandbox |
||
cwd |
nil |
|
cache |
nil |
sdk/ruby/lib/svm/agent_tools.rb:37Not in the Java SDK’s AgentTools.
repo_map()
Section titled “repo_map()”def repo_map(self, path: str='.', *, focus: list[str] | None=None, mentions: list[str] | None=None, max_files: int | None=None, budget: int | None=None, cwd: str | None=None, cache: bool | None=None) -> ToolResultThe repository’s most referenced definitions, one source line each, as many as fit in budget (1024 by default). focus (files the agent is working on, relative to path) and mentions (names) steer the ranking.
| Parameter | Type | Default |
|---|---|---|
path |
str |
'.' |
focus |
list[str] | None |
None |
mentions |
list[str] | None |
None |
max_files |
int | None |
None |
budget |
int | None |
None |
cwd |
str | None |
None |
cache |
bool | None |
None |
Returns ToolResult
sdk/python/svm/agent_tools.py:167repoMap(o: RepoMapOptions = {}): Promise<ToolResult>The repository’s most referenced definitions, one source line each, as many as fit in the budget (1024 by default). focus (files the agent is working on, relative to path) and mentions (names) steer the ranking.
| Parameter | Type | Default |
|---|---|---|
o |
RepoMapOptions |
{} |
Returns Promise<ToolResult>
sdk/typescript/src/agent-tools.ts:161func (t *AgentTools) RepoMap(ctx context.Context, dir string, focus, mentions []string, c ToolCall) (ToolResult, error)RepoMap returns the repository’s most referenced definitions, one source line each, as many as fit in the budget (1024 by default).
| Parameter | Type | Default |
|---|---|---|
ctx |
context.Context |
|
dir |
string |
|
focus |
[]string |
|
mentions |
[]string |
|
c |
ToolCall |
Returns (ToolResult, error)
sdk/go/agent_tools.go:291def repo_map(path: ".", focus: nil, mentions: nil, max_files: nil, budget: nil, cwd: nil, cache: nil)The repository’s most referenced definitions, one source line each, as many as fit in budget (1024 by default).
| Parameter | Type | Default |
|---|---|---|
path |
"." |
|
focus |
nil |
|
mentions |
nil |
|
max_files |
nil |
|
budget |
nil |
|
cwd |
nil |
|
cache |
nil |
sdk/ruby/lib/svm/agent_tools.rb:94public Result repoMap(String path, List<String> focus, List<String> mentions, Integer budget)The repository’s most referenced definitions, one source line each, as many as fit in budget (1024 by default).
| Parameter | Type | Default |
|---|---|---|
path |
String |
|
focus |
List<String> |
|
mentions |
List<String> |
|
budget |
Integer |
Returns Result
sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:155def run(self, tool: str, args: dict[str, Any], *, budget: int | None=None, cwd: str | None=None, timeout_seconds: int=120, cache: bool | None=None) -> ToolResultRun one tool by name with the driver’s own arguments (see sdk/surface/agent_tools/__main__.py).
| Parameter | Type | Default |
|---|---|---|
tool |
str |
|
args |
dict[str, Any] |
|
budget |
int | None |
None |
cwd |
str | None |
None |
timeout_seconds |
int |
120 |
cache |
bool | None |
None |
Returns ToolResult
sdk/python/svm/agent_tools.py:108async run(tool: string, args: Record<string, unknown>, options: ToolOptions & { timeoutSeconds?: number } = {}): Promise<ToolResult>Run one tool by name with the driver’s own arguments (see sdk/surface/agent_tools/__main__.py).
| Parameter | Type | Default |
|---|---|---|
tool |
string |
|
args |
Record<string, unknown> |
|
options |
ToolOptions & { timeoutSeconds?: number } |
{} |
Returns Promise<ToolResult>
sdk/typescript/src/agent-tools.ts:91func (t *AgentTools) Run(ctx context.Context, tool string, args map[string]any, c ToolCall) (ToolResult, error)Run runs one tool by name with the driver’s own arguments (see sdk/surface/agent_tools/__main__.py).
| Parameter | Type | Default |
|---|---|---|
ctx |
context.Context |
|
tool |
string |
|
args |
map[string]any |
|
c |
ToolCall |
Returns (ToolResult, error)
sdk/go/agent_tools.go:115def run(tool, args, budget: nil, cwd: nil, timeout_seconds: 120, cache: nil)Runs one tool by name with the driver’s own arguments (see sdk/surface/agent_tools/__main__.py).
| Parameter | Type | Default |
|---|---|---|
tool |
||
args |
||
budget |
nil |
|
cwd |
nil |
|
timeout_seconds |
120 |
|
cache |
nil |
sdk/ruby/lib/svm/agent_tools.rb:47public Result run(String tool, Map<String, Object> toolArgs, Integer budget, String workingDirectory, int timeoutSeconds, Boolean useCache)Runs one tool by name with the driver’s own arguments (see sdk/surface/agent_tools/__main__.py).
| Parameter | Type | Default |
|---|---|---|
tool |
String |
|
toolArgs |
Map<String, Object> |
|
budget |
Integer |
|
workingDirectory |
String |
|
timeoutSeconds |
int |
|
useCache |
Boolean |
Returns Result
sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:87search()
Section titled “search()”def search(self, pattern: str, path: str='.', *, glob: str | list[str] | None=None, fixed_strings: bool=False, case: str='smart', context: int=0, max_matches: int=50, max_per_file: int=10, budget: int | None=None, cwd: str | None=None, cache: bool | None=None) -> ToolResultMatches grouped by file with line numbers, at most max_matches in all and max_per_file per file, and the totals.
| Parameter | Type | Default |
|---|---|---|
pattern |
str |
|
path |
str |
'.' |
glob |
str | list[str] | None |
None |
fixed_strings |
bool |
False |
case |
str |
'smart' |
context |
int |
0 |
max_matches |
int |
50 |
max_per_file |
int |
10 |
budget |
int | None |
None |
cwd |
str | None |
None |
cache |
bool | None |
None |
Returns ToolResult
sdk/python/svm/agent_tools.py:159search(pattern: string, o: SearchOptions = {}): Promise<ToolResult>Matches grouped by file with line numbers, at most maxMatches in all and maxPerFile per file, and the totals.
| Parameter | Type | Default |
|---|---|---|
pattern |
string |
|
o |
SearchOptions |
{} |
Returns Promise<ToolResult>
sdk/typescript/src/agent-tools.ts:152func (t *AgentTools) Search(ctx context.Context, pattern string, o SearchOptions, c ToolCall) (ToolResult, error)Search returns matches grouped by file with line numbers, at most MaxMatches in all and MaxPerFile per file, and the totals.
| Parameter | Type | Default |
|---|---|---|
ctx |
context.Context |
|
pattern |
string |
|
o |
SearchOptions |
|
c |
ToolCall |
Returns (ToolResult, error)
sdk/go/agent_tools.go:270def search(pattern, path: ".", glob: nil, fixed_strings: false, case_mode: "smart", context: 0, max_matches: 50, max_per_file: 10, budget: nil, cwd: nil, cache: nil)Matches grouped by file with line numbers, at most max_matches in all and max_per_file per file, and the totals.
| Parameter | Type | Default |
|---|---|---|
pattern |
||
path |
"." |
|
glob |
nil |
|
fixed_strings |
false |
|
case_mode |
"smart" |
|
context |
0 |
|
max_matches |
50 |
|
max_per_file |
10 |
|
budget |
nil |
|
cwd |
nil |
|
cache |
nil |
sdk/ruby/lib/svm/agent_tools.rb:88public Result search(String pattern, String path, int maxMatches, int maxPerFile, Integer budget)Matches grouped by file with line numbers, at most maxMatches in all and maxPerFile per file, and the totals.
| Parameter | Type | Default |
|---|---|---|
pattern |
String |
|
path |
String |
|
maxMatches |
int |
|
maxPerFile |
int |
|
budget |
Integer |
Returns Result
sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:150upload()
Section titled “upload()”def upload(self) -> NoneWrite the tools into the sandbox. run does this by itself the first time a sandbox lacks them.
sdk/python/svm/agent_tools.py:148async upload(): Promise<void>Write the tools into the sandbox. run does this by itself the first time a sandbox lacks them.
sdk/typescript/src/agent-tools.ts:142func (t *AgentTools) Upload(ctx context.Context) errorUpload writes the tools into the sandbox. Run does this by itself the first time a sandbox lacks them.
| Parameter | Type | Default |
|---|---|---|
ctx |
context.Context |
Returns error
sdk/go/agent_tools.go:245def uploadWrites the tools into the sandbox. #run does this by itself the first time a sandbox lacks them.
Source:sdk/ruby/lib/svm/agent_tools.rb:77public void upload()Writes the tools into the sandbox. run does this by itself the first time a sandbox lacks them.
Source:sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:144view()
Section titled “view()”def view(self, path: str, *, start: int=1, lines: int=100, line_chars: int | None=None, budget: int | None=None, cwd: str | None=None, cache: bool | None=None) -> ToolResultLines start to start + lines - 1 of a file, numbered, with how many lines lie above and below; a directory is listed.
| Parameter | Type | Default |
|---|---|---|
path |
str |
|
start |
int |
1 |
lines |
int |
100 |
line_chars |
int | None |
None |
budget |
int | None |
None |
cwd |
str | None |
None |
cache |
bool | None |
None |
Returns ToolResult
sdk/python/svm/agent_tools.py:153view(path: string, o: ViewOptions = {}): Promise<ToolResult>Lines start to start + lines - 1 of a file, numbered, with how many lines lie above and below; a directory is listed.
| Parameter | Type | Default |
|---|---|---|
path |
string |
|
o |
ViewOptions |
{} |
Returns Promise<ToolResult>
sdk/typescript/src/agent-tools.ts:147func (t *AgentTools) View(ctx context.Context, file string, start, lines int, c ToolCall) (ToolResult, error)View returns lines start to start+lines-1 of a file, numbered, with how many lie above and below; a directory is listed.
| Parameter | Type | Default |
|---|---|---|
ctx |
context.Context |
|
file |
string |
|
start |
int |
|
lines |
int |
|
c |
ToolCall |
Returns (ToolResult, error)
sdk/go/agent_tools.go:255def view(path, start: 1, lines: 100, line_chars: nil, budget: nil, cwd: nil, cache: nil)Lines start to start + lines - 1 of a file, numbered, with how many lie above and below; a directory is listed.
| Parameter | Type | Default |
|---|---|---|
path |
||
start |
1 |
|
lines |
100 |
|
line_chars |
nil |
|
budget |
nil |
|
cwd |
nil |
|
cache |
nil |
sdk/ruby/lib/svm/agent_tools.rb:83public Result view(String path, int start, int lines, Integer budget)Lines start to start + lines - 1 of a file, numbered, with how many lie above and below; a directory is listed.
| Parameter | Type | Default |
|---|---|---|
path |
String |
|
start |
int |
|
lines |
int |
|
budget |
Integer |
Returns Result
sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:147with_cache()
Section titled “with_cache()”def with_cache(self, cache: ToolCache | None) -> AgentToolsThese tools behind cache (None turns it off).
| Parameter | Type | Default |
|---|---|---|
cache |
ToolCache | None |
Returns AgentTools
sdk/python/svm/agent_tools.py:104withCache(cache: ToolCache | undefined): AgentToolsThese tools behind cache (undefined turns it off).
| Parameter | Type | Default |
|---|---|---|
cache |
ToolCache | undefined |
Returns AgentTools
sdk/typescript/src/agent-tools.ts:88func (t *AgentTools) WithCache(cache *ToolCache) *AgentToolsWithCache returns these tools behind cache (nil turns it off).
| Parameter | Type | Default |
|---|---|---|
cache |
*ToolCache |
Returns *AgentTools
sdk/go/agent_tools.go:102def with_cache(cache)These tools behind cache (nil turns it off).
| Parameter | Type | Default |
|---|---|---|
cache |
sdk/ruby/lib/svm/agent_tools.rb:42public AgentTools withCache(ToolCache cache)These tools behind cache (null turns it off).
| Parameter | Type | Default |
|---|---|---|
cache |
ToolCache |
Returns AgentTools
sdk/java/src/main/java/dev/svm/sandbox/AgentTools.java:74ToolResult
Section titled “ToolResult”What a tool returns. text is what to show the agent; ok is False when the tool could not do what was asked (a missing file, a patch that does not apply) and text then says why. tokens is estimated at three characters a token, which errs high. cached is True when the answer came from the tool-result cache. For command, data holds exit_code, stdout and stderr.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
cached |
bool |
|
data |
dict[str, Any] |
|
error |
str | None |
|
ok |
bool |
|
text |
str |
|
tokens |
int |
|
truncated |
bool |
| Property | Type | Description |
|---|---|---|
cached |
boolean |
|
data |
Record<string, unknown> |
|
error |
string |
|
ok |
boolean |
|
text |
string |
|
tokens |
number |
|
truncated |
boolean |
| Property | Type | Description |
|---|---|---|
Cached |
bool |
|
Data |
map[string]any |
|
Error |
string |
|
OK |
bool |
|
Text |
string |
|
Tokens |
int |
|
Truncated |
bool |
| Property | Type | Description |
|---|---|---|
cached |
||
data |
||
error |
||
ok |
||
text |
||
tokens |
||
truncated |
Not in the Java SDK.
ToolCache
Section titled “ToolCache”The answers, in memory (max_entries, least recently used first out) or in directory so processes can share them.
tools are the agent tools cached when a call does not say (cache=None); a call passes cache=True or False to opt in or out itself. apply_patch is cached only as a dry run, and a command only when the call says pure=True. root is the tree digested, relative to the call’s working directory; exclude names directories (at any depth) left out of it.
Give the tools a working directory (AgentTools(sandbox, cwd="/work", cache=...) or cwd= per call): without one the sandbox’s is /, which is not cached (the call runs uncached and says why). A tree too large to digest within the driver’s limits (200,000 entries or 20 seconds) is not cached either.
Properties
Section titled “Properties”Python exposes these as methods; see below.
| Property | Type | Description |
|---|---|---|
exclude |
string[] |
|
hitRate |
number |
|
root |
string |
|
store |
ToolCacheStore |
|
tools |
ReadonlySet<string> |
Go exposes these as methods; see below.
| Property | Type | Description |
|---|---|---|
exclude |
||
root |
||
tools |
| Property | Type | Description |
|---|---|---|
EXCLUDE |
List<String> |
|
READ_TOOLS |
Set<String> |
def get(self, key: str, digest: str) -> dict[str, Any] | None| Parameter | Type | Default |
|---|---|---|
key |
str |
|
digest |
str |
Returns dict[str, Any] \| None
sdk/python/svm/tool_cache.py:115async get(key: string, digest: string): Promise<CachedEntry | undefined>The stored answer for key at the tree digest, if any.
| Parameter | Type | Default |
|---|---|---|
key |
string |
|
digest |
string |
Returns Promise<CachedEntry \| undefined>
sdk/typescript/src/tool-cache.ts:157func (c *ToolCache) Get(key, digest string) (map[string]any, float64, bool)Get returns the stored answer and how long its run took.
| Parameter | Type | Default |
|---|---|---|
key |
string |
|
digest |
string |
Returns (map[string]any, float64, bool)
sdk/go/tool_cache.go:260def get(key, digest)| Parameter | Type | Default |
|---|---|---|
key |
||
digest |
sdk/ruby/lib/svm/tool_cache.rb:106public Map<String, Object> get(String key, String digest)| Parameter | Type | Default |
|---|---|---|
key |
String |
|
digest |
String |
Returns Map<String, Object>
sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:213clear()
Section titled “clear()”def clear(self) -> Nonesdk/python/svm/tool_cache.py:151async clear(): Promise<void>Drop every stored answer (the counters in stats are kept).
sdk/typescript/src/tool-cache.ts:165func (c *ToolCache) Clear()Clear forgets every answer held in memory.
Source:sdk/go/tool_cache.go:333def clearsdk/ruby/lib/svm/tool_cache.rb:146public void clear()sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:257constructor()
Section titled “constructor()”Not in the Python SDK’s ToolCache.
constructor(options: ToolCacheOptions = {})| Parameter | Type | Default |
|---|---|---|
options |
ToolCacheOptions |
{} |
sdk/typescript/src/tool-cache.ts:123Not in the Go SDK’s ToolCache.
Not in the Ruby SDK’s ToolCache.
Not in the Java SDK’s ToolCache.
initialize()
Section titled “initialize()”Not in the Python SDK’s ToolCache.
Not in the TypeScript SDK’s ToolCache.
Not in the Go SDK’s ToolCache.
def initialize(tools: READ_TOOLS, max_entries: 4096, directory: nil, root: ".", exclude: EXCLUDE)| Parameter | Type | Default |
|---|---|---|
tools |
READ_TOOLS |
|
max_entries |
4096 |
|
directory |
nil |
|
root |
"." |
|
exclude |
EXCLUDE |
sdk/ruby/lib/svm/tool_cache.rb:27Not in the Java SDK’s ToolCache.
def key(self, tool: str, args: dict[str, Any], budget: int | None, cwd: str | None, version: str) -> strThe call’s key without the digest: tool, inputs, budget, the tools’ version and the tree’s bounds. The tools answer in paths relative to the root, so where the tree sits is left out; a command can print it, so its working directory is in.
| Parameter | Type | Default |
|---|---|---|
tool |
str |
|
args |
dict[str, Any] |
|
budget |
int | None |
|
cwd |
str | None |
|
version |
str |
Returns str
sdk/python/svm/tool_cache.py:92key(tool: string, args: Record<string, unknown>, budget: number | null, cwd: string | null, version: string): Promise<string>The call’s key without the digest: tool, inputs, budget, the tools’ version and the tree’s bounds. The tools answer in paths relative to the root, so where the tree sits is left out; a command can print it, so its working directory is in.
| Parameter | Type | Default |
|---|---|---|
tool |
string |
|
args |
Record<string, unknown> |
|
budget |
number | null |
|
cwd |
string | null |
|
version |
string |
Returns Promise<string>
sdk/typescript/src/tool-cache.ts:143func (c *ToolCache) Key(tool string, args map[string]any, budget *int, cwd, version string) stringKey is the call’s key without the digest: tool, inputs, budget, the tools’ version and the tree’s bounds.
| Parameter | Type | Default |
|---|---|---|
tool |
string |
|
args |
map[string]any |
|
budget |
*int |
|
cwd |
string |
|
version |
string |
Returns string
sdk/go/tool_cache.go:200def key(tool, args, budget, cwd, version)The call’s key without the digest: tool, inputs, budget, the tools’ version and the tree’s bounds.
| Parameter | Type | Default |
|---|---|---|
tool |
||
args |
||
budget |
||
cwd |
||
version |
sdk/ruby/lib/svm/tool_cache.rb:85public String key(String tool, Map<String, Object> args, Integer budget, String cwd, String version)The call’s key without the digest: tool, inputs, budget, the tools’ version and the tree’s bounds.
| Parameter | Type | Default |
|---|---|---|
tool |
String |
|
args |
Map<String, Object> |
|
budget |
Integer |
|
cwd |
String |
|
version |
String |
Returns String
sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:164known()
Section titled “known()”def known(self, key: str) -> list[str]| Parameter | Type | Default |
|---|---|---|
key |
str |
Returns list[str]
sdk/python/svm/tool_cache.py:104async known(key: string): Promise<string[]>The digests the store holds an answer for under key, newest first.
| Parameter | Type | Default |
|---|---|---|
key |
string |
Returns Promise<string[]>
sdk/typescript/src/tool-cache.ts:154func (c *ToolCache) Known(key string) []stringKnown lists the digests the cache holds an answer for under key, newest first.
| Parameter | Type | Default |
|---|---|---|
key |
string |
Returns []string
sdk/go/tool_cache.go:225def known(key)| Parameter | Type | Default |
|---|---|---|
key |
sdk/ruby/lib/svm/tool_cache.rb:96public List<String> known(String key)| Parameter | Type | Default |
|---|---|---|
key |
String |
Returns List<String>
sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:195normalize()
Section titled “normalize()”Not in the Python SDK’s ToolCache.
Not in the TypeScript SDK’s ToolCache.
Not in the Go SDK’s ToolCache.
def self.normalize(tool, args)Spells paths one way, so ./src/a.py and src/a.py share a key; unset arguments are dropped.
| Parameter | Type | Default |
|---|---|---|
tool |
||
args |
sdk/ruby/lib/svm/tool_cache.rb:36public static Map<String, Object> normalize(String tool, Map<String, Object> args)Drops unset arguments and spells paths one way, so ./src/a.py and src/a.py share a key.
| Parameter | Type | Default |
|---|---|---|
tool |
String |
|
args |
Map<String, Object> |
Returns Map<String, Object>
sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:81def put(self, key: str, digest: str, answer: dict[str, Any], seconds: float) -> None| Parameter | Type | Default |
|---|---|---|
key |
str |
|
digest |
str |
|
answer |
dict[str, Any] |
|
seconds |
float |
sdk/python/svm/tool_cache.py:128async put(key: string, digest: string, answer: Record<string, unknown>, seconds: number): Promise<void>Store answer for key at the tree digest; seconds is how long the run took.
| Parameter | Type | Default |
|---|---|---|
key |
string |
|
digest |
string |
|
answer |
Record<string, unknown> |
|
seconds |
number |
sdk/typescript/src/tool-cache.ts:160func (c *ToolCache) Put(key, digest string, answer map[string]any, seconds float64) errorPut stores an answer and how long its run took.
| Parameter | Type | Default |
|---|---|---|
key |
string |
|
digest |
string |
|
answer |
map[string]any |
|
seconds |
float64 |
Returns error
sdk/go/tool_cache.go:284def put(key, digest, answer, seconds)| Parameter | Type | Default |
|---|---|---|
key |
||
digest |
||
answer |
||
seconds |
sdk/ruby/lib/svm/tool_cache.rb:121public void put(String key, String digest, Map<String, Object> answer, double seconds)| Parameter | Type | Default |
|---|---|---|
key |
String |
|
digest |
String |
|
answer |
Map<String, Object> |
|
seconds |
double |
Raises SandboxException
sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:226record()
Section titled “record()”def record(self, *, hit: bool=False, miss: bool=False, stored: bool=False, uncacheable: bool=False, saved: float=0.0) -> None| Parameter | Type | Default |
|---|---|---|
hit |
bool |
False |
miss |
bool |
False |
stored |
bool |
False |
uncacheable |
bool |
False |
saved |
float |
0.0 |
sdk/python/svm/tool_cache.py:156record(r: { hit?: boolean; miss?: boolean; stored?: boolean; uncacheable?: boolean; saved?: number }): void| Parameter | Type | Default |
|---|---|---|
r |
{ hit?: boolean; miss?: boolean; stored?: boolean; uncacheable?: boolean; saved?: number } |
sdk/typescript/src/tool-cache.ts:167func (c *ToolCache) Record(r CacheRecord)Record counts an outcome in Stats, for a caller that runs tools around the cache itself.
| Parameter | Type | Default |
|---|---|---|
r |
CacheRecord |
sdk/go/tool_cache.go:347def record(hit: false, miss: false, stored: false, uncacheable: false, saved: 0.0)| Parameter | Type | Default |
|---|---|---|
hit |
false |
|
miss |
false |
|
stored |
false |
|
uncacheable |
false |
|
saved |
0.0 |
sdk/ruby/lib/svm/tool_cache.rb:153public void record(boolean hit, boolean miss, boolean stored, boolean uncacheable, double saved)Counts one call in stats: a hit, a miss, an answer stored, an uncacheable call, and the seconds a hit saved.
| Parameter | Type | Default |
|---|---|---|
hit |
boolean |
|
miss |
boolean |
|
stored |
boolean |
|
uncacheable |
boolean |
|
saved |
double |
sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:260request()
Section titled “request()”def request(self, key: str) -> dict[str, Any]The cache field the guest program reads.
| Parameter | Type | Default |
|---|---|---|
key |
str |
Returns dict[str, Any]
sdk/python/svm/tool_cache.py:100async request(key: string): Promise<Record<string, unknown>>The cache field the guest program reads.
| Parameter | Type | Default |
|---|---|---|
key |
string |
Returns Promise<Record<string, unknown>>
sdk/typescript/src/tool-cache.ts:149func (c *ToolCache) Request(key string) map[string]anyRequest is the cache field the guest program reads.
| Parameter | Type | Default |
|---|---|---|
key |
string |
Returns map[string]any
sdk/go/tool_cache.go:220def request(key)The cache field the guest program reads.
| Parameter | Type | Default |
|---|---|---|
key |
sdk/ruby/lib/svm/tool_cache.rb:92public Map<String, Object> request(String key)The cache field the guest program reads.
| Parameter | Type | Default |
|---|---|---|
key |
String |
Returns Map<String, Object>
sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:187stats()
Section titled “stats()”Not in the Python SDK’s ToolCache.
stats: CacheStatsProperty (read-only).
func (c *ToolCache) Stats() CacheStatsStats is a snapshot of the counters.
Returns CacheStats
sdk/go/tool_cache.go:99statsProperty (read-only).
stats: StatsProperty (read-only).
wants()
Section titled “wants()”def wants(self, tool: str, args: dict[str, Any], choice: bool | None) -> bool| Parameter | Type | Default |
|---|---|---|
tool |
str |
|
args |
dict[str, Any] |
|
choice |
bool | None |
Returns bool
sdk/python/svm/tool_cache.py:85wants(tool: string, args: Record<string, unknown>, choice: boolean | undefined): booleanapplyPatch is cached only as a dry run, and a command only when the call says it is pure.
| Parameter | Type | Default |
|---|---|---|
tool |
string |
|
args |
Record<string, unknown> |
|
choice |
boolean | undefined |
Returns boolean
sdk/typescript/src/tool-cache.ts:133func (c *ToolCache) Wants(tool string, args map[string]any, choice *bool) boolWants says whether a call goes through the cache: choice nil follows the tool list.
| Parameter | Type | Default |
|---|---|---|
tool |
string |
|
args |
map[string]any |
|
choice |
*bool |
Returns bool
sdk/go/tool_cache.go:184def wants?(tool, args, choice)| Parameter | Type | Default |
|---|---|---|
tool |
||
args |
||
choice |
sdk/ruby/lib/svm/tool_cache.rb:78public boolean wants(String tool, Map<String, Object> args, Boolean choice)| Parameter | Type | Default |
|---|---|---|
tool |
String |
|
args |
Map<String, Object> |
|
choice |
Boolean |
Returns boolean
sdk/java/src/main/java/dev/svm/sandbox/ToolCache.java:157CacheStats
Section titled “CacheStats”saved_seconds adds, for every hit, how long the stored run took less how long the hit took.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
hits |
int |
|
misses |
int |
|
saved_seconds |
float |
|
stored |
int |
|
uncacheable |
int |
| Property | Type | Description |
|---|---|---|
hits |
number |
|
misses |
number |
|
savedSeconds |
number |
|
stored |
number |
|
uncacheable |
number |
| Property | Type | Description |
|---|---|---|
Hits |
int |
|
Misses |
int |
|
SavedSeconds |
float64 |
|
Stored |
int |
|
Uncacheable |
int |
Not in the Ruby SDK.
Not in the Java SDK.
hit_rate()
Section titled “hit_rate()”hit_rate: floatProperty (read-only).
Not in the TypeScript SDK’s CacheStats.
func (s CacheStats) HitRate() float64HitRate is hits over hits and misses.
Returns float64
sdk/go/tool_cache.go:38Not in the Ruby SDK.
Not in the Java SDK.