Loading patternsโฆ
Code as Action (CodeAct)(CA)
Instead of emitting one JSON tool call per turn, the agent's action space is executable code that orchestrates tools with loops, conditionals, and variables. A single code block can call many tools, branch on results, and keep intermediate data in the runtime rather than passing every result back through the context window. Anthropic reports roughly a 98 percent token reduction on some multi-tool workflows when tools are called from code via MCP.
In 30 seconds
- What
- Agent writes executable code that calls multiple tools with loops, conditionals, and variables in a single turn, keeping intermediate results in runtime.
- When to use
- Multi-tool workflows with iteration, branching, or state that would otherwise require many sequential model round-trips and context window passes.
- Watch out
- Code execution errors halt the entire workflow; agent must debug and retry, and sandboxing overhead can negate token savings on simple tasks.
Ask the AI expert about this pattern
Opens the assistant with your question prefilled. You review it before sending.
Code as Action (CodeAct): Overview
Instead of emitting one JSON tool call per turn, the agent's action space is executable code that orchestrates tools with loops, conditionals, and variables. A single code block can call many tools, branch on results, and keep intermediate data in the runtime rather than passing every result back through the context window. Anthropic reports roughly a 98 percent token reduction on some multi-tool workflows when tools are called from code via MCP.
- Action space is executable code, not a single JSON call
- Loops, conditionals, and variables compose many tool calls per turn
- Intermediate results stay in the runtime, not the context window
- Fewer model round-trips for multi-step, multi-tool work
- Large token reduction on tool-heavy workflows (up to ~98 percent reported)
- Tools exposed to code (for example via MCP) with results filtered before return
The Agent Architect
One pattern, one tradeoff, one production failure story. A short weekly briefing for people building agentic systems.
Weekly email, one-click unsubscribe. We only use your address to send the briefing.
References
The papers, specifications, and repositories this pattern is based on.
ReasoningLayer Box
Run these agents in your own office, with unlimited tokens.
The ReasoningLayer Box puts the models, the memory and your AI workers on a box at your place. Nothing leaves the building, nothing is metered, and there is no price per person. The design partner program is open by application: our lowest price and a direct say in the roadmap.
- No token meter, no credits
- Your data never leaves your building
- One box for a team of 10 to 20