Tool calling vs. code mode
The same job twice: redact PII in every support dataset. Left calls the tools one at a time; right hands the sandbox a program.
Tool calling
every result passes through the model
turn 0
Context window
datasets
every example
updates
full, more turns to go
Model
list_datasets
MCP tool
get_dataset_examples
MCP tool
update_examples
MCP tool
Code mode
one program, only the return value comes back
turn 0
Context window
one line
Model
Sandbox
run_code(program)
datasets =
list_datasets
(project="support")
for ds in datasets:
examples =
get_dataset_examples
(ds["id"])
fixed = [redact_pii(e) for e in examples]
update_examples
(ds["id"], fixed)
return f"updated {len(datasets)} datasets"
every example stays here; the model never reads them
list_datasets
MCP tool
get_dataset_examples
MCP tool
update_examples
MCP tool