Skip to content

Forward image tool results through the Genkit adapter - #2338

Merged
leehack merged 2 commits into
mainfrom
fix/genkit-tool-result-media
Nov 26, 2026
Merged

leehack merged 2 commits into
mainfrom
fix/genkit-tool-result-media

Conversation

@leehack

@leehack leehack commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Map Genkit MediaPart values in tool results to LlamaToolResultContent.content (ordered with text parts; result is null so output stays Genkit-history-only, as with text). Text-only results keep their joined form.
  • Pre-flight LlamaEngineCapabilities.toolResultMedia (image/audio), so an unsupported runtime/template/backend fails UNIMPLEMENTED before the next model turn. Thinking-budget/speculation guards and usage counts now include tool-result media.
  • Remote HTTP(S) images in tool results go through the application LlamaDartMediaResolver (same limits, cancellation, sanitized errors); without one they are rejected with a redacted INVALID_ARGUMENT. Audio, resource, data, video, PDF and other non-image parts fail UNIMPLEMENTED (remote audio and non-image remote media are never fetched); malformed image data URLs and remote images without a resolver stay INVALID_ARGUMENT.
  • New example genkit_llamadart_tool_media_example.dart, docs/skill/README/CONTRIBUTING updates, opt-in real-model test.
  • Closes Support media-bearing Genkit tool results after runtime qualification #1212 (core delivered by Return images from tools on native llama.cpp (#1008) #1462). genkit_llamadart is independently versioned: this adds only an ## Unreleased entry; no pubspec bump and no release prep (3.13.0 is left for a separate two-file prep PR).

Changelog

  • [packages/genkit_llamadart] Forward image MediaPart values in Genkit tool results to the next model turn on native llama.cpp vision models with a qualified template, and reject audio and unsupported runtimes with UNIMPLEMENTED.

