Tool Forges (experimental)
A chain often fails not because the plan is wrong, but because a step has to
do something a language model does badly: call a real API, or compute an
exact number from a file. Both forges add a tested capability before the
author writes the chain, instead of hoping an llm step gets it right.
Both follow the same rule: tests before admission, and a blind judge. The judge does not see who wrote the tool, only its contract, inputs and outputs.
API tool forge
Section titled “API tool forge”Package mmar_mage/forge/, arm field forge_enabled, since 9 October 2026.
- Need. The plan marks a capability the declared tools do not cover.
- Sources. A local catalogue, APIs.guru (OpenAPI specs), the official MCP registry and an optional web search hook. Sources return metadata only; nothing is installed or run at this point.
- Selection. BM25 ranking to a shortlist, then a choice of one operation.
- Adapter. A read-only HTTP tool from one OpenAPI
GEToperation, or a remote MCP server’s tool (executed with CARL’s native MCP client when themcpSDK is installed). - Tests. Proposed test calls, recorded as cassettes so reruns do not hit the network.
- Judge. A blind review of the recorded behaviour, then admission into the capability list the author sees.
Code-tool forge
Section titled “Code-tool forge”Module mmar_mage/code_forge.py, arm field code_forge, commit acf7091
(2 November 2026). Hypothesis H5 of the memory study: a missing exact
computation is forged once and reused across a task family.
flowchart LR
Plan["plan node<br/>compute + code_tool spec"] --> Store{"stored tool<br/>for this spec?"}
Store -->|yes: rerun its tests| Use
Store -->|no| T["tester<br/>cases from the spec only"]
T --> C["coder<br/>def run(inputs)"]
C --> S["sandbox tests<br/>schema + expected values<br/>+ empty input"]
S -->|fail, ≤ 2 repairs| C
S -->|pass| J["blind judge"]
J -->|admit| Save[("tool store")] --> Use["author calls it<br/>through a code step"]
- The planner marks exact computation over supplied data as a
computenode with acode_toolspec: name, general purpose, typed inputs and outputs. - Tests first. A tester call that never sees code writes cases with exact expected outputs from the spec alone.
- Code. A coder call writes one pure
def run(inputs), standard library only. - Sandbox tests. Every case plus an empty-input case runs in CARL’s code step sandbox. Output must validate against the tool’s schema and match the expected values. Failures go back to the coder (two repairs by default).
- Judge. Checks that the inputs carry enough data, that the code derives the outputs (no answers copied from tests) and handles the general case. It may excuse at most one wrong expectation. If it blames the specification, the forge stops and the node goes back to the author.
- Store and reuse. An admitted tool goes to a local JSON store or to
IdeaL as a
toolentity (tool keymage-code:<name>, runtimecarl-code, artifact filesrun.pyandtool.json, checked by hash on read). Later tasks get a card per stored tool.
In the chain, the author calls the tool with a code step whose source is
$memory.tools.<name>. The compiler inserts the tested program as a
memory write step, so the chain carries its own code and stays
self-contained when reused. After execution the runner counts uses and
successes; a tool used twice without a success is demoted.
Defaults (ForgeSettings): at most 2 tools and 10 model calls per
generation, 2 repairs, 300 s, judge on. The forge has its own model client
and budget, separate from the generation’s.
Runtime facts it relies on
Section titled “Runtime facts it relies on”- A CARL
codestep accepts only context references ininput_mapping, so the compiler moves every constant argument into a separate memory write step. - The program cannot be inline:
sourcemust be a reference, so it lives in a memory write step that runs first and is never the final step. - The IdeaL catalog returns at most one tool per query, and IdeaL keeps tool code only as an artifact in the server’s git store. Without a configured store the write fails and the tool stays in the local mirror.
Sandboxes
Section titled “Sandboxes”| Runtime | Use |
|---|---|
docker | Measurements. No network, read-only, 256 MB, 1 CPU, 32 processes. |
local-seatbelt | macOS development only: sandbox-exec, no network, writes only in the workspace, secret directories unreadable. Wall time enforced; CPU, memory and process limits are not. |
local-double | Plain subprocess, unit tests only. |