Skip to content

[Feat] Add Cloudflare Clef / Clef-flash as a served System One backend - #131

Open
Birfy wants to merge 1 commit into
mainfrom
issue-126-clef
Open

Birfy wants to merge 1 commit into
mainfrom
issue-126-clef

Conversation

@Birfy

@Birfy Birfy commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Required human contributor answers

Per the repo owner's (Danyang, @Birfy) standing instruction, these are filled from the issue (#126) instead of waiting for separate human answers.

  1. What outcome are you trying to achieve?

    Answer: Agents can call Cloudflare Clef or Clef-flash as a served System One decision model over HTTP (--model clef) for text, and for screenshots when the observation has images, without loading weights in process ([Feat] Add Cloudflare Clef / Clef-flash as a System One decision backend #126).

  2. What is the highest-leverage variable for that outcome?

    Answer: Whether the HTTP body matches the official Clef / Workers AI schema (model, state, questions, optional images data URLs, max 4) on both Workers AI and local POST /v1/systemone, with a clean refusal when URL/token or the response body is missing or bad — and without inventing OneJev media / <image:N> mapping or a videos / score path our interface does not have.

  3. How will this work move that variable rather than create busywork?

    Answer: It adds a dedicated served adapter (same shape as clm / onejev): one deadline per decision, provenance (url, request_id, served model name, usage), and contract tests against a stub server so CI does not call Cloudflare or a GPU.

  4. Who is the customer or user, and what do they actually need?

    Answer: People who want --model clef against Workers AI or a local SGLang Clef server for choice/noul decisions, including optional screenshots, without waiting for a live qualification run.

After answering the four questions: is a PR needed at all to achieve this outcome?

Human decision and rationale (or explicit source reference): Yes; #126 proposes this adapter as the scope of one PR and distinguishes "adapter wired" from "qualified on this checkpoint and path".

For a bug fix: link actual observed failure evidence.

Evidence: Not a bug fix: a new served backend (#126).

Why

system1-agents has no --model clef. Workers AI is not /v1/systemone: it is POST /client/v4/accounts/$ACCOUNT_ID/ai/run/@cf/cloudflare/clef (or clef-flash). Local SGLang does speak /v1/systemone, but screenshots use Clef's images field, not OneJev's media. Closes #126.

How

Start with s1a/decision_models/clef.py, then factory.py and the fronts, and tests/test_decision_models_clef.py.

  • --model clef → ClefModel.from_env(): CLEF_URL (local /v1/systemone) or CLOUDFLARE_ACCOUNT_ID + CLOUDFLARE_AUTH_TOKEN (Workers AI; CLOUDFLARE_API_TOKEN accepted as an alias). CLEF_MODEL=clef|clef-flash (default clef-flash). Optional CLEF_API_KEY / CLEF_TIMEOUT_S (default 30).
  • Body follows the official Workers AI schema: model, state as the observation (no image markers), questions as choice/noul, images as PNG/JPEG/WebP data URLs only when present (max 4). Workers AI REST envelopes ({success, result, errors}) are unwrapped; a local body with answers is used as-is.
  • No image → text path still runs. More than 4 images, an empty image, or a non-PNG/JPEG/WebP type → MODEL_CALL_FAILED. Transport errors / malformed answers / success: false fail closed, same as other served clients.
  • raw keeps served_by (including path: local or workers-ai), url, request_id, server_timing, optional cf_ray, and sent_images digests (never image bytes).
  • Registered in DECISION_MODEL_NAMES and on the tool, browser, rails, CLI decide/probe, and MCP decide fronts (Clef is text-capable; images are optional).
  • score questions and videos are unsupported on our interface and are not sent. The Workers AI Clef / Clef-flash input schema also has no videos field (that extension is documented on Clef-omni). This adapter does not remap CLEF_MODEL to a Hugging Face id if a local server wants Cloudflare/clef.

What

  • New env vars CLEF_URL, CLEF_MODEL, CLEF_API_KEY, CLEF_TIMEOUT_S, plus CLOUDFLARE_ACCOUNT_ID / CLOUDFLARE_AUTH_TOKEN in docs/configuration.md and .env.example.
  • Docs: docs/decision-models.md (backend row + optional smoke recipe), docs/capabilities.md (adapter wired vs not qualified; no Decision Index numbers copied as ours), docs/agents.md, docs/architecture.md.
  • NOTICE / THIRD_PARTY_LICENSES for Clef (Apache-2.0; weights not vendored).
  • CHANGELOG Unreleased entry.

Verification

  • uv run ruff format --check . && uv run ruff check . && uv run ty check: all clean
  • uv run pytest -q and scripts/smoke.sh: 1401 passed, 134 skipped, 267 subtests passed; smoke OK
  • CHANGELOG.md and the docs say what the code does now

Offline tests cover the text path (no images/media/videos fields), screenshot data URLs, the Workers AI REST envelope and cf-ray, a success: false envelope, more than 4 images, transport error (after retry), malformed answers, HTTP 500, one decision deadline across the permitted retry, from_env / build_model (local vs Workers AI, local URL wins, token alias), and front registration.

Demo / evidence

  • Video link, or exemption/blocker with follow-up: exempt for this PR — [Feat] Add Cloudflare Clef / Clef-flash as a System One decision backend #126 distinguishes "adapter wired" from "qualified"; acceptance is CI-complete with a stub server. No Cloudflare token or local Clef server was available on this box, so no live Workers AI or GPU run was performed and nothing was invented under docs/results/. Hardware / path qualification remains unmarked in the capability matrix until a pinned run lands.
  • Application/task → agent actions → independently checked result: not recorded (no live path).
  • System1-Agents / System1-Omni commits, checkpoint and worker/frontend provenance: Agents branch issue-126-clef; no System1-Omni involved (Workers AI or a local SGLang Clef server).

--model clef talks to Workers AI or a local /v1/systemone server
(CLEF_URL, or CLOUDFLARE_ACCOUNT_ID + CLOUDFLARE_AUTH_TOKEN;
CLEF_MODEL=clef|clef-flash, default clef-flash). Screenshots map to
Clef's images array (max 4); a text observation still runs. Contract
tests use a stub server; no live Cloudflare or GPU call in CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Add Cloudflare Clef / Clef-flash as a System One decision backend

1 participant