Vision

The adk-vision crate gives agents local-first perception: detection, segmentation, document reading, embedding, description, tracking and editing behind one set of contracts, with every region in source pixels, every weight file verified, and every image that leaves the machine passing the egress gate and recorded first — redacted, held or refused only when you opt in to that restriction. It implements spec 3.7.

Note: adk-vision is Experimental. This release holds phases A to C of spec 3.7: the contracts, the runtime, the egress boundary, the conformance suite, the local ONNX backends, the document readers (ocr, ocr-vl, nim), the cloud backends and a local describer (phase A); streams, video and tracking, visual wakes, measurement and the live camera surface (phase B); teams, visual memory and screen grounding (phase C). Phase D, spatial perception, is planned.

[dependencies]
adk-vision = { version = "3.0.0", features = ["fetch"] }

Concepts

ConceptTypeWhat it is
Source imageSourceImage, ImageRefPixels decoded once on the device, named by the sha256: digest of their encoded bytes; MediaStore keeps them as artifacts
Sent imageSentImageWhat an on-device backend sees: pixels and the transform chain from the source. Only VisionRuntime makes one
Released imageReleasedImageWhat a remote backend sees: the copy the gate cropped and, when the rules list classes, redacted; its bytes and its egress receipt. Only EgressGate makes one
Raw regionRawRegionA backend's answer, in the backend's own coordinate frame. Never leaves the call that produced it
RegionRegion, RegionSetAn answer in source pixels, with its backend, model, frame, transform chain and any escalation
ManifestModelManifestA model's files pinned by revision and SHA-256, its licence, runtime and input
Verified modelVerifiedModelA model whose every file matched its manifest under a licence the gate allowed

The Traits

TraitDoesReturns
DetectorFinds objects for closed-set classes or open-vocabulary conceptsBoxes and masks
SegmenterSegments for concept, point, box or mask promptsMasks and polygons
DocumentReaderReads a page: layout, text, tablesBlocks with regions, words, cells and reading order
EmbedderEmbeds images and texts into one EmbeddingSpaceVectors
DescriberAnswers in text, a schema-shaped value, and regions when askedDescription
TrackerAssociates detections across frames, pure CPURegions with anonymous TrackIds
VideoAnalyzerTracks, captions or answers over a clip or sampled frames (video); the video analyst indexes the captions (analyst)VideoAnalysis
EditorCrops, resizes, redacts, blurs, pixelates, annotatesA new image with Provenance::Derived

Each image-taking trait is generic over what its backend is handed. An on-device backend implements Detector (that is, Detector<SentImage>); a remote backend implements Detector<ReleasedImage>, and handing it a SentImage does not compile. The built-in DeterministicEditor and GreedyIouTracker need no model.

Coordinate Frames

Every backend descriptor names the frame it answers in:

CoordFrameProvidersMeaning
SentPixelsMeta sam-3.1; Claude, once the runtime has resized the image to Claude's limit; local backends that undo their own letterboxPixels of the image as sent
Normalized { scale, order }Gemini box_2d: scale: 1000, order: YxNumbers on a fixed scale, in the provider's axis order
ModelInput { width, height, letterbox }RF-DETR, SAM 2Pixels of the model's input tensor, with the sent image letterboxed into it

Between the source image and the sent image, the runtime records a TransformChain of Crop, Resize, Pad, Rotate and Redact steps. Mapping a raw region to source pixels runs the frame, then the chain in reverse, then clamps to the image:

use adk_vision::{
    AxisOrder, BackendId, CoordFrame, Digest, RawRegion, RegionNormalizer, Transform,
    TransformChain,
};

// A 3024x1964 screenshot, cropped to a field and its margin, sent to Gemini.
let chain = TransformChain::new(3024, 1964)
    .then(Transform::Crop { x: 1900, y: 1160, width: 220, height: 120 })
    .unwrap();
let gemini = CoordFrame::Normalized { scale: 1000, order: AxisOrder::Yx };
let normalizer = RegionNormalizer::new(Digest::of(b"screenshot"), chain, gemini, BackendId::new("gemini"));

// Gemini answers [ymin, xmin, ymax, xmax] on 0-1000 of the crop.
let raw = RawRegion::boxed(gemini.box_from_raw([167.0, 91.0, 833.0, 909.0]), "save", 0.9);
let region = normalizer.region(raw).unwrap().unwrap();
let b = region.shape.bbox().unwrap();
assert!((b.x0 - 1920.0).abs() < 1.0 && (b.y0 - 1180.0).abs() < 1.0);

