# Free models: the `free` rung and the `delegate` call site

<!-- toc -->
- [Turning it on](#turning-it-on)
- [The two call sites](#the-two-call-sites)
- [What `delegate` may hand over](#what-delegate-may-hand-over)
- [The contract with the answer](#the-contract-with-the-answer)
- [Unattended runs](#unattended-runs)
- [Requirements](#requirements)
<!-- /toc -->

Layer 2 of model routing. With `/multi-agent:route-on --free`, simple text work
that the pipeline does itself goes to the multi-agent-mcp's verified
free-model chain instead of a Claude rung. Decisions, plans, code, reviews,
triage and security judgements never do.

Off by default. Nothing here changes a run until routing and its free chain are
both on.

## Turning it on

```bash
bash "$HOME/.claude/lib/route-state.sh" on --free                    # no-training providers (Groq, Cloudflare) and a local Ollama
bash "$HOME/.claude/lib/route-state.sh" on --free --allow-training   # also every other chain-eligible provider in the catalog
```

`--free` sets `modelRouting.free.enabled`, adds `bulk-read` and `delegate` to
`scope`, and lists which providers are usable. One free key is enough to start:
Groq's (<https://console.groq.com/keys>), stored with `/multi-agent:setup` or
`credential-store.sh set llm-groq -`, or exported as `GROQ_API_KEY` for the
server. `/multi-agent:route-status` reports the last seven days: tasks answered
free and verified, tasks handed back to Claude, and the tokens kept off Claude.
`/multi-agent:doctor` warns when the switch is on and no provider is usable;
`--probe` sends each provider one tiny request.

**Data policy.** `allowTraining: false` (the default) keeps text to providers
whose free tier does not train on prompts (Groq, Cloudflare Workers AI) and a
local Ollama. The provider list is data: the toolkit's `tools/llm/catalog/`
carries each provider's base URL, data use, commercial terms, sign-up friction
and a source quote per fact, and `mcp__multi-agent__llm_providers`
reports it.
Choosing or adding a provider, or reading an `ESCALATE_TO_CLAUDE` result, goes
through the `ai-common-toolkit:free-llm-apis` skill, which carries the same
catalog with its terms and the chain's fallback order.
`--allow-training` adds free tiers that may train on prompts or whose data use
is not stated. Corporate source, tickets and logs belong under the default.

## The two call sites

| Call site | Who calls | What goes free | Fallback |
| ----------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `bulk-read` | `bulk-read.sh`, when the read gate diverts a large file | the line-numbered summary of one file, validated against `schemas/bulk-read-output.schema.json` and the file's line count | the host's one-shot call, taken from `schemas/hosts.json` (`headless.argv`), on the `bulkRead.model` rung or `haiku`: `claude -p --model <rung>` on Claude Code. A host the registry gives no such call for degrades and names the reason, and the caller reads the region itself |
| `delegate` | a skill or phase, through the `llm_delegate` MCP tool | one of the simple tasks below | the session does the task itself |

Both ask the router first, so the policy has one implementation:

```bash
bash "$HOME/.claude/lib/model-dispatch.sh" delegate --default host   # prints `free` or `host`
```

`free` means call `llm_delegate`; anything else means do the task in-session as
before. A subagent is dispatched by the host, so the router never answers `free`
for one.

## What `delegate` may hand over

Only tasks whose answer can be checked against their own source:

| Task | `llm_delegate` | Development | Analysis |
| ------------------------------- | ------------------------------- | ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| Summarize a long text | `task: summarize` | build and test logs, crash logs, a long file the plan only needs the shape of | Confluence pages, Swagger descriptions, Jira descriptions and comment threads, `generic-doc` links fetched through `web_scrape`, research documents |
| Pull named fields out of a text | `task: extract` with a `schema` | ticket keys, endpoints, error codes, failing test names from a log | acceptance criteria, endpoints and field lists, dates and owners from a document |
| Pick one label | `task: classify` with `labels` | commit type from a diff summary, a log line's severity | issue type, affected platform, a comment's intent |
| Translate a draft | `task: translate` | localization drafts for review (the resources repo stays the contract) | a source document into the output language |
| Write a draft from a source | `task: draft` | a commit body or PR description draft from the diff summary, then the humanizer | a section draft the analysis author then edits |

In analysis Phase 1, a fetched `confluence`, `document`, `generic-doc` or
`jira` text longer than about 8,000 characters is summarized before it is
reasoned over: ask the router once per run, then `extract` with a schema for
the fields a section needs (acceptance criteria, endpoints, field lists, dates,
owners) and `summarize` for the rest. The verified answer is the working copy
for drafting; the raw fetch stays in its evidence bucket and Section 21 still
cites the source. `binding: true` standards are never delegated: their wording
is the requirement.

Never handed over: deciding what to build, the plan, any code or diff, review
findings and triage, security or licence judgements, anything written to a
ticket, PR or channel without the session reading it first.

## The contract with the answer

- A verified answer is still a third-party model's text. It comes back fenced
  as untrusted; the session reads it as data and checks it against the plan
  like any other input.
- `ESCALATE_TO_CLAUDE` is not an error. It lists a reason per provider; the
  session does the task itself and the run continues. Nothing is retried in a
  loop and no weaker answer is substituted.
- The toolkit scrubs key-shaped strings before anything leaves the machine.
  Text that must not leave the machine at all (credentials, personal data,
  customer records) is not delegated, whatever the policy says.

## Unattended runs

`llm_delegate` runs in the MCP server, outside the run's OS sandbox, and reads
provider keys from the credential store; agent-guard allows it only while
`route-on --free` is on. `bulk-read.sh` runs inside the sandbox, which cannot
read the Keychain: it uses the free chain only when the provider key is in the
run's environment, keeps the toolkit's quota and usage files under
`~/.multi-agent-unattended/toolkit-index`, and reads on haiku otherwise. The
installer adds the allowed provider hosts to the sandbox network list
(`lib/unattended-profile-check.mjs` `prefsHosts`) when the free chain is on;
re-run `install --unattended` after turning it on.

## Requirements

`@mmerterden/multi-agent-mcp` ≥ v3.21.0 (`llm_delegate`,
`llm_providers`, the `multi-agent-mcp-llm` CLI). `lib/toolkit-llm.sh` finds
the CLI through `MULTI_AGENT_MCP_LLM`, then `PATH`, then `npx`.
