peterfriese/system-one-foundation-models/clef-foundation-models
Claude Code and agent skill by peterfriese/system-one-foundation-models
- community
Checking that the SKILL.md file is still in the repository.
Evaluate Cloudflare Clef (27B) and Clef-Flash (9B) multimodal System One decision models natively through Apple's Foundation Models framework in Swift 6. Use when building iOS 27+, macOS 27+, or visionOS 27+ apps that evaluate strongly-typed @Generable structs and enums over visual attachments (camera frames, photos, screenshots) using LanguageModelSession, deploying via Cloudflare Workers AI edge, Cloudflare AI Gateway, or local inference runners, implementing visual confidence routing (RoutingPolicy, NoulJudgement, ScoreValue), integrating AVFoundation camera pipelines, or writing deterministic offline unit tests with MockClefBackendProtocol.
Install
npx vskill@latest install peterfriese/system-one-foundation-models/clef-foundation-modelsSKILL.md
Cloudflare Clef Foundation Models Bridge
[!TIP]Multi-Backend Architecture: For projects integrating on-device Core ML (LayaOnDevice), self-hosted HTTP daemons (LayaFoundationModels), and TypeSafe Jev cloud alongside Cloudflare Clef, refer to the unifiedsystem-one-foundation-modelsskill and package target. This skill focuses specifically on Cloudflare Clef & Clef-Flash multimodal decision evaluation, AVFoundation camera integration, and Cloudflare edge gateway infrastructure.
This skill guides the design, implementation, and testing of applications integrating Cloudflare Clef (27B) and Cloudflare Clef-Flash (9B) multimodal decision models via Apple's Foundation Models framework (FoundationModels) in Swift 6.
1. Core Mental Model: Multimodal Decisions, Not Autoregressive Chat
Cloudflare Clef and Clef-Flash are multimodal System One decision models, not conversational vision-language models (VLMs). Rather than autoregressively generating textual captions or chat descriptions, Clef evaluates application text and visual attachments in a single forward pass, returning calibrated decision primitives in sub-100ms with zero output tokens (output_tokens: 0).
- Multimodal State: Contextual text plus up to 4 image attachments passed inside
Prompt { ... }. - `@Generable` Type $\to$ Decision Questions: Strongly-typed Swift structs and enums define the questions evaluated over that visual scene.
- Dual Signal Output:
- The Typed Content: What the model judged (
response.contentcontaining enums, booleans, and rubric scores). - Calibrated Epistemic Uncertainty: Whether to automate the action (
response.judgement(...),response.decision(...),response.scoreValue(...)).
Model Family Comparison
| Model | Parameters | Target Workflows | Cold Latency | Key Strengths | |
|---|---|---|---|---|---|
| Clef-Flash | 9B (Qwen3.5 base) | Interactive mobile apps, camera viewfinder triage, real-time scanning | ~80–120ms | Ultra-fast edge execution, low bandwidth overhead, ideal for live iOS camera streams. | |
| Clef | 27B (Qwen3.8 base) | High-resolution document forensics, multi-page KYC verification, subtle damage audit | ~250–450ms | High discriminative capacity for nuanced enterprise documents, fine print, and micro-defects. |
2. Pluggable Endpoint Topologies (ClefEndpoint)
Configure the target endpoint via the ClefEndpoint enum. ClefLanguageModel connects to global Cloudflare edge nodes or local inference servers:
3. Multimodal Inputs with Apple Foundation Models (Attachment)
Passing Image Attachments via Prompt
Visual inputs are attached directly to standard Apple Foundation Models Prompt builder blocks using Attachment(cgImage) or Attachment(data:type:):
Apple Framework Capability Gating: LanguageModelCapabilities.Capability.vision
Apple's FoundationModels framework performs client-side capability validation before passing generation requests to an underlying LanguageModelExecutor.
If a caller submits a Prompt containing visual attachments:
- The session runtime verifies
model.capabilities. - The capability set must include `.vision` alongside
.guidedGeneration. - If
.visionis missing,LanguageModelSessiontraps immediately withLanguageModelSession.GenerationError.unsupportedCapability: "The selected model does not support image input. Consider trying again with a different model." ClefLanguageModelexplicitly advertises both capabilities:
``swift public var capabilities: LanguageModelCapabilities { LanguageModelCapabilities([.guidedGeneration, .vision]) } ``
- Supported MIME/UTTypes: PNG (
.png), JPEG (.jpeg), and WebP (.webP).
Image Preprocessing Best Practice: 1024px Downsampling & 0.8 JPEG Compression
Modern Apple mobile hardware captures photos at resolutions up to 48MP. Uploading raw, uncompressed frames or large PNGs leads to severe failure modes (see Tech Note 0015):
- BPE Tokenizer Blowout: Cloudflare's edge gateway serializes images under the
imagesarray as RFC 2397 Data URLs (data:image/jpeg;base64,...). Unrecognized schemas or oversized text blobs fall back to standard Byte-Pair Encoding (BPE) text tokenizers, calculating 700,000+ input tokens and instantly exceeding the 64k context limit (HTTP 413). - Payload & Patch Inflation: Uncompressed frames consume 10–30 MB of bandwidth and generate excessive vision transformer patches, degrading latency.
Production Best Practice: Always downsample camera frames to a maximum dimension of 1024px and compress to JPEG at 0.8 quality:
This reduces upload payloads to 100–300 KB, maps cleanly to ~1,000 vision patch tokens, and guarantees sub-100ms edge processing.
Multimodal Guardrails
SystemOneImage.Guardrails enforces strict validation prior to wire serialization:
- Maximum Images: Up to 4 images per evaluation (
Guardrails.maxImageCount = 4). - Maximum Resolution: Up to 16 megapixels per image (
Guardrails.maxMegapixels = 16.0). - Maximum Payload Size: 13 MiB total payload cap (
Guardrails.maxPayloadBytes = 13 * 1024 * 1024).
4. @Generable Schema Modeling for Visual Decisions
SchemaTranslator maps Apple @Generable types directly to System One decision primitives:
| Swift Type & Annotations | System One Primitive | Question Key Convention | Output Behavior | |
|---|---|---|---|---|
Bool | `noul` | Field name (e.g. "isRecognized") | Calibrated probability of truth ($0.0 \dots 1.0$). Decodes to Swift Bool. | |
enum: String | `choice` | Field name (e.g. "itemCategory") | Discrete categorical selection among defined enum cases. | |
Int + @Guide(.range(min...max)) | `score` | Field name (e.g. "conditionScore") | Ordinal rubric scoring mapped to integer levels with continuous weighting. | |
@Guide(description: "...") | `instructions` | N/A | Natural language guidance steering visual judgment. |
Negative Constraints (Strictly Forbidden)
- ❌ No unconstrained `String` properties: Clef models do not generate free-form text. A
Stringproperty without enum choices throwsSystemOneError.invalidSchema. - ❌ No unstructured collections: Arrays of open-ended values (
[String]) or dictionaries are unsupported. - ❌ No requests without schemas: Calling
session.respond(to: prompt)without agenerating:schema throwsSystemOneError.structuredOutputRequired. - ❌ No tool calling:
LanguageModelCapabilitiesonly includes[.guidedGeneration, .vision].
Production Schema Example
5. Visual Confidence Routing with RoutingPolicy
Never write naive if prob > 0.5 checks:
- `0.50` indicates maximum epistemic uncertainty, not "half true".
- The undecided band ($0.35 \dots 0.65$) indicates the model is genuinely undecided (
answer == nil). - A probability of
0.05is a confident "no" ($\text{decisiveness} = \max(p, 1 - p) = 0.95$), which routes to.autowithanswer: false.
Use RoutingPolicy to triage visual judgments into operational actions:
6. AVFoundation Camera Integration Pipeline
For interactive iOS, iPadOS, and macOS apps, capture live camera frames, downsample using CIContext, and evaluate via LanguageModelSession:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/clef-foundation-models/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/peterfriese/system-one-foundation-models/clef-foundation-models)