The crate's tests hold Gemini, Claude, sam-3.1 and RF-DETR answers for twelve targets within 2 px of the truth after normalisation, and random transform chains within 0.5 px.

Screen Points

ScreenSpace turns screenshot pixels into the logical points a click uses. A screenshot of a 1512×982-point display at device pixel ratio 2 is 3024×1964 pixels:

use adk_vision::ScreenSpace;

let screen = ScreenSpace::new("built-in", [0.0, 0.0], 2.0);
assert_eq!(screen.to_points([2010.0, 1220.0]), [1005.0, 610.0]);

Screen Grounding builds on it: numbered marks on a screenshot's candidates, the chosen mark's click point in points, and screenshots fitted to a model's image limits.

The Wire Form

RegionSet — the image's digest and dimensions plus its regions — is published as a JSON Schema in adk-vision/schema/region-set.json. Shapes carry a kind tag, transforms an op tag, and fields are camelCase:

{
  "image": "sha256:…",
  "width": 3024,
  "height": 1964,
  "regions": [{
    "image": "sha256:…",
    "shape": { "kind": "box", "x0": 1920, "y0": 1180, "x1": 2100, "y1": 1260 },
    "label": "save",
    "score": 0.9,
    "origin": {
      "backend": "gemini",
      "frame": { "kind": "normalized", "scale": 1000, "order": "yx" },
      "chain": {
        "sourceWidth": 3024,
        "sourceHeight": 1964,
        "steps": [{ "op": "crop", "x": 1900, "y": 1160, "width": 220, "height": 120 }]
      }
    }
  }]
}

The Runtime

VisionRuntime routes each call:

StepWhat happens
RouteThe call's route, else the task's, else the first registered on-device backend; registration order decides, no backend is privileged
PrepareAn on-device backend gets a SentImage downscaled to its InputLimits (or a refusal naming the limit); a remote one gets a ReleasedImage from the egress gate
MeterThe budget hold opens before the image is prepared or released, so a call the budget cannot cover sends nothing and leaves no egress record; images (and pages, for reading) are committed as units, at the unit price for a per-unit backend and zero for a local one; a token-billed backend's TokenEstimate sizes its hold
CancelThe VisionCx cancellation token ends the call at once; a frozen kill switch refuses it before the backend runs
NormaliseEvery answer is mapped to source pixels
EscalateOn a trigger, the uncertain region's crop goes to the escalation backend, whose answer replaces the primary's with escalatedFrom; an escalation the egress gate refuses leaves the primary's answer, and a held one stops the call for approval
TriggerEscalatesSends
LowConfidence { threshold }Each region, block or description scored below the thresholdThe region's crop plus margin
NoResultA call that found nothingThe whole image: no region exists to crop
Disagreement { with, min_iou }Regions a second on-device backend does not confirm (detection and segmentation)Each region's crop plus margin

Each call returns its CallRecords — backend, locality, image and egress digests, units, cost, region count, duration — the fields of the vision.call audit record.

The Egress Gate

EgressGate::release is the only way an image reaches a remote backend:

  1. Destination. Under the on-device profile (on_device = true in [egress]) every host is refused; otherwise the adk-core EgressPolicy decides each of the backend's hosts.
  2. Minimise. The image is cropped to the request's crop and downscaled to the backend's limit.
  3. Redact. Each class the configuration's redact list names is found by its Redactor and filled with solid colour, because blur and pixelation of text can be reversed; then the caller's marked regions. A listed class with no redactor refuses the release. The list is empty by default.
  4. Decide. The first [[egress.rule]] matching the host or provider and the data class, else the default, says deny, ask or allow. allow is the default. ask holds the release until a person approves its exact egress digest; a different image is a different digest and is held again.
  5. Record. With a media store (EgressGate::with_media_store), the egress copy is stored as an artifact. The EgressReceipt goes to the EgressRecorder, and a vision.egress.released record to the call's audit trail, before the image is returned; a refusal is recorded too.
  6. Release.

.adk/vision.toml holds the rules. With no file, every release is allowed and nothing is redacted; each restriction is an opt-in, enforced once chosen. Redaction of a listed class always precedes the decision, and an unknown key is an error:

[egress]
default = "ask"
redact = ["faces", "personal_text"]

[[egress.rule]]
host = "generativelanguage.googleapis.com"
classes = ["document_crop"]
action = "allow"

[[egress.rule]]
provider = "openrouter"
action = "deny"

