Skip to content

Tool Step

ToolStepDescription calls a Python function you registered on the context. Its behaviour is configured with ToolStepConfig.

Tools are looked up by name in the context’s tool registry:

def calculate_growth(data: str) -> dict:
return {"growth_rate": 0.15, "trend": "positive"}
context.register_tool("calculate_growth", calculate_growth)

Both plain and async functions work. A plain function runs in a worker thread (asyncio.to_thread); an async function is awaited directly. Both are bounded by ToolStepConfig.timeout.

FieldTypeDefaultPurpose
tool_namestrrequiredName of the registered tool.
tool_descriptionstr""What the tool does.
parameterslist[ToolParameter][]Declared parameters: types for coercion and the required flag.
input_mappingdict[str, str]{}Tool parameter name → reference or quoted literal.
timeoutfloat30.0Seconds per call.
error_recoveryToolErrorRecovery | NoneNoneRetries and fallback tools (below).
allowed_tool_tagslist[str] | NoneNoneTag allowlist. The step refuses a tool whose registered tags don’t intersect it.
output_keystr"result"Accepted for compatibility. The tool executor does not read it.
retry_on_errorboolTrueAccepted for compatibility. The tool executor does not read it; use error_recovery.
FieldTypeDefaultPurpose
namestrrequiredParameter name (matches the input_mapping key).
typestr"string"string, int, float, bool, list or dict. A string value is coerced to this type; list and dict are parsed as JSON.
descriptionstr""Free text.
requiredboolTrueSee “Unresolved inputs” below.
defaultAnyNoneInformational.
from mmar_carl import ToolStepDescription, ToolStepConfig, ToolParameter
ToolStepDescription(
number=2,
title="Calculate growth",
dependencies=[1],
config=ToolStepConfig(
tool_name="calculate_growth",
parameters=[ToolParameter(name="data", type="string")],
input_mapping={"data": "$history[-1]"}, # feed step 1's output
),
)

Inputs from the host: $outer_context.<field>

Section titled “Inputs from the host: $outer_context.<field>”

When the host passes structured input in ReasoningContext.runtime_input, a mapping can read one field of it:

context = ReasoningContext(
outer_context="Plan a trip.", # prompt text for LLM steps
runtime_input={"user": {"city": "Oslo"}},
api=client,
)
ToolStepConfig(
tool_name="weather",
parameters=[ToolParameter(name="city", type="string")],
input_mapping={"city": "$outer_context.user.city"}, # → "Oslo"
)

With runtime_input set, $outer_context resolves to runtime_input, not to the prompt text. Without it, $outer_context.<field> reads from outer_context when that holds a JSON object. runtime_input is copied into every per-step context, so the reference works inside chain.execute() and in parallel batches. Details: dynamic references.

If a required parameter resolves to None, the step fails and the tool is not called:

CARL_TOOL_INPUT_UNRESOLVED: required parameter 'city' resolved to null; check input_mapping and runtime input.

A parameter is required when its ToolParameter says required=True (the default). Without a declaration, CARL inspects the function: a parameter with no default value is required, and so is any name the signature does not list (for example a **kwargs tool). Mark optional inputs with ToolParameter(..., required=False) or give the function parameter a default.

Typical causes:

  • a typo in a reference, or a $memory key no step writes;
  • $outer_context.<field> when the field is absent from runtime_input;
  • an unquoted literal. A string that is neither a $ reference nor quoted is looked up as a metadata key and usually resolves to None. Write literals in quotes and declare the type:
ToolStepConfig(
tool_name="total",
parameters=[ToolParameter(name="values", type="list")],
input_mapping={"values": '"[100, 200, 300]"'}, # quoted → parsed as JSON list
)

ToolErrorRecovery adds retries and fallback tools:

FieldTypeDefaultPurpose
retry_maxint0Extra attempts after the first failure.
retry_delayfloat0.0Seconds between attempts.
on_timeoutstr | NoneNoneFallback tool to call on timeout.
on_exceptionstr | NoneNoneFallback tool to call after retries are exhausted.
from mmar_carl import ToolStepConfig, ToolErrorRecovery
ToolStepConfig(
tool_name="web_search",
error_recovery=ToolErrorRecovery(
retry_max=2,
retry_delay=1.0,
on_timeout="cached_search", # registered fallback tool
on_exception="cached_search",
),
)

The fallback tool receives the same keyword arguments as the primary tool. CARL_TOOL_INPUT_UNRESOLVED is raised before any attempt, so retries and fallbacks never run with a missing input.

On success the step result has:

  • result_data: the tool’s return value (read it later with $steps.<n>.result_data or $metadata.step_<n>). Since 0.5.0 a string whose whole content is a JSON object or array is decoded, so a tool that returns JSON text can feed $steps.<n>.result_data.<field> downstream;
  • result: the value as a string (JSON for non-strings, the raw text for strings);
  • tool_name: the tool that actually answered, i.e. the fallback’s name when ToolErrorRecovery switched to one;
  • a history entry Step N. <title> [TOOL: <name>] with the result.

A timeout or exception gives success=False with error_message. Whether dependent steps still run depends on fail-fast.

A chain tool is registered under its own name and is called by a tool step like any function. It returns a typed envelope. Since 0.5.0 the tool step fails when the envelope’s status is not completed; the envelope stays in result_data.

execute_eager_tools() (new in 0.5.0, experimental) runs a static graph of tool steps without the batch scheduler. A tool starts as soon as its declared dependencies have succeeded and a worker is free. Results come back in declaration order.

import asyncio
from mmar_carl import ToolStepConfig, ToolStepDescription
from mmar_carl.eager_tools import execute_eager_tools
async def add_one(value):
return {"value": value + 1}
async def double(value):
return {"value": value * 2}
steps = [
ToolStepDescription(number=1, title="Add one", config=ToolStepConfig(
tool_name="add_one", input_mapping={"value": "$outer_context.value"})),
ToolStepDescription(number=2, title="Double", dependencies=[1], config=ToolStepConfig(
tool_name="double", input_mapping={"value": "$steps.1.result_data.value"})),
]
results = asyncio.run(execute_eager_tools(
steps,
tools={"add_one": add_one, "double": double},
outer_context={"value": 20},
max_concurrency=2,
))
# [step 1 → {'value': 21}, step 2 → {'value': 42}]

It is a host API, not a step type, and it is imported from mmar_carl.eager_tools (it is not a top-level export). Rules:

  • Tools are an explicit mapping of trusted async def functions. They must be stateless, safe in any order the dependencies allow, and responsive to cancellation.
  • A step reads only JSON from $outer_context, from its declared ancestors’ results, or quoted literals. Each step gets its own copy, so a tool that mutates its input cannot change another step’s input. The graph and the reference scope are validated before any tool runs.
  • A failed step blocks its descendants; they come back with success=False and skipped=True. Unrelated branches still finish. ToolStepConfig.timeout fails one step; the overall timeout cancels in-flight tools, waits for their cleanup and raises TimeoutError.

Use ReasoningChain.execute_async() for anything with memory, history, events, conditional routing, checkpoints, dynamic steps or RE-PLAN.

Use the @carl_tool decorator and dynamic discovery to register tools in bulk (from a module, a glob, a factory, or a pinned Git commit).