Skip to content

Official Codebase of 3DCodeVerse

Python

agents: images reach the session -- the reference photo, and the sheet the judge scored

gaoypengc7a0c6a9ccb6
diff --git a/harness/codeverse/agents/api_agent.py b/harness/codeverse/agents/api_agent.py
index d759e86f..35d87c5e 100644
--- a/harness/codeverse/agents/api_agent.py
+++ b/harness/codeverse/agents/api_agent.py
@@ -130,7 +130,12 @@ class _Loop:
self.last_build_turn = -1
self.nudged = False
self.errors: list[str] = []
- self.messages: list[ChatMessage] = [ChatMessage.user(job.prompt)]
+ # the images ride on the first message only: reference photos, and for a refine
+ # session the contact sheet the judge scored. Until 2026-08-26 no image reached an
+ # agent session at all — GenerationTask.images fed the single-shot path only, so a
+ # `--image` reference was seen by the planner and the judge and never by the code
+ # writer, which had to infer it back from compare_reference's IoU number.
+ self.messages: list[ChatMessage] = [ChatMessage.user(job.prompt, images=job.images or None)]
self.system = self._system_prompt()
self.max_usd = job.api.max_usd
self.t_deadline = time.monotonic() + job.timeout_s
diff --git a/harness/codeverse/contracts/agent.py b/harness/codeverse/contracts/agent.py
index 00fe694d..979e0ca5 100644
--- a/harness/codeverse/contracts/agent.py
+++ b/harness/codeverse/contracts/agent.py
@@ -6,6 +6,7 @@ from typing import Any
from pydantic import BaseModel, Field, model_validator
+from codeverse.contracts.chat import ImagePart
from codeverse.contracts.common import Usage
@@ -66,6 +67,11 @@ class AgentJob(BaseModel):
"and the language entry file stay allowed). Refine tasks set this so a session fixing one "
"part cannot rewrite its neighbours.",
)
+ images: list[ImagePart] = Field(
+ default_factory=list,
+ description="inline images for the FIRST user message (reference photos; the contact sheet the "
+ "judge scored). Backends without an image channel ignore them; the prompt names the files too.",
+ )
always_writable: list[str] = Field(
default_factory=list,
description="files exempt from edit_only (the entry file: adding a part means importing it there)",
diff --git a/harness/codeverse/tracks/generation.py b/harness/codeverse/tracks/generation.py
index c0f63ead..fb4d2883 100644
--- a/harness/codeverse/tracks/generation.py
+++ b/harness/codeverse/tracks/generation.py
@@ -430,6 +430,7 @@ def run_agent_task(
extra=extra,
edit_only=task.edit_only,
always_writable=_always_writable(language),
+ images=list(task.images),
**({"max_turns": turns_cap} if turns_cap > 0 else {}),
)
acc = _SessionAcc(task=task, budget=budget)
diff --git a/harness/codeverse/tracks/prompting.py b/harness/codeverse/tracks/prompting.py
index be673f8e..89150e29 100644
--- a/harness/codeverse/tracks/prompting.py
+++ b/harness/codeverse/tracks/prompting.py
@@ -39,12 +39,16 @@ def parts_table_for(parts: Sequence[Any]) -> str:
"""``parts_table`` for an explicit part subset (one scoped session's parts)."""
if not parts:
return "(no parts)"
- rows = ["| part | role | bbox centre (x,y,z) m | extents (x,y,z) m | attach_to | inst | material |",
- "|---|---|---|---|---|---|---|"]
+ rows = [
+ "| part | role | bbox centre (x,y,z) m | extents (x,y,z) m | attach_to | inst | material |",
+ "|---|---|---|---|---|---|---|",
+ ]
for p in parts:
c = ", ".join(f"{v:.3f}" for v in p.bbox.center)
e = ", ".join(f"{v:.3f}" for v in p.bbox.extents)
- rows.append(f"| {p.name} | {p.role} | ({c}) | ({e}) | {p.attach_to or '-'} | {p.instances} | {p.material or '-'} |")
+ rows.append(
+ f"| {p.name} | {p.role} | ({c}) | ({e}) | {p.attach_to or '-'} | {p.instances} | {p.material or '-'} |"
+ )
return "\n".join(rows)
@@ -71,7 +75,9 @@ def part_details_for(parts: Sequence[Any]) -> str:
ce = ", ".join(f"{v:.3f}" for v in c.bbox.extents)
inst = f" ×{c.instances}" if getattr(c, "instances", 1) > 1 else ""
mat = f" [{c.material}]" if getattr(c, "material", "") else ""
- out.append(f" - sub-part **{c.name}**{inst}{mat} — centre ({cc}) extents ({ce}) m: {c.description}")
+ out.append(
+ f" - sub-part **{c.name}**{inst}{mat} — centre ({cc}) extents ({ce}) m: {c.description}"
+ )
return "\n".join(out)
@@ -79,12 +85,16 @@ def joints_table(plan: Plan) -> str:
joints = getattr(plan, "joints", None)
if not joints:
return "(no joints)"
- rows = ["| joint | type | parent | child | axis | pivot (world, m) | lower | upper | rest | motion |",
- "|---|---|---|---|---|---|---|---|---|---|"]
+ rows = [
+ "| joint | type | parent | child | axis | pivot (world, m) | lower | upper | rest | motion |",
+ "|---|---|---|---|---|---|---|---|---|---|",
+ ]
for j in joints:
ax = ", ".join(f"{v:.3f}" for v in j.axis)
pv = ", ".join(f"{v:.3f}" for v in j.pivot)
- rows.append(f"| {j.name} | {j.type} | {j.parent} | {j.child} | ({ax}) | ({pv}) | {j.lower:.3f} | {j.upper:.3f} | {j.rest:.3f} | {j.motion} |")
+ rows.append(
+ f"| {j.name} | {j.type} | {j.parent} | {j.child} | ({ax}) | ({pv}) | {j.lower:.3f} | {j.upper:.3f} | {j.rest:.3f} | {j.motion} |"
+ )
return "\n".join(rows)
@@ -101,7 +111,9 @@ def bbox_line(bbox: Any) -> str:
return f"centre ({c}) m, extents ({e}) m"
-def glb_to_plan_frame(v: Sequence[float], language: Language, *, extents: bool = False) -> tuple[float, float, float]:
+def glb_to_plan_frame(
+ v: Sequence[float], language: Language, *, extents: bool = False
+) -> tuple[float, float, float]:
"""Map a GLB-frame (Y-up, +Z front) vector into the language's authoring frame.
Blender/CadQuery/URDF plans are Z-up with -Y front: glb (x, y, z) → (x, -z, y)."""
x, y, z = float(v[0]), float(v[1]), float(v[2])
@@ -114,7 +126,9 @@ def constraints_text(spec: Any) -> str:
c = spec.constraints
lines = []
if c.dimensions_m:
- lines.append("Dimensions (m): " + ", ".join(f"{k}={v:.3f}" for k, v in c.dimensions_m.items()))
+ lines.append(
+ "Dimensions (m): " + ", ".join(f"{k}={v:.3f}" for k, v in c.dimensions_m.items())
+ )
if c.max_triangles:
lines.append(f"Max triangles: {c.max_triangles}")
if c.style:
@@ -151,7 +165,9 @@ def cookbook_sections(ctx: RunContext, names: Sequence[str], *, max_chars: int =
out.append(sec.body.rstrip())
text = "\n\n".join(out)
if len(text) > max_chars:
- text = text[:max_chars].rstrip() + "\n\n…[chapters clipped — call read_cookbook for the rest]"
+ text = (
+ text[:max_chars].rstrip() + "\n\n…[chapters clipped — call read_cookbook for the rest]"
+ )
return text
@@ -212,14 +228,16 @@ def scope_context(ctx: RunContext, scope: PartScope, **extra: Any) -> dict[str,
"""Template context for ONE scoped part session: only its parts, plus the exact
numbers of the neighbours it must weld to but may not write."""
d = base_prompt_context(ctx, **extra)
- d.update({
- "scope_label": scope.label,
- "scope_names": ", ".join(scope.names),
- "parts_table": parts_table_for(scope.parts),
- "part_details": part_details_for(scope.parts),
- "interfaces": interfaces_text(ctx.plan, scope),
- "n_scope_parts": len(scope.parts),
- })
+ d.update(
+ {
+ "scope_label": scope.label,
+ "scope_names": ", ".join(scope.names),
+ "parts_table": parts_table_for(scope.parts),
+ "part_details": part_details_for(scope.parts),
+ "interfaces": interfaces_text(ctx.plan, scope),
+ "n_scope_parts": len(scope.parts),
+ }
+ )
d.update(extra)
return d
@@ -229,26 +247,54 @@ def reference_images(ctx: RunContext, limit: int = 3) -> list[ImagePart]:
out: list[ImagePart] = []
for r in list(ctx.spec.references)[:limit]:
if Path(r.path).is_file():
- out.append(ImagePart(path=r.path, label=f"reference ({r.role}){': ' + r.note if r.note else ''}"))
+ out.append(
+ ImagePart(
+ path=r.path, label=f"reference ({r.role}){': ' + r.note if r.note else ''}"
+ )
+ )
return out
+def judged_sheet(last: Any) -> list[ImagePart]:
+ """The contact sheet the judge scored last round, as ONE inline image for the refine session.
+
+ "What the judge saw" reached the refine agent as a paragraph of text; the picture it
+ was written about did not. A session told "the horn intersects the case" then had to
+ re-render to find out which view showed it. One image is cheap next to a session of
+ 30 tool turns, and it is the same file the score came from, so the agent and the judge
+ are finally looking at the same thing.
+ """
+ sheet = getattr(getattr(last, "renders", None), "contact_sheet", None)
+ if not sheet or not Path(sheet).is_file():
+ return []
+ return [
+ ImagePart(
+ path=str(sheet),
+ label=f"the contact sheet the judge scored (round {getattr(last, 'index', '?')})",
+ )
+ ]
+
+
def reference_note(ctx: RunContext) -> str:
"""Prompt paragraph telling the generator how to use the reference images (empty when none)."""
refs = [r for r in ctx.spec.references if Path(r.path).is_file()]
if not refs:
return ""
- lines = [f"REFERENCE IMAGES ({len(refs)}): match their silhouette, proportions and visible details — they "
- "outrank the text when the two disagree. A harness measures the front-view outline IoU against the "
- "target reference; aim for IoU ≥ 0.6."]
+ lines = [
+ f"REFERENCE IMAGES ({len(refs)}): match their silhouette, proportions and visible details — they "
+ "outrank the text when the two disagree. A harness measures the front-view outline IoU against the "
+ "target reference; aim for IoU ≥ 0.6."
+ ]
for i, r in enumerate(refs, 1):
lines.append(f"- reference {i} ({r.role}): `{r.path}`" + (f" — {r.note}" if r.note else ""))
if ctx.single_shot:
lines.append("The images are attached to this message.")
else:
tgt = next((r.path for r in refs if r.role == "target"), refs[0].path)
- lines.append(f"Use the `compare_silhouette` tool (render_png=<your front render>, reference_png=`{tgt}`) "
- "after building to check the outline, and `render_views` to look at your model.")
+ lines.append(
+ f"Use the `compare_silhouette` tool (render_png=<your front render>, reference_png=`{tgt}`) "
+ "after building to check the outline, and `render_views` to look at your model."
+ )
return "\n".join(lines)
@@ -277,10 +323,16 @@ def expected_files(ctx: RunContext) -> list[str]:
def skeleton_files(ctx: RunContext, max_chars: int = MAX_SKELETON_CHARS) -> dict[str, str]:
"""Current src/ files (the skeleton), trimmed, for single-shot prompts."""
- return current_files(ctx, [str(p.relative_to(ctx.ws.root)) for p in sorted(ctx.ws.src.rglob("*")) if p.is_file()], max_chars)
+ return current_files(
+ ctx,
+ [str(p.relative_to(ctx.ws.root)) for p in sorted(ctx.ws.src.rglob("*")) if p.is_file()],
+ max_chars,
+ )
-def current_files(ctx: RunContext, rels: Sequence[str], max_chars: int = MAX_SKELETON_CHARS) -> dict[str, str]:
+def current_files(
+ ctx: RunContext, rels: Sequence[str], max_chars: int = MAX_SKELETON_CHARS
+) -> dict[str, str]:
out: dict[str, str] = {}
total = 0
for rel in rels:
@@ -302,34 +354,49 @@ def judge_digest(last: RoundRecord, max_issues: int = 8) -> str:
j = last.judgment
if j is None:
return "(no judgment for the previous round)"
- lines = [f"Previous score {j.overall:.2f} ({'passed' if j.passed else 'not passed'}). {j.summary}".strip()]
+ lines = [
+ f"Previous score {j.overall:.2f} ({'passed' if j.passed else 'not passed'}). {j.summary}".strip()
+ ]
for k, v in sorted(j.scores.items(), key=lambda kv: kv[1])[:6]:
lines.append(f"- {k}: {v:.2f}")
for i in j.issues[:max_issues]:
- lines.append(f"- [{i.severity}/{i.kind}] {i.target}: {i.detail}" + (f" (seen in {i.evidence})" if i.evidence else ""))
+ lines.append(
+ f"- [{i.severity}/{i.kind}] {i.target}: {i.detail}"
+ + (f" (seen in {i.evidence})" if i.evidence else "")
+ )
return "\n".join(lines)
-def measurement_vs_plan(last: RoundRecord, plan: Plan | None, language: Language = Language.THREEJS) -> str:
+def measurement_vs_plan(
+ last: RoundRecord, plan: Plan | None, language: Language = Language.THREEJS
+) -> str:
"""Exact numbers (in the plan's frame): measured overall/part bboxes vs planned ones."""
m = last.measurement
if m is None or plan is None or not hasattr(plan, "overall_bbox"):
return ""
pe = plan.overall_bbox.extents
me = glb_to_plan_frame(m.extents, language, extents=True)
- lines = [f"Measured overall extents {me[0]:.3f}×{me[1]:.3f}×{me[2]:.3f} m vs plan "
- f"{pe[0]:.3f}×{pe[1]:.3f}×{pe[2]:.3f} m; ground gap {m.ground_gap_m:+.3f} m; footprint offset {m.footprint_offset_m:.3f} m; "
- f"{m.tri_count} tris, {m.n_meshes} meshes, {m.n_islands} islands."]
+ lines = [
+ f"Measured overall extents {me[0]:.3f}×{me[1]:.3f}×{me[2]:.3f} m vs plan "
+ f"{pe[0]:.3f}×{pe[1]:.3f}×{pe[2]:.3f} m; ground gap {m.ground_gap_m:+.3f} m; footprint offset {m.footprint_offset_m:.3f} m; "
+ f"{m.tri_count} tris, {m.n_meshes} meshes, {m.n_islands} islands."
+ ]
planned = {to_snake(p.name): p for p in getattr(plan, "parts", [])}
for pm in m.parts[:24]:
p = planned.get(to_snake(pm.name))
if p is None:
continue
- ext = glb_to_plan_frame([b - a for a, b in zip(pm.bbox_min, pm.bbox_max, strict=True)], language, extents=True)
- cen = glb_to_plan_frame([(a + b) / 2 for a, b in zip(pm.bbox_min, pm.bbox_max, strict=True)], language)
- lines.append(f"- {p.name}: measured centre ({cen[0]:.3f}, {cen[1]:.3f}, {cen[2]:.3f}) extents ({ext[0]:.3f}, {ext[1]:.3f}, {ext[2]:.3f})"
- f" | plan centre ({p.bbox.center[0]:.3f}, {p.bbox.center[1]:.3f}, {p.bbox.center[2]:.3f}) extents "
- f"({p.bbox.extents[0]:.3f}, {p.bbox.extents[1]:.3f}, {p.bbox.extents[2]:.3f})")
+ ext = glb_to_plan_frame(
+ [b - a for a, b in zip(pm.bbox_min, pm.bbox_max, strict=True)], language, extents=True
+ )
+ cen = glb_to_plan_frame(
+ [(a + b) / 2 for a, b in zip(pm.bbox_min, pm.bbox_max, strict=True)], language
+ )
+ lines.append(
+ f"- {p.name}: measured centre ({cen[0]:.3f}, {cen[1]:.3f}, {cen[2]:.3f}) extents ({ext[0]:.3f}, {ext[1]:.3f}, {ext[2]:.3f})"
+ f" | plan centre ({p.bbox.center[0]:.3f}, {p.bbox.center[1]:.3f}, {p.bbox.center[2]:.3f}) extents "
+ f"({p.bbox.extents[0]:.3f}, {p.bbox.extents[1]:.3f}, {p.bbox.extents[2]:.3f})"
+ )
gate_lines = [f"- {f.as_line(with_gate=True)}" for g in last.gates for f in g.errors][:12]
return "\n".join(lines + gate_lines)
@@ -359,7 +426,11 @@ def file_for_target_factory(ctx: RunContext):
try:
out = custom(part_names[key])
if out:
- return [str(out)] if isinstance(out, (str, Path)) else [str(p) for p in out]
+ return (
+ [str(out)]
+ if isinstance(out, (str, Path))
+ else [str(p) for p in out]
+ )
except Exception as e: # noqa: BLE001
log.warning("runtime.file_for_part failed for %s: %s", target, e)
return [f"src/parts/{key}.js"] if lang is Language.THREEJS else [entry]
@@ -369,11 +440,16 @@ def file_for_target_factory(ctx: RunContext):
try:
out = whole(target)
if out:
- return [str(out)] if isinstance(out, (str, Path)) else [str(p) for p in out]
+ return (
+ [str(out)]
+ if isinstance(out, (str, Path))
+ else [str(p) for p in out]
+ )
except Exception as e: # noqa: BLE001
log.warning("runtime.file_for_target failed for %s: %s", target, e)
return [entry]
return []
+
return _per_part
if lang is Language.SCENE_THREEJS:
@@ -392,5 +468,6 @@ def file_for_target_factory(ctx: RunContext):
if key in ("env", "environment", "lighting", "sky", "fog", "ground", "water", "light"):
return ["src/env.js"]
return []
+
return _scene
return None
diff --git a/harness/codeverse/tracks/static_object.py b/harness/codeverse/tracks/static_object.py
index 6d38b1ba..c9b2805c 100644
--- a/harness/codeverse/tracks/static_object.py
+++ b/harness/codeverse/tracks/static_object.py
@@ -38,6 +38,7 @@ from codeverse.tracks.prompting import (
file_for_target_factory,
glb_to_plan_frame,
judge_digest,
+ judged_sheet,
measurement_vs_plan,
reference_images,
scope_context,
@@ -348,7 +349,7 @@ class StaticObjectTrack(BaseTrack):
kind="refine",
temperature=0.4,
thinking="medium",
- images=reference_images(ctx),
+ images=reference_images(ctx) + judged_sheet(last),
edit_only=scoped,
)
diff --git a/harness/tests/agents/test_api_agent.py b/harness/tests/agents/test_api_agent.py
index 250ab710..350c58d0 100644
--- a/harness/tests/agents/test_api_agent.py
+++ b/harness/tests/agents/test_api_agent.py
@@ -208,3 +208,22 @@ def test_live_api_agent_gemini(tmp_ws):
assert res.ok, res.errors
assert (tmp_ws.src / "hello.txt").read_text().strip() == "hi"
assert res.usage.input_tokens > 0 and res.tool_calls >= 1
+
+
+def test_job_images_ride_on_the_first_user_message(tmp_ws, tmp_path):
+ """Until 2026-08-26 no image reached an agent session: GenerationTask.images fed the
+ single-shot path only, so a `--image` reference was seen by the planner and the judge
+ and never by the code writer, and a refine session got "what the judge saw" as prose
+ without the sheet the prose was written about."""
+ from codeverse.contracts.chat import ImagePart
+
+ png = tmp_path / "sheet.png"
+ png.write_bytes(b"\x89PNG\r\n\x1a\n" + b"\x00" * 32)
+ fake = FakeChatModel([resp("Done")])
+ job = _job(tmp_ws)
+ job = job.model_copy(update={"images": [ImagePart(path=str(png), label="the contact sheet the judge scored (round 0)")]})
+ ApiAgent("fake:fake-1", chat_model=fake).run(job)
+ first = fake.requests[0].messages[0]
+ imgs = [pt for pt in first.parts if isinstance(pt, ImagePart)]
+ assert imgs and imgs[0].path == str(png), "the image must be a part of the FIRST user message"
+ assert "judge scored" in (imgs[0].label or "")
diff --git a/harness/tests/orchestrator_tracks/test_refine_sees_the_sheet.py b/harness/tests/orchestrator_tracks/test_refine_sees_the_sheet.py
new file mode 100644
index 00000000..411ef2f8
--- /dev/null
+++ b/harness/tests/orchestrator_tracks/test_refine_sees_the_sheet.py
@@ -0,0 +1,22 @@
+"""The refine session gets the contact sheet the judge scored, not just the prose about it."""
+
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+from codeverse.tracks.prompting import judged_sheet
+
+
+def test_the_judged_sheet_becomes_one_labelled_image(tmp_path):
+ png = tmp_path / "sheet.png"
+ png.write_bytes(b"\x89PNG\r\n\x1a\n" + b"\x00" * 32)
+ last = SimpleNamespace(index=2, renders=SimpleNamespace(contact_sheet=str(png)))
+ imgs = judged_sheet(last)
+ assert len(imgs) == 1 and imgs[0].path == str(png)
+ assert "round 2" in imgs[0].label and "judge" in imgs[0].label
+
+
+def test_no_sheet_means_no_image_not_an_error(tmp_path):
+ assert judged_sheet(SimpleNamespace(index=0, renders=None)) == []
+ assert judged_sheet(SimpleNamespace(index=0, renders=SimpleNamespace(contact_sheet=""))) == []
+ assert judged_sheet(SimpleNamespace(index=0, renders=SimpleNamespace(contact_sheet=str(tmp_path / "gone.png")))) == []