A rule names exactly one of host and provider. A provider is the id a model's responses carry in LlmResponse::provider — anthropic, gemini, openai, bedrock, nvidia, muse — and a backend names its providers in BackendDescriptor::providers, which LlmDescriber::remote fills from Llm::data_destinations. See Restricting What Leaves the Machine.

Model Manifests and Licences

{
  "id": "rf-detr-n-q4f16",
  "task": "detect",
  "source": {
    "kind": "huggingFace",
    "repo": "onnx-community/rfdetr_nano-ONNX",
    "revision": "eae21cee0687a91bcf9fa071605c48d7705d2d91"
  },
  "files": [{
    "path": "onnx/model_q4f16.onnx",
    "sha256": "sha256:42d8072bc00975405531e4e7f20dda40a6cb5ed67e345ecd764f92748463a996",
    "size": 18996625
  }],
  "licence": {
    "id": "Apache-2.0",
    "url": "https://huggingface.co/onnx-community/rfdetr_nano-ONNX",
    "class": "permissive"
  },
  "runtime": { "kind": "ort", "opset": 17 }
}

A revision is a 40-digit commit hash, never a branch. ManifestSet::builtin() holds the built-in entries, which arrive with each backend, pinned by the benchmark run that accepts the model; with_dir adds the user's own manifests, such as an RF-DETR fine-tune.

LicenceClassFetched and loaded when
permissiveAlways
useRestrictedA person's acceptance of that licence URL is recorded; adk-rust vision models accept <id> shows the licence first, and no agent tool records one
nonCommercial, copyleftThe user's LicencePolicy names the model; never in the built-in manifest

Fetching

ModelFetcher (feature fetch) downloads through hf-hub 0.5 into the shared Hugging Face cache layout:

VariableEffect
HF_HUB_CACHEThe cache directory
HF_HOMEThe cache is $HF_HOME/hub when HF_HUB_CACHE is unset; otherwise ~/.cache/huggingface/hub
HF_TOKENThe access token for gated repositories
HF_ENDPOINTA mirror instead of https://huggingface.co
HF_HUB_OFFLINE=1No socket is opened: a cached file is verified and returned, a missing one is an error

The licence gate runs before any request. Each file's size and SHA-256 are checked after download and before every load, and a mismatch is refused with both digests. A 401 or 403 from the hub is a gated repository and becomes LicenceAcceptanceRequired naming the repository page. Backends take a VerifiedModel, which only verification constructs.

use std::sync::Arc;
use adk_vision::{FetchConfig, InMemoryAcceptanceStore, ModelFetcher, ModelManifest};

# async fn demo(manifest: ModelManifest) -> adk_vision::Result<()> {
let fetcher = ModelFetcher::new(FetchConfig::from_env(), Arc::new(InMemoryAcceptanceStore::new()));
let model = fetcher.fetch(&manifest).await?;
let file = model.file("onnx/model_q4f16.onnx").unwrap();
println!("{} {}", file.path().display(), file.digest());
# Ok(())
# }

Writing a Backend

  1. Describe it: a BackendDescriptor with its id, Locality, CoordFrame, price and InputLimits.
  2. Implement the trait for SentImage if it runs on the device, or for ReleasedImage if it sends the image off the machine. Answer with RawRegions in your frame.
  3. Register it: VisionRuntimeBuilder::detector or remote_detector, and so on; a descriptor whose locality does not match is refused.
  4. Run the conformance suite with feature conformance:
mod my_detector {
    use std::sync::Arc;
    use adk_vision::conformance::DetectorTarget;

    adk_vision::detector_conformance_tests! {
        backend = DetectorTarget::Local(Arc::new(my_crate::MyDetector::new())),
    }
}
CaseChecks
CoordinatesRegions within the fixture's tolerance in source pixels, inside the image, with backend, frame and chain
UsageImages recorded as units; zero cost for a local backend, the unit price for a per-unit one
CancellationA cancelled call ends with Cancelled; a slow backend within one call
Kill switchA frozen control refuses before the backend runs and nothing is released
EgressA local backend leaves the egress recorder empty; every remote image is a recorded release
UnreleasedA remote backend without an egress gate is refused as Forbidden
OversizedRefused with the limit in the message, or downscaled with the resize recorded
ErrorsA rate limit maps to RateLimited with a retry hint

A VideoAnalyzer runs video_analyzer_conformance_tests! instead; see Video and Tracking.

EgressGate::stage runs the first three steps and stores the copy without releasing it, so an approval card can show the exact image; see Governed Vision Tools.