@@ -250,23 +250,29 @@ def run_agent(
250250 base_url : str | None = None ,
251251 top_k : int | None = None ,
252252 num_choices : int | None = None ,
253+ image_metadata : str | None = None ,
253254) -> AgentToolSelection :
254255 """
255256 Execute the agent for a user task and at least one image path.
256257
257258 - derive canonical original_formats (tiff / dicom / nifti / ...)
258- - build a compact image metadata summary
259+ - build a compact image metadata summary (or use pre-computed one)
259260 - pass both to the LLM as hidden context
260261 - store image_paths/original_formats in deps so retrieval tools can use them
261262 - optionally allow runtime model/base_url/top_k/num_choices overrides
263+
264+ Args:
265+ image_metadata: Optional pre-computed metadata string. If provided,
266+ avoids redundant metadata extraction.
262267 """
263268 if not image_paths :
264269 raise ValueError ("run_agent requires at least one image path" )
265270
266271 tool_logs : List [ToolRunLog ] = []
267272
268273 # ---- 1) Derive image-based metadata and format hints --------------------
269- meta_str = summarize_image_metadata (image_paths ) or ""
274+ # Use pre-computed metadata if available, otherwise compute it
275+ meta_str = image_metadata if image_metadata is not None else (summarize_image_metadata (image_paths ) or "" )
270276 fmt_str = detect_ext_token (image_paths ) or ""
271277 original_formats = [t .lower () for t in fmt_str .split ()] if fmt_str else []
272278
0 commit comments