CodeAct Skill
Interactive, stateful Python execution loop using the code-interpreter MCP.
All agent actions are expressed as executable Python. The kernel persists for
the duration of the session; every variable, import, and computed value is
available in subsequent tool calls.
This skill carries no Python itself — it is a routing and in-context-learning
primer. When invoked, it primes the model with the CodeAct Loop protocol and
hands off all execution to the code-interpreter MCP via kernel.exec.
Quick path — the CodeAct Loop
- Write a small, focused Python block addressing the current sub-goal.
- Call
kernel.exec with that block.
- Read the returned
ExecutionTrace: inspect stdout, result, and
exception. The ExecutionTrace is the canonical evidence record; LLM
opinion about what the code does is not.
- If
exception is non-null or stdout does not match the expected output,
revise and call kernel.exec again. If correct, advance to the next
sub-goal.
- All variables from prior
exec calls remain in the KernelSession
namespace. Reference them freely without re-importing or recomputing.
Continue until the task is complete or a kernel.reset is required to clear
corrupted namespace state.
Trace-as-Reward (DDD-005): the ExecutionTrace is ground truth. A clean
exit with the expected stdout/result verifies the step — no LLM judge is in
the critical path.
The code-interpreter MCP exposes six tools on the KernelSession:
kernel.exec (the loop workhorse), plus kernel.list_vars, kernel.inspect,
kernel.reset, kernel.interrupt, and kernel.install_pkg for debugging and
introspection. See references/operations.md for their session semantics.
Worked tool-call syntax (three exemplars showing state persistence across calls):
see references/exemplars.md.
When to use
- Multiple sequential computation steps that depend on each other's results
(e.g. load data, filter, aggregate, visualise).
- Intermediate state (DataFrames, model objects, parsed structures) would be
expensive or awkward to re-derive from scratch on every tool call.
- The agent needs to observe a runtime result — an exception traceback, a
printed value, an assertion outcome — and revise based on that observation.
- Numerical reasoning, data wrangling, hypothesis testing, or scientific
computation where the Python interpreter is the source of truth.
When NOT to use
| Instead of CodeAct, use… |
When |
| Bash |
One-shot execution, no state needed — no kernel overhead. |
sparc:code |
Single-file code generation without execution; plan-then-write, stateless. |
deepseek-reasoning |
Pure symbolic / mathematical reasoning with no data to load. |
pytorch-ml |
Heavy GPU training or multi-file ML scripts — subprocess/script mode; the kernel MCP is CPU-only in v1. |
build-with-quality |
Full TDD pipeline with assertion gates, coverage, defect prediction — a QE swarm, not exploration. |
jupyter-notebooks |
The task is building or running a .ipynb notebook file (cell/kernel management, HTML/PDF export) rather than an ephemeral in-session kernel loop — CodeAct's KernelSession has no notebook file behind it. |
Reach back for codeact whenever the task is multi-step with state across
turns, or data analysis over a single dataset where state should persist so you
revise without reloading.
References (on demand)
references/exemplars.md — three in-context-learning exemplars with exact
kernel.exec tool-call syntax and trace outputs, demonstrating
KernelSession state persistence.
references/operations.md — degradation / fail-closed contract, the
agentbox.toml manifest gate, kernel session semantics (reset / interrupt /
inspect, cold-start, serialisation across sessions), identity + ecosystem URN
tagging, and composition with expel-lesson-extractor,
voyager-skill-library, and tree-search-coder.
references/empirical-priors.md — benchmark lifts, token-efficiency data,
RSS/cost accounting for swarm sizing, and the ADR/DDD/PRD + arxiv citation
list.
1---2name: codeact3description: Plan-execute-reflect loop over a persistent Python kernel (the `code-interpreter` MCP): write Python, execute, observe the returned trace (stdout / exception / last value), then revise. Variables, imports, and dataframes survive across every tool call in the session. Use for multi-step numerical reasoning, data wrangling, scientific Q&A, hypothesis-test loops, or any task where intermediate state must persist between turns and a runtime result should drive the next step.4---56# CodeAct Skill78Interactive, stateful Python execution loop using the `code-interpreter` MCP.9All agent actions are expressed as executable Python. The kernel persists for10the duration of the session; every variable, import, and computed value is11available in subsequent tool calls.1213This skill carries no Python itself — it is a routing and in-context-learning14primer. When invoked, it primes the model with the CodeAct Loop protocol and15hands off all execution to the `code-interpreter` MCP via `kernel.exec`.1617---1819## Quick path — the CodeAct Loop20211. **Write** a small, focused Python block addressing the current sub-goal.222. **Call** `kernel.exec` with that block.233. **Read** the returned `ExecutionTrace`: inspect `stdout`, `result`, and24 `exception`. The `ExecutionTrace` is the canonical evidence record; LLM25 opinion about what the code does is not.264. If `exception` is non-null or `stdout` does not match the expected output,27 **revise** and call `kernel.exec` again. If correct, advance to the next28 sub-goal.295. All variables from prior `exec` calls remain in the `KernelSession`30 namespace. Reference them freely without re-importing or recomputing.3132Continue until the task is complete or a `kernel.reset` is required to clear33corrupted namespace state.3435**Trace-as-Reward (DDD-005)**: the `ExecutionTrace` is ground truth. A clean36exit with the expected `stdout`/`result` verifies the step — no LLM judge is in37the critical path.3839The `code-interpreter` MCP exposes six tools on the `KernelSession`:40`kernel.exec` (the loop workhorse), plus `kernel.list_vars`, `kernel.inspect`,41`kernel.reset`, `kernel.interrupt`, and `kernel.install_pkg` for debugging and42introspection. See `references/operations.md` for their session semantics.4344Worked tool-call syntax (three exemplars showing state persistence across calls):45see `references/exemplars.md`.4647---4849## When to use5051- Multiple sequential computation steps that depend on each other's results52 (e.g. load data, filter, aggregate, visualise).53- Intermediate state (DataFrames, model objects, parsed structures) would be54 expensive or awkward to re-derive from scratch on every tool call.55- The agent needs to observe a runtime result — an exception traceback, a56 printed value, an assertion outcome — and revise based on that observation.57- Numerical reasoning, data wrangling, hypothesis testing, or scientific58 computation where the Python interpreter is the source of truth.5960## When NOT to use6162| Instead of CodeAct, use… | When |63|---|---|64| **Bash** | One-shot execution, no state needed — no kernel overhead. |65| **`sparc:code`** | Single-file code generation without execution; plan-then-write, stateless. |66| **`deepseek-reasoning`** | Pure symbolic / mathematical reasoning with no data to load. |67| **`pytorch-ml`** | Heavy GPU training or multi-file ML scripts — subprocess/script mode; the kernel MCP is CPU-only in v1. |68| **`build-with-quality`** | Full TDD pipeline with assertion gates, coverage, defect prediction — a QE swarm, not exploration. |69| **`jupyter-notebooks`** | The task is building or running a `.ipynb` notebook file (cell/kernel management, HTML/PDF export) rather than an ephemeral in-session kernel loop — CodeAct's `KernelSession` has no notebook file behind it. |7071Reach back for **codeact** whenever the task is multi-step *with* state across72turns, or data analysis over a single dataset where state should persist so you73revise without reloading.7475---7677## References (on demand)7879- `references/exemplars.md` — three in-context-learning exemplars with exact80 `kernel.exec` tool-call syntax and trace outputs, demonstrating81 `KernelSession` state persistence.82- `references/operations.md` — degradation / fail-closed contract, the83 `agentbox.toml` manifest gate, kernel session semantics (reset / interrupt /84 inspect, cold-start, serialisation across sessions), identity + ecosystem URN85 tagging, and composition with `expel-lesson-extractor`,86 `voyager-skill-library`, and `tree-search-coder`.87- `references/empirical-priors.md` — benchmark lifts, token-efficiency data,88 RSS/cost accounting for swarm sizing, and the ADR/DDD/PRD + arxiv citation89 list.