Skip to content
Star33Playground

Code-Action Strategy

ExperimentalLast updated 2026-11-17 · c98e90871

code-action is an experimental reasoning strategy. How it compares to the other seven strategies, and which model size it needs, is on Choosing a Reasoning Strategy. Instead of calling tools one at a time in a ReAct loop, the LLM writes a single code block that orchestrates multiple tools as ordinary async function calls. The block runs in an isolated Worker-thread sandbox.

  • Tasks requiring multi-step numeric computation
  • Any task where tool call order is deterministic and parallelizable
  • When token efficiency matters more than step-by-step observability
const agent = await ReactiveAgents.create()
.withReasoning({ defaultStrategy: "code-action" })
.build();
  1. Plan — LLM receives TypeScript function signatures for each registered tool and writes a single async IIFE.
  2. Execute — The IIFE runs in a Node.js Worker thread. Tool calls are routed back to the host via postMessage round-trips.
  3. Observe — Tool call log and final return value are formatted as an observation message.
  4. Reflect — Verifier checks the result; if it fails, the LLM regenerates code with feedback.
agent:my-agent ← AGENT span
code-action:plan ← LLM span (code generation)
code-action:execute ← TOOL span (sandbox run)

Tool calls made from generated code go through the same tool-policy gate as every other strategy (v0.14): allowedTools and the .withContract() forbidden-tools deny-list are enforced per call inside the sandbox — a blocked tool is recorded as a failed call and never executes, even when the code names it directly.

Reliability note: unlike the kernel-hosted strategies, code-action runs a coarse plan/execute/verify loop with no per-iteration repair hook and no kernel (no thought ledger, no loop detector). Its honesty guarantees come from the shared terminal mint it exits through: declared requiredTools are checked post-run (groundedOnRequired verdict), the contract-coverage cap applies, and a failing verifier verdict ships partial, never completed. Prefer a kernel-hosted strategy when you need mid-run steering, progress arbitration, or delegation composition.

@experimental — v0.11.1

Install

Bun (recommended)bun add reactive-agents
Node 22.5+npm install reactive-agents

Get notified on new releases