docs/VISION_AGENT.md 在 GitHub 查看源文件

Controlled Agent image evidence / 受控视觉证据

Discover inspect_image_samples with tool_search, then pass only a dataset identity and one to four distinct file identities:

{"dataset_id":"dataset-id","file_ids":["file-a","file-b"]}

The read uses the same dataset membership, deleted-file visibility and asset grant checks as native downloads. Both query and download grants are required for protected assets. The server supplies the actor; paths, URLs, extra fields and duplicate IDs are rejected. No original object or annotation is modified. Normal read-usage and invocation audits remain.

工具只接收数据集及文件 ID。文件必须属于所选数据集且仍可见;受保护资产同时检查查询与下载 授权。工具不接受路径、URL、调用者身份或其它字段,也不修改原图及标注。

Payload and persistence

  • Source reads stop at 16 MiB plus one detection byte; headers reject more than 16,777,216 pixels, Pillow decompression bombs and animated/multipage images before full decoding.
  • The existing transcription sanitizer applies EXIF orientation, composites transparency on white and strips EXIF, GPS, ICC and textual metadata. Corrected source dimensions are retained.
  • RGB JPEG thumbnails preserve aspect ratio, never enlarge, and have a maximum edge of 512 pixels. Quality is fixed at 80; further halving bounds each encoded image to 64 KiB.
  • Each typed evidence record retains its file AssetRef, source SHA-256, corrected dimensions, thumbnail dimensions, media type, byte count, thumbnail SHA-256 or a safe per-image error. Corruption fails that image; authorization or membership failure rejects the batch.
  • FunctionResult.images and ToolOutcome.images are ephemeral. Base64 uses SecretStr and is excluded from serialization and reprs. Transcripts, SSE, invocation outcomes, traces and checkpoints store metadata and references, never image bytes or private object paths.

Before each model attempt (including fallbacks), the latest inspection in the active user turn is resolved again through current grants. Its complete evidence fingerprint must still match the stored result. A changed, deleted or newly denied source supplies no pixels. Only that latest batch is attached; compare up to four images in one inspection. A new user turn must inspect again. Durable read replays also recheck query and download grants.

每次模型尝试前重新授权、读取并比对来源指纹。缩略图只在内存中存在。当前用户轮次只挂载最后 一次检查的图片;后续用户消息需要重新调用工具。损坏图片返回逐图错误,授权失败拒绝整个批次。

Providers and budget

ChatMessage.images is an optional tuple of frozen ImageBlock values, omitted when empty. Text-only JSON remains unchanged. Only user messages carry images; a ModelRequest permits at most four images across all messages. Vendor adapters send OpenAI/Ollama-compatible image_url data URIs (detail=low); the installed Anthropic adapter converts those into native image / base64 sources. Each image has an adjacent text block naming its exact AssetRef. Existing prompt caching and retry policy remain in force.

The volatile vision context segment reserves 1024 + ceil(width/32) * ceil(height/32) * 32 input units per thumbnail (up to 9,216). Metadata and evidence text retain ordinary UTF-8 byte accounting. This conservative estimate enters the existing persistent reservation before a provider call; reported provider usage then reconciles the trace. Missing usage retains the reservation under the existing policy. The offline demo keeps its existing quarter-scale accounting. This estimate targets bounded thumbnails; arbitrary model-specific tokenization remains the provider's responsibility.

ScriptedChatModel and FakeProvider retain typed image blocks offline. Asking the demo 视觉检查, 看看图片 discovers the tool, searches up to four images, and reports actual thumbnail luminance and 32-square grayscale differences. These disclosed deterministic checks provide initial dark/bright/near-duplicate signals; they do not establish semantic annotation errors. Real vision-capable models can assess blur, exposure and annotation consistency from pixels. Thumbnail downsampling can hide fine detail, so conclusions remain sample evidence for review.

Verification and handoff

The focused tests are tests/agent/test_vision_evidence.py and tests/runtime/test_vision_chat.py. They generate every image locally and block external networking. SDK request bodies are captured with httpx.MockTransport, including the Ollama-compatible endpoint; no model service or account is needed.

Track handoff: the requested fast gates passed, with 72 tests across the two vision files, tests/runtime/test_prompt_caching.py and tests/versioning/test_vector_checksums.py.

Gate Result
Scoped Ruff lint and format Passed; 303 Python files formatted
Scoped Pyright 0 errors, 0 warnings
scripts/check_size.py Passed; agent 1400, runtime 1409, transcription 1500 lines
scripts/check_boundaries.py Storage row boundaries passed
python -m scripts.check_schema Frozen schema and storage ratchets passed
scripts/check_public_worktree.py No findings
lint-imports 5 contracts kept, 0 broken
Focused pytest command above 72 passed

No dependencies, storage implementation, settings, memory, frontend or reserved release documents changed. The track ends with one local commit; no push or deployment is performed. Full-wave integration owns the complete make check, public changelog and frontend reconciliation. Those broader gates and live model quality are outside this offline proof.