Production-readiness scope

  • User-facing scope: Genkit tools can return images that the model reads on the next turn.
  • Supported platforms/paths: native llama.cpp with a loaded projector and a tool-result-media-qualified template (Qwen3-VL; Qwen3.5-0.8B with the Qwen3-VL template); local path, file://, data: and resolver-fetched HTTP(S) images.
  • Unsupported or intentionally unavailable paths: audio (no runtime reports it), video/resource/data parts, LiteRT-LM, Web, unqualified templates: UNIMPLEMENTED before the next model call (redacted); remote images without a resolver: INVALID_ARGUMENT.
  • Out of scope / follow-ups: None (Design multimodal tool-result content with preserved tool identity #1008 stays open for core's other families).

Completeness checklist

  • Declared scope is fully implemented.
  • Unsupported combinations fail loudly (see above).
  • Dartdoc/docs, README, example, skill and changelog updated.
  • Regression coverage: ordered mixed text/media, both roles, multiple calls, interrupt/resume, capability rejection, remote resolver success/failure/cancellation, redaction.
  • Validation coverage registry: N/A, adapter-only (no core public capability change).
  • Security/privacy: tests assert URLs/tokens never appear in errors; resolver errors drop causes.
  • Follow-ups: None.

PR type guidance

  • Feature PR: API behavior, docs, example, unsupported paths and happy/negative tests included.

Test Plan

From packages/genkit_llamadart (Flutter 3.47.1 SDK):

  • dart format --output=none --set-exit-if-changed .; dart analyze --fatal-infos; python3 .github/check_docs.py
  • dart test -x real-model: 504 pass, hosted llamadart 0.21.0 (lower bound) and checkout-core override
  • dart test -p chrome on converter/media/remote-media suites: 128 pass
  • Staged archive dart pub publish --dry-run: 0 warnings
  • Root python3 tool/ci/check_format.py
  • Real model (below)

Matrix Evidence

Matrix row Scope covered Platform / model / backend Result Evidence / notes
genkit-contracts package suites, docs, staging macOS arm64, Dart PASS see Test Plan; CI to confirm
genkit-native-cpu Genkit tool returns red/blue PNG; model names the color on the next turn macOS arm64 CPU, Qwen3-VL-2B-Instruct Q4_K_M (sha256 089d75c5…ca6c2ae, rev 52d6c8ff…eb503) + F16 mmproj (c3d5afbe…6aea5), 2 threads PASS (red, blue) real_model_tool_result_media_test.dart; also passes on Qwen3.5-0.8B + Qwen3-VL template; hosted 0.21.0 and checkout core
tool-result-image-smoke core scenario N/A N/A core is unchanged; the adapter test reuses its env vars instead (the scenario runs a core test)
Example genkit_llamadart_tool_media_example.dart with the Qwen3-VL pair and a red PNG same PASS printed "A solid red square image."

Mutation checks (10 mutants: result non-null, reversed order, no remote rejection, no image/audio capability check, no resolver collection, no nested replacement, dropped text, top-level-only media for guards/usage) are all killed; the new tests fail against the base lib/.

Review Notes

  • Independent review status: pending, exact-head auditor required (high-risk).
  • CI status / head SHA: pending / 2ac130c

High-risk regression review

  • Classification: high-risk (backendRuntime, regressionPolicy, structuredOutput)
  • Implementation task: this PR (worker)
  • Independent blocking QA task: pending
  • Exact head / current base: 2ac130c / 4809d67
  • Production-branch deletion, bypass, or miswire proof: reverting the four lib/ files fails 10 new tests; mutants above
  • Affected-family real-model/artifact evidence: Qwen3-VL-2B-Instruct Q4_K_M + F16 projector, native llama.cpp CPU (see matrix)
  • Explicit unavailable-family or other N/A evidence: audio tool results: no runtime reports them; LiteRT-LM/Web: unsupported by core
  • Known PR-caused P1 regressions: 0 known
  • Unresolved review threads: 0

Delta (audit B1 fix, 2ac130c): non-image tool-result media now fails UNIMPLEMENTED regardless of resolver config; the resolver queues only image/* tool-result media. Rejected-case tests assert StatusCode; they fail against 12c5334 (8 failures) and 4 delta mutants are killed. Package dart test -x real-model 508 pass, Chrome suites 174 pass, analyze/format/check_docs clean. Docs note that tool-returned local paths are read as given.

@leehack
leehack marked this pull request as ready for review November 26, 2026 18:33
@leehack
leehack merged commit de12abb into main Nov 26, 2026
46 checks passed
@leehack
leehack deleted the fix/genkit-tool-result-media branch November 26, 2026 18:33
@github-actions

Copy link
Copy Markdown
Contributor

Chat app preview removed for leehack/llamadart-chat-pr-2338.

leehack added a commit that referenced this pull request Nov 27, 2026
## Summary

- Supersedes #2345 after the prerequisite in #2344 merged into `main`.
- Prepare genkit_llamadart 3.13.0 with `>=0.21.0 <0.23.0`.
- Collect the package release notes for the image tool-result support
merged in #2338.

## Changelog

- [packages/genkit_llamadart] Support llamadart 0.22.x alongside 0.21.x.
- [packages/genkit_llamadart] Forward image tool results to the next
model turn on qualified native llama.cpp vision templates.

## Production-readiness scope

- User-facing scope — Package dependency resolution on the 0.21.x and
0.22.x core series. The release includes the image tool-result support
from #2338.
- Supported paths — Qualified native llama.cpp vision templates for
image tool results. Dependency resolution validated against hosted core
0.21.0 and 0.22.0.
- Unsupported paths — Audio tool results and unsupported runtimes return
`UNIMPLEMENTED`.
- Follow-up — Independent audit and the owner’s release approval under
#2337. The feature is tracked in #1212.

## Completeness checklist

- [x] Two-file prep scope verified against the prerequisite.
- [x] Package changelog records the compatibility and image tool-result
changes.
- [x] Hosted compatibility exercised at each core version. Runtime
regressions and public capability evidence were covered by #2338.
- [x] Checked the diff for sensitive output or data handling. N/A for
new API, examples, runtime code, and capability registry entries.

## PR type guidance

- Independent Genkit release prep. The package manifest and changelog
are the only changed files.

## Test Plan

- [x] `dart run tool/prepare_workspace.dart` on the clean worktree
- [x] Package `dart analyze --fatal-infos` and `dart test -x real-model`
with hosted llamadart 0.21.0 and 0.22.0, using the repository fixture
layout
- [x] Package docs and checker tests
- [x] Root release-docs verifier in normal and `--release-prep` modes
- [x] Root Genkit floor, release-routing and staging tests
- [x] Standalone `dart pub publish --dry-run` with hosted llamadart
0.22.0
- N/A for full root VM, Chrome, coverage and new model qualification.
The prep changes release metadata and dependency constraints. See #2338
for the feature’s runtime verification.

## Matrix Evidence

| Matrix row | Scope covered | Platform / model / backend | Result |
Evidence / notes |
| --- | --- | --- | --- | --- |
| genkit-contracts | Hosted 0.21.0 and 0.22.0 dependencies | macOS /
model-free | Pass | 508 tests per version, fatal-info analysis, exact
hosted lockfile and package config on each version |
| genkit-release | Standalone publish dry-run, release docs, routing and
staging | macOS / model-free | Pass | 0 publish dry-run warnings, two
release-doc verifier modes and 13 root tooling tests |
| genkit-native-cpu | Image tool-result runtime | N/A for release prep |
N/A | Feature evidence is recorded in #2338 |

## Review Notes

- Independent review — Pending at the draft head.
- CI status / head SHA — Head `55d36534e14b0e586dee2f1045e85e0bc1622be5`
targets `main`. The cherry-pick has the same Git tree as validated head
`207ef23cf1ac90e7be812121afb311bd11d71c4d`. The local validation above
applies to those identical files. Hosted checks and the independent
audit are pending at the new head.

## High-risk regression review

- Classification — high-risk, artifactConsumer
- Implementation task — Genkit 3.13.0 release prep under #2337
- Independent blocking QA task — Pending coordinator handoff
- Exact head / current base — `55d36534e14b0e586dee2f1045e85e0bc1622be5`
/ `90c6ed0b3433cf4b0ffaa87fe1015b03b6907739`
- Production-branch deletion, bypass, or miswire proof — Pending
independent QA. The prerequisite demonstrates the floor checks reject
incorrect and malformed constraints.
- Affected-family real-model/artifact evidence — Hosted core 0.21.0 and
0.22.0 used for the package contract suite. The source feature’s
qualified template evidence is in #2338.
- Explicit unavailable-family or other N/A evidence — The release prep
only adjusts package metadata and the core dependency range.
- Known PR-caused P1 regressions — 0 found in local validation.
Independent audit pending.
- Unresolved review threads — Pending hosted verification.
@leehack leehack mentioned this pull request Nov 27, 2026
8 of 11 tasks
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.

Support media-bearing Genkit tool results after runtime qualification

1 participant