codemode

command
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

codemode: one tool call that runs a script over many tools

Code mode gives the model a single tool, code_mode, that runs a Starlark script. Inside the script every bound tool is a function, so the model can chain calls, run independent ones concurrently with parallel(...), and filter large results before anything reaches the conversation: only what the script prints and returns comes back. The script has no file system, network, environment, processes or clock of its own, only the bound tools, and every call it makes goes through the agent's own guard and event stream.

This example runs offline with no API key: the model is provider/faux replaying two scripted code_mode calls over real tools (three built-in file tools on a temporary workspace, and a stock lookup from an in-process MCP server).

Run it

go run ./examples/codemode
code_mode binds 4 tools; its description is 2753 bytes (2753 characters)

  nested: call_1 called list_files (ok=true)
  nested: call_1 called read_file (ok=false)
  nested: call_2 called find_files (ok=true)
  ...
  nested: call_2 called inventory__stock (ok=true)

code_mode result:
  Go files: main.go, util.go
  CHANGELOG.md: read_failed

code_mode result:
  README.md -> # Example project
  docs/NOTES.md -> Notes: the scripts read these concurrently.
  Return value: {"apples": 12, "pears": 0}
...
Code mode example completed successfully

What it shows

  • The generated tool description declares each bound tool as a typed Starlark function (BuildInfo reports its size).
  • A failed call comes back to the script as a value (is_error(missing), missing.error), and the script carries on.
  • parallel([call(...), ...]) runs independent calls concurrently.
  • Every nested call appears on the agent's event stream with the code_mode call as its parent, but the transcript holds only the two code_mode calls and their results, not the seven calls the scripts made.

The code that matters

all, err := tools.For(ws, tools.Options{})
bound, err := core.Named(all, "list_files", "find_files", "read_file")
bound = append(bound, mcpTools...) // tools from an mcp.Pool work the same way

cm, info, err := codemode.New(bound, codemode.Options{})
agent, err := agentkit.New(agentkit.Config{
	Client:   model,
	Model:    faux.Model().ID,
	Toolset:  agentkit.Toolset{Tools: []core.Tool{cm}}, // the model sees code_mode alone
	MaxTurns: 5,
})

core.Named picks tools by name, in that order, and fails with the list of names it has when one is missing. None of the bound tools is a shell tool, so no Toolset.Guard is required; bind execute and you must supply one.

Further reading

Documentation

Overview

Command codemode shows the code-mode tool: the model writes one Starlark script that calls several tools, filters what they return, and hands back only the answer.

go run ./examples/codemode

It runs offline, with no API key: the "model" is provider/faux replaying two scripted code_mode calls. The tools are real — list_files, find_files and read_file over a temporary workspace, and a stock lookup served by an in-process MCP server — and every call a script makes goes through the agent's own interceptor and event pipeline.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL