Module media

Module media 

Source
Expand description

Tool media returns — the ADK pattern where a function response carries images or other media to the model alongside its JSON payload, so vision tools (screenshots, chart renderers, document croppers) feed the model something it can actually look at.

The mechanism is a convention, so it works with every existing tool shape unchanged: a tool embeds media under the reserved "_media" key of its JSON result (via attach), and the text-agent loop lifts it out of the function response and delivers it to the model as inline_data parts in the same turn. Tools that never touch _media behave exactly as before.

T::simple("chart", "Render a chart", |args| async move {
    let png: Vec<u8> = render(&args)?;
    let mut result = json!({"rendered": true});
    media::attach(&mut result, "image/png", &png);
    Ok(result)
})

Structs§

MediaAttachment
One media attachment lifted from a tool result.

Constants§

MEDIA_KEY
Reserved result key holding media attachments.

Functions§

attach
Attach raw media bytes to a tool result. Repeated calls accumulate.
extract
Remove and return any media attachments from a tool result — called by the agent loop so the model receives media as parts, not as base64 JSON noise inside the function response.