> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch34-infrastructure/34.6-source-deep-dive-media-candidate-chain-and-vision-skip.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 34.6 Source Deep Dive: The Media Candidate Chain and the Vision Skip

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~230,000 tokens, Output \~8,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`); line numbers refer to this commit

***

§34.3 covered what link and media understanding are for. This section looks at its model-selection logic — the most elegant implementation of §44.2's principle *downgrade configuration errors into performance problems*.

## 34.6.1 The Pipeline: Pre-Digesting Inbound Attachments

When a message arrives with an image, audio, or video, `applyMediaUnderstanding` (`src/media-understanding/apply.ts`) converts attachments into text descriptions or transcripts in **image → audio → video** order (concurrency 2 by default) and folds them into the model context.

## 34.6.2 A Probe Order, Not a Config Switch

Model selection for each capability is an **explicit candidate chain**:

* If `tools.media.<capability>.models` is configured → try each in order (an entry may be a provider API call **or a local CLI command**);
* If not configured → enter auto probing:

```ts
// src/media-understanding/runner.ts:453-485
async function resolveAutoEntries(params): Promise<MediaUnderstandingModelConfig[]> {
  const activeEntry = await resolveActiveModelEntry(params);  // ① can the current primary model do it?
  if (activeEntry) return [activeEntry];
  if (params.capability === "audio") {
    const localAudio = await resolveLocalAudioEntry();        // ② local transcription CLI
    if (localAudio) return [localAudio];
  }
  if (params.capability === "image") {
    const imageModelEntries = resolveImageModelFromAgentDefaults(params.cfg);
    if (imageModelEntries.length > 0) return imageModelEntries;
  }
  const gemini = await resolveGeminiCliEntry(params.capability); // ③ gemini CLI
  if (gemini) return [gemini];
  const keys = await resolveKeyEntry(params);                    // ④ pick by available API key
  if (keys) return [keys];
  return [];
}
```

**The local audio path probes sherpa-onnx → whisper.cpp → whisper in order** (`runner.ts:306-316`) — **so voice messages can be transcribed with no API key at all.**

The remote fallback picks by `AUTO_AUDIO_KEY_PROVIDERS` (openai / groq / deepgram / google / mistral, `defaults.ts:37-43`), with matching default models like groq's `whisper-large-v3-turbo` (`defaults.ts:30-35`).

> **The key design: the local-vs-remote choice is a probe order, not a configuration switch.**
>
> What's the difference? As a switch, a user who hasn't installed the local tool but enabled "use local" simply gets failed voice messages. As a probe order, a missing local install falls through to the remote API automatically.
>
> **It downgrades a configuration problem into a performance/cost problem** (§44.2.3's third point). Consumer-facing software especially should use this — the probability of a user misconfiguring far exceeds the probability of a component failing.

## 34.6.3 The Vision Skip: Don't Digest Twice

Images have an important short-circuit:

```ts
// runner.ts:707-716
// Skip image understanding when the primary model supports vision natively.
// The image will be injected directly into the model context instead.
if (capability === "image" && activeProvider) {
  const catalog = await loadModelCatalog({ config: cfg });
  const entry = findModelInCatalog(catalog, activeProvider, params.activeModel?.model ?? "");
  if (modelSupportsVision(entry)) {
    logVerbose("Skipping image understanding: primary model supports vision natively");
```

When the primary model supports vision itself, **the image goes into context as the original rather than a secondhand text description**.

Two gains:

1. **Saves an API call**;
2. **Avoids the describing model's information loss** — "the image contains an error dialog" is far worse than letting the primary model look at the image itself.

**Audio has no equivalent short-circuit**, because transcribed text is more useful for retrieval and citation (you can search a transcript; you can't search audio).

### Every decision is recorded structurally

Which entry was chosen, and why something was skipped or failed, are all recorded as a structured `MediaUnderstandingDecision`.

Another confirmation of §44.2.4's warning: **a degradation chain must come with observability**, or the user has no idea why their voice transcription got so bad (it may have quietly degraded to a weaker model).

## 34.6.4 Three Supporting Subsystems

| Subsystem                 | Responsibility                                                    | Notable detail                                                                                                                                                                                                           |
| ------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `src/link-understanding/` | Extract URLs from messages and hand them to a summarization model | **SSRF blocklist filtering happens at extraction time** (`detect.ts:19-32`'s `isBlockedHostnameOrIp` reuses the network layer's protection directly); markdown link syntax is stripped first, recognizing only bare URLs |
| `src/media/`              | Shared media infrastructure                                       | Fetch limits, MIME sniffing, ffmpeg wrapping, inbound path policy                                                                                                                                                        |
| `src/tts/`                | Outbound speech                                                   | **The default provider is the free `edge`** (Microsoft Edge TTS), switchable to OpenAI / ElevenLabs, with streaming PCM support                                                                                          |

The link-understanding "filter at extraction" point is worth expanding: **it doesn't check at fetch time, it filters out private-network addresses the moment a URL is recognized.**

That way no downstream code path can ever hold a private-network URL — **moving protection to the point where data enters the system** is more reliable than checking at every point of use.

"Recognize only bare URLs, strip markdown link syntax" is also protective: a disguised form like `[looks normal](http://192.168.1.1/admin)` won't be mistaken for a safe link.

***

## Section Summary

1. **The candidate chain's core design is "a probe order, not a config switch"** — a missing local tool falls through to remote automatically, **downgrading a configuration problem into a performance/cost problem**; the local audio path probes sherpa-onnx → whisper.cpp → whisper, so voice transcription works with no API key.
2. **The vision skip**: when the primary model natively supports vision, the image goes into context directly rather than through a secondhand description — saving a call and avoiding the describing model's information loss. Audio doesn't short-circuit because transcripts are more useful for retrieval and citation.
3. **Every selection decision is recorded as a structured `MediaUnderstandingDecision`** — a degradation chain must come with observability.
4. **Link understanding filters against the SSRF blocklist at extraction time** and recognizes only bare URLs (stripping markdown syntax to prevent disguise) — **moving protection to the data's entry point** is more reliable than checking at every use site.
5. TTS defaults to the free Microsoft Edge TTS — another "works with zero configuration" default choice.
