Tool calling

Choose parser behavior deliberately.

Models do not emit one universal tool-call syntax. AFM detects several native formats and lets you decide whether to preserve, repair, or expose their output.

Three modes

ModeStart optionUse it when
NativeDefaultYou want the model family's narrow parser and parity with its documented format.
Repair--tool-call-parser afm_adaptive_xmlA real client needs resilience to JSON-in-XML, type mistakes, nullable schemas, or fuzzy names.
Raw--tool-call-parser noneYou are inspecting the exact emitted markup or diagnosing a template/parser mismatch.
# Production-oriented repair mode
afm mlx -m <model> \
  --tool-call-parser afm_adaptive_xml \
  --fix-tool-args

# Parser-free inspection
afm mlx -m <model> --tool-call-parser none

Model-native formats

AFM detects tool conventions using the model configuration and chat template. Supported families include JSON, Qwen XML, Gemma, GLM, Kimi, MiniMax, LFM2, and related variants. Detection is not a claim that every checkpoint was trained equally well for tools; it selects the compatible parser.

Tool choice

ValueMeaning
autoThe model may answer normally or call a tool.
noneTool calls are disabled for the request.
requiredThe response must select a tool.
Named functionForce one declared function.

Streaming responses expose OpenAI-style tool-call deltas while ordinary assistant content continues through normal content chunks.

Structured output is a separate layer

response_format: { "type": "json_object" } and JSON-schema response requests tell AFM what the client expects. Token-level enforcement is enabled only when the server starts with --enable-grammar-constraints.

SCHEMA=$(jq -c . schema.json)
afm mlx -m <model> \
  --guided-json "$SCHEMA" \
  --enable-grammar-constraints

A server-level --guided-json schema applies when an individual request omits response_format. Tools, grammar-constrained output, logprobs, and stop sequences also make speculative MTP/EAGLE3 requests ineligible for their fast path.

Client patterns that matter

  • OpenCode and Cline: stable, long system prompts benefit from --enable-prefix-caching.
  • Multiple tabs or sessions: set --concurrent N to the number of active conversations you intend to serve.
  • OpenClaw: --openclaw-config emits a provider block with detected model metadata.
  • Required API key field: use any placeholder value; AFM does not authenticate localhost requests by default.