Skip to content

Agent Zero AI framework

Simplify vision sidecar execution

Alessandro5d4f49ad6161
diff --git a/tests/test_parallel_tool.py b/tests/test_parallel_tool.py
index 575f21f51..dc1a91199 100644
--- a/tests/test_parallel_tool.py
+++ b/tests/test_parallel_tool.py
@@ -160,42 +160,6 @@ def test_normalize_parallel_tool_calls_accepts_json_string_array() -> None:
assert calls[1].tool_args["message"] == "Research nuclear fusion news in Italian."
-def test_parallel_keeps_mixed_tools_and_batched_vision_paths() -> None:
- calls = parallel_tools.normalize_parallel_tool_calls(
- [
- {"tool_name": "search_a", "tool_args": {"query": "one"}},
- {"tool_name": "search_b", "tool_args": {"query": "two"}},
- {"tool_name": "browser_agent", "tool_args": {"message": "open page"}},
- {
- "tool_name": "vision_load",
- "tool_args": {
- "paths": ["/tmp/before.png", "/tmp/after.png"],
- "query": "compare",
- },
- },
- ]
- )
-
- assert [call.tool_name for call in calls] == [
- "search_a",
- "search_b",
- "browser_agent",
- "vision_load",
- ]
- assert calls[3].tool_args["paths"] == ["/tmp/before.png", "/tmp/after.png"]
-
-
-def test_parallel_allows_multiple_independent_vision_calls() -> None:
- calls = parallel_tools.normalize_parallel_tool_calls(
- [
- {"tool_name": "vision_load", "tool_args": {"paths": ["/tmp/a.png"]}},
- {"tool_name": "vision_load", "tool_args": {"paths": ["/tmp/b.png"]}},
- ]
- )
-
- assert [call.tool_name for call in calls] == ["vision_load", "vision_load"]
-
-
def test_subordinate_prompts_share_reusable_tree_contract() -> None:
call_prompt = (PROJECT_ROOT / "prompts/agent.system.tool.call_sub.md").read_text(
encoding="utf-8"
diff --git a/tests/test_vision_load_image_refs.py b/tests/test_vision_load_image_refs.py
index 619901aa0..61ba5bbf3 100644
--- a/tests/test_vision_load_image_refs.py
+++ b/tests/test_vision_load_image_refs.py
@@ -217,6 +217,8 @@ async def test_vision_sidecar_sends_multiple_images_once_and_keeps_history_text_
content = calls[0]["messages"][1].content
assert content[0] == {"type": "text", "text": "Compare the login errors."}
assert [item["type"] for item in content].count("image_url") == 2
+ assert "max_tokens" not in calls[0]
+ assert "explicit_caching" not in calls[0]
assert "fixes the red login error" in response.message
assert response.message != "dummy"
assert raw_messages == []
@@ -237,16 +239,31 @@ async def test_parallel_worker_consumes_parent_ephemeral_image(monkeypatch, tmp_
monkeypatch.setattr(vision_load_module.chat_media.files, "get_abs_path", fake_get_abs_path)
monkeypatch.setattr(vision_load_module.chat_media.files, "normalize_a0_path", fake_normalize_a0_path)
- monkeypatch.setattr(vision_load_module.VisionLoad, "_config_agent", lambda self: self.agent)
+ parent_id = "parent-vision"
+ parent_agent = SimpleNamespace(
+ context=SimpleNamespace(id=parent_id),
+ agent_name="Parent Agent",
+ )
+ parent_context = SimpleNamespace(agent0=parent_agent)
+ agent_stub = types.ModuleType("agent")
+ agent_stub.AgentContext = SimpleNamespace(
+ get=lambda context_id: parent_context if context_id == parent_id else None
+ )
+ monkeypatch.setitem(sys.modules, "agent", agent_stub)
+ config_owners = []
+
+ def get_chat_config(owner):
+ config_owners.append(owner)
+ return {"vision": True, "max_embeds": 10}
+
monkeypatch.setattr(
vision_load_module,
"get_chat_model_config",
- lambda _agent: {"vision": True, "max_embeds": 10},
+ get_chat_config,
)
monkeypatch.setattr(vision_load_module, "get_vision_model_config", lambda _agent: {})
monkeypatch.setattr(vision_load_module, "use_vision_sidecar", lambda _agent: False)
- parent_id = "parent-vision"
ref = vision_load_module.ephemeral_images.put_image_bytes(
context_id=parent_id,
mime="image/png",
@@ -271,6 +288,9 @@ async def test_parallel_worker_consumes_parent_ephemeral_image(monkeypatch, tmp_
await tool.execute(paths=[ref])
+ assert tool._config_owner is parent_agent
+ assert config_owners and all(owner is parent_agent for owner in config_owners)
+ assert tool._context_id() == parent_id
assert tool.loaded_paths == ["shot.png"]
assert vision_load_module.ephemeral_images.get_image(ref, context_id=parent_id) is None
stored_ref = tool.images_dict["shot.png"]
diff --git a/tools/vision_load.py b/tools/vision_load.py
index b29ff931f..6cba5d2c0 100644
--- a/tools/vision_load.py
+++ b/tools/vision_load.py
@@ -1,4 +1,3 @@
-import asyncio
import json
from mimetypes import guess_type
@@ -16,7 +15,6 @@ from plugins._model_config.helpers.model_config import (
)
TOKENS_ESTIMATE = 1500
-VISION_TIMEOUT_SECONDS = 300
VISION_SYSTEM_PROMPT = (
"You are a precise vision analyst. Answer only what was asked about the images. "
"Be concise and factual. Preserve exact visible text when asked to read it."
@@ -93,7 +91,8 @@ class VisionLoad(Tool):
if self._delegated and self.images_dict:
try:
capsule = await self._call_vision_model(
- list(self.images_dict.values()), self._query(query, kwargs)
+ list(self.images_dict.values()),
+ str(query or "").strip() or DEFAULT_VISION_QUERY,
)
message = (
f"Vision Model analyzed {len(self.images_dict)} image(s)"
@@ -163,12 +162,8 @@ class VisionLoad(Tool):
return 10
def _context_id(self) -> str:
- context = getattr(self.agent, "context", None)
- if not context:
- return ""
- get_data = getattr(context, "get_data", None)
- parent_id = get_data(PARALLEL_WORKER_PARENT_CONTEXT_KEY) if get_data else ""
- return str(parent_id or getattr(context, "id", "") or "").strip()
+ context = getattr(self._config_owner, "context", None)
+ return str(getattr(context, "id", "") or "").strip()
def _config_agent(self):
context = getattr(self.agent, "context", None)
@@ -189,16 +184,11 @@ class VisionLoad(Tool):
{"type": "image_url", "image_url": {"url": path}}
for path in image_paths
)
- response, _ = await asyncio.wait_for(
- model.unified_call(
- messages=[
- SystemMessage(content=VISION_SYSTEM_PROMPT),
- HumanMessage(content=content),
- ],
- explicit_caching=False,
- max_tokens=2000,
- ),
- timeout=VISION_TIMEOUT_SECONDS,
+ response, _ = await model.unified_call(
+ messages=[
+ SystemMessage(content=VISION_SYSTEM_PROMPT),
+ HumanMessage(content=content),
+ ],
)
if not str(response or "").strip():
raise RuntimeError("Vision Model returned an empty response.")
@@ -266,15 +256,6 @@ class VisionLoad(Tool):
return "vision_load error: `paths` must be an array of image paths."
return [str(path or "").strip() for path in paths]
- @staticmethod
- def _query(query: str, kwargs: dict) -> str:
- if str(query or "").strip():
- return str(query).strip()
- for key in ("prompt", "question", "instruction", "focus", "request"):
- if str(kwargs.get(key) or "").strip():
- return str(kwargs[key]).strip()
- return DEFAULT_VISION_QUERY
-
@staticmethod
def _is_data_image_url(value: str) -> bool:
normalized = str(value or "").strip().lower()
diff --git a/tools/vision_load.py.dox.md b/tools/vision_load.py.dox.md
index 2269eab56..82445f699 100644
--- a/tools/vision_load.py.dox.md
+++ b/tools/vision_load.py.dox.md
@@ -25,6 +25,7 @@
- Delegated history contains the text capsule only. Native history contains the tool result followed by one raw message holding all loaded image blocks.
- Direct parallel workers resolve ephemeral refs, model routing, and durable chat-media storage against their recorded parent context; independent vision jobs remain generic parallel jobs.
- `max_embeds` comes from the model that actually receives the images.
+- Vision Model calls use the selected model's Advanced `kwargs`; this tool does not impose a separate timeout or output-token limit.
- Update this file whenever tool arguments, output shape, `break_loop` behavior, intervention handling, prompt instructions, or side effects change.
- `VisionLoad` is a `Tool`.
- `VisionLoad` defines `execute(...)`.
@@ -33,7 +34,7 @@
## Key Concepts
-- Important called helpers/classes observed in the source: `build_vision_model`, `use_vision_sidecar`, `self._get_max_embeds`, `Response`, `self._context_id`, `chat_media.save_image_base64`, `chat_media.save_image_data_url`, `chat_media.materialize_image_ref`, `ephemeral_images.consume_image`, `images.to_data_url`, `self.agent.hist_add_tool_result`, `history.RawMessage`.
+- Important called helpers/classes observed in the source: `build_vision_model`, `use_vision_sidecar`, `self._get_max_embeds`, `Response`, `self._context_id`, `chat_media.save_image_base64`, `chat_media.save_image_data_url`, `chat_media.materialize_image_ref`, `ephemeral_images.consume_image`, `images.to_data_url`, `self.agent.hist_add_tool_result`, `history.RawMessage`, `model.unified_call`.
- Keep request/response, tool, or helper semantics documented here at the same time as source changes.
## Work Guidance