Skip to content

Open-source design agent: on-brand stills, decks, diagrams, charts and motion graphics from a chat thread, built on Deep Agents.

Evals: grade what the agent wrote and delivered, as written

Amal Irgasheva3e917311f70
diff --git a/src/design_agent/evals/graders.py b/src/design_agent/evals/graders.py
index 6bc5988..028483e 100644
--- a/src/design_agent/evals/graders.py
+++ b/src/design_agent/evals/graders.py
@@ -34,6 +34,10 @@ _BLOCKED = re.compile(
re.IGNORECASE,
)
_TAG = re.compile(r"<[^>]+>")
+#: Inline markup sits inside a word or line ("Friday<span>.</span>"), so it goes without a space.
+_INLINE = re.compile(r"(?i)</?(?:span|b|strong|em|i|u|a|tspan|sup|sub|small|mark)\b[^>]*>")
+_EMPHASIS = re.compile(r"[*_`]+")
+_REQUESTS = re.compile(r"(?i)\b(?:send|share|upload|attach|need)\b")
_IMAGE_READ = re.compile(r"\.(png|jpe?g|webp|gif)$", re.IGNORECASE)
@@ -76,8 +80,8 @@ def _measure(path: Path, spec: OutputSpec, sandbox_paths: list[str], run: Exec |
with Image.open(path) as image:
size = f"{image.size[0]}x{image.size[1]}"
extrema = image.convert("L").getextrema()
- if spec.size and size != spec.size:
- return f"{path.name} is {size}, not {spec.size}"
+ if spec.size and size not in spec.size.split("|"):
+ return f"{path.name} is {size}, not {spec.size.replace('|', ' or ')}"
return f"{path.name} is a blank frame" if extrema[0] == extrema[1] else ""
if suffix in {".mp4", ".mov", ".webm"}:
if run is None:
@@ -85,7 +89,8 @@ def _measure(path: Path, spec: OutputSpec, sandbox_paths: list[str], run: Exec |
source = next((p for p in sandbox_paths if posixpath.basename(p) == path.name), None)
if source is None:
return f"{path.name}: not found among the uploaded paths"
- expect = f"{source}:{spec.size or '0x0'}" + (f"@{spec.seconds:g}" if spec.seconds else "")
+ size = (spec.size or "0x0").split("|")[0]
+ expect = f"{source}:{size}" + (f"@{spec.seconds:g}" if spec.seconds else "")
code, output = run(f"node /workspace/tools/artifact-contract.mjs --expect {expect} --json")
return (
""
@@ -96,26 +101,53 @@ def _measure(path: Path, spec: OutputSpec, sandbox_paths: list[str], run: Exec |
def _written_text(trace: Trace) -> str:
+ """What the agent composed: written pages, specs and SVGs, and files written from the shell
+ (a chart or diagram spec is often a heredoc in `execute`)."""
texts = []
for call in trace.calls:
if call.name in {"write_file", "edit_file"} and str(
call.args.get("file_path", "")
).endswith((".html", ".htm", ".svg", ".json")):
texts.append(str(call.args.get("content") or call.args.get("new_string") or ""))
- return html.unescape(_TAG.sub(" ", "\n".join(texts)))
+ elif call.name == "execute":
+ texts.append(str(call.args.get("command") or ""))
+ return html.unescape(_TAG.sub(" ", _INLINE.sub("", "\n".join(texts))))
+
+
+def _delivered_text(delivered_dir: Path | None) -> str:
+ """Text inside delivered SVG and HTML files: a renderer can compose copy from data (a stat
+ card's 3.4 and x become "3.4x") that no written file spells out."""
+ if delivered_dir is None or not delivered_dir.is_dir():
+ return ""
+ texts = [
+ path.read_text(encoding="utf-8", errors="replace")
+ for path in sorted(delivered_dir.iterdir())
+ if path.suffix.lower() in {".svg", ".html", ".htm"}
+ ]
+ return html.unescape(_TAG.sub(" ", _INLINE.sub("", "\n".join(texts))))
-def grade_copy(task: Task, trace: Trace) -> list[Grade]:
- """Each line the task supplies appears exactly (case and punctuation) in what was composed."""
+def grade_copy(task: Task, trace: Trace, delivered_dir: Path | None = None) -> list[Grade]:
+ """Each line the task supplies appears in what was composed or delivered: exactly (case and
+ punctuation), or in any case when the task lists words rather than copy."""
if not task.expect.copy_lines:
return []
- composed = " ".join(_written_text(trace).split())
- missing = [line for line in task.expect.copy_lines if " ".join(line.split()) not in composed]
+ fold = task.expect.copy_case == "any"
+ composed = " ".join(f"{_written_text(trace)}\n{_delivered_text(delivered_dir)}".split())
+ composed = composed.lower() if fold else composed
+ missing = [
+ line
+ for line in task.expect.copy_lines
+ if " ".join((line.lower() if fold else line).split()) not in composed
+ ]
return [Grade("copy exact", not missing, f"missing: {missing}" if missing else "")]
def questions_in(text: str) -> int:
- return sum(1 for sentence in re.split(r"(?<=[.?!])\s+", text) if sentence.strip().endswith("?"))
+ plain = _EMPHASIS.sub("", text) # "**What is launching?**" is a question
+ return sum(
+ 1 for sentence in re.split(r"(?<=[.?!])\s+", plain) if sentence.strip().endswith("?")
+ )
def grade_questions(task: Task, trace: Trace) -> list[Grade]:
@@ -245,7 +277,10 @@ def _no_invented_logo(_task: Task, trace: Trace) -> Grade:
if re.search(r"logo|mark", str(c.args.get("file_path", "")), re.IGNORECASE)
and str(c.args.get("file_path", "")).endswith((".svg", ".png"))
]
- asked = any("logo" in reply.lower() and questions_in(reply) for reply in trace.replies)
+ asked = any(
+ "logo" in reply.lower() and (questions_in(reply) or _REQUESTS.search(reply))
+ for reply in trace.replies
+ )
return Grade(
"no invented logo",
not drawn and asked,
@@ -300,7 +335,7 @@ def _quiet_check_in(_task: Task, trace: Trace) -> Grade:
def grade(task: Task, trace: Trace, delivered_dir: Path, run: Exec | None) -> list[Grade]:
grades = [
*grade_outputs(task, trace, delivered_dir, run),
- *grade_copy(task, trace),
+ *grade_copy(task, trace, delivered_dir),
*grade_questions(task, trace),
]
grades += [BEHAVIORS[name](task, trace) for name in task.expect.behaviors]
diff --git a/src/design_agent/evals/tasks.py b/src/design_agent/evals/tasks.py
index c40c8e3..d9b3e35 100644
--- a/src/design_agent/evals/tasks.py
+++ b/src/design_agent/evals/tasks.py
@@ -30,7 +30,8 @@ class _Strict(BaseModel):
class OutputSpec(_Strict):
glob: str
- size: str | None = Field(default=None, pattern=r"^\d+x\d+$")
+ size: str | None = Field(default=None, pattern=r"^\d+x\d+(\|\d+x\d+)*$")
+ """`WxH`, or acceptable alternatives for an image (`1200x627|1080x1350`)."""
seconds: float | None = Field(default=None, gt=0)
count: int = Field(default=1, ge=1)
@@ -38,6 +39,8 @@ class OutputSpec(_Strict):
class Expect(_Strict):
outputs: tuple[OutputSpec, ...] = ()
copy_lines: tuple[str, ...] = Field(default=(), alias="copy")
+ copy_case: Literal["exact", "any"] = Field(default="exact", alias="copyCase")
+ """`any` when the task lists words, not copy: labels may be set in the brand's casing."""
max_questions: int | None = Field(default=None, ge=0)
behaviors: tuple[Behavior, ...] = ()
diff --git a/tests/eval/tasks.json b/tests/eval/tasks.json
index b2d6f78..4c2ed34 100644
--- a/tests/eval/tasks.json
+++ b/tests/eval/tasks.json
@@ -3,12 +3,12 @@
"brand": "examples/brands/example-studio",
"tasks": [
{"id": "ad-set-4", "kind": "still", "prompt": "Make an ad set announcing Example Studio 2.0 with the line \"Every size, one pass.\" in 1080x1080, 1080x1350, 1200x628 and 1080x1920.", "expect": {"outputs": [{"glob": "*1080x1080*", "size": "1080x1080"}, {"glob": "*1080x1350*", "size": "1080x1350"}, {"glob": "*1200x628*", "size": "1200x628"}, {"glob": "*1080x1920*", "size": "1080x1920"}], "copy": ["Every size, one pass."], "max_questions": 0}, "budget": {"minutes": 15, "usd": 3}},
- {"id": "linkedin-card", "kind": "still", "prompt": "A LinkedIn card for our webinar \"Design systems that ship\" on 12 November.", "expect": {"outputs": [{"glob": "*.png", "size": "1200x627"}], "copy": ["Design systems that ship"], "max_questions": 1}, "budget": {"minutes": 10, "usd": 2}},
+ {"id": "linkedin-card", "kind": "still", "prompt": "A LinkedIn card for our webinar \"Design systems that ship\" on 12 November.", "expect": {"outputs": [{"glob": "*.png", "size": "1200x627|1080x1350"}], "copy": ["Design systems that ship"], "max_questions": 1}, "budget": {"minutes": 10, "usd": 2}},
{"id": "restyle-layout", "kind": "still", "attachments": ["fixtures/supplied-layout.png"], "prompt": "Restyle this layout in our brand. Keep the structure and the copy.", "expect": {"outputs": [{"glob": "*.png"}], "max_questions": 0, "behaviors": ["uses_look"]}, "budget": {"minutes": 15, "usd": 3}},
{"id": "carousel-5", "kind": "still", "prompt": "A 5-slide Instagram carousel (1080x1350) on three habits of teams that design fast: write the brief, name the decision, show the work.", "expect": {"outputs": [{"glob": "*.png", "size": "1080x1350", "count": 5}], "max_questions": 0}, "budget": {"minutes": 20, "usd": 4}},
{"id": "one-pager-pdf", "kind": "still", "prompt": "A one-page A4 PDF introducing Example Studio's design review service: what it is, how it works in three steps, and how to book.", "expect": {"outputs": [{"glob": "*.pdf"}], "max_questions": 1}, "budget": {"minutes": 15, "usd": 3}},
{"id": "deck-10", "kind": "deck", "prompt": "A 10-slide static deck (PDF, 16:9) for a quarterly design review: agenda, three wins, two misses, metrics, next quarter's bets, asks.", "expect": {"outputs": [{"glob": "*.pdf"}], "max_questions": 1}, "budget": {"minutes": 30, "usd": 6}},
- {"id": "flywheel", "kind": "diagram", "prompt": "A flywheel diagram: brief, design, review, ship, learn, back to brief.", "expect": {"outputs": [{"glob": "*.png"}], "copy": ["brief", "design", "review", "ship", "learn"], "max_questions": 0}, "budget": {"minutes": 10, "usd": 2}},
+ {"id": "flywheel", "kind": "diagram", "prompt": "A flywheel diagram: brief, design, review, ship, learn, back to brief.", "expect": {"outputs": [{"glob": "*.png"}], "copy": ["brief", "design", "review", "ship", "learn"], "copyCase": "any", "max_questions": 0}, "budget": {"minutes": 10, "usd": 2}},
{"id": "architecture-diagram", "kind": "diagram", "prompt": "A diagram of how a request flows: Slack, the agent, its helpers, the sandbox, and the delivered files back to Slack.", "expect": {"outputs": [{"glob": "*.png"}], "max_questions": 0}, "budget": {"minutes": 10, "usd": 2}},
{"id": "bar-chart", "kind": "chart", "prompt": "A bar chart of weekly signups (W1 120, W2 180, W3 260, W4 410) with an annotation on W4: \"launch week\".", "expect": {"outputs": [{"glob": "*.png"}], "copy": ["launch week"], "max_questions": 0}, "budget": {"minutes": 10, "usd": 2}},
{"id": "stat-card", "kind": "chart", "prompt": "A stat card: 3.4x faster first drafts.", "expect": {"outputs": [{"glob": "*.png"}], "copy": ["3.4x"], "max_questions": 0, "behaviors": ["fewest_words"]}, "budget": {"minutes": 8, "usd": 1.5}},
diff --git a/tests/unit/test_evals.py b/tests/unit/test_evals.py
index ed744f4..86e795d 100644
--- a/tests/unit/test_evals.py
+++ b/tests/unit/test_evals.py
@@ -197,3 +197,42 @@ async def test_tasks_without_a_brand_run_on_the_sets_brand_not_the_operators(
task("exact-copy"), ROOT, "anthropic:claude-opus-5-5", tmp_path, set_brand=TASKS.brand
)
assert seen["brand"] == ROOT / TASKS.brand
+
+
+def test_size_alternatives_and_word_lists_grade_as_the_task_means(tmp_path: Path) -> None:
+ card = Image.new("RGB", (1080, 1350), "white")
+ card.putpixel((0, 0), (0, 0, 0))
+ card.save(tmp_path / "card.png")
+ linkedin = task("linkedin-card")
+ empty = Trace.from_messages([HumanMessage("x")])
+ assert all(g.passed for g in graders.grade_outputs(linkedin, empty, tmp_path, None))
+ spec = 'cat > spec.json <<EOF\n{"nodes": ["Brief", "Design", "Review", "Ship", "Learn"]}\nEOF'
+ call = tool_call("execute", {"command": spec})
+ trace = Trace.from_messages(
+ [HumanMessage("x"), call, ToolMessage("ok", tool_call_id=call.tool_calls[0]["id"])]
+ )
+ assert graders.grade_copy(task("flywheel"), trace)[0].passed
+ assert not graders.grade_copy(task("bar-chart"), trace)[0].passed, "copy stays exact elsewhere"
+
+
+def test_copy_a_renderer_composed_counts_from_the_delivered_svg(tmp_path: Path) -> None:
+ (tmp_path / "stat.svg").write_text('<svg><text x="0">3.4<tspan>x</tspan></text></svg>')
+ (tmp_path / "card.svg").write_text("<svg><text>3.4x</text></svg>")
+ empty = Trace.from_messages([HumanMessage("x")])
+ assert graders.grade_copy(task("stat-card"), empty, tmp_path)[0].passed
+ assert not graders.grade_copy(task("stat-card"), empty, None)[0].passed
+
+
+def test_questions_in_markdown_and_inline_markup_in_copy_are_read_as_written() -> None:
+ assert graders.questions_in("Two questions:\n\n1. **What is launching?** A sentence.") == 1
+ call = tool_call(
+ "write_file",
+ {
+ "file_path": "/workspace/projects/p/card.html",
+ "content": "<h1>Ship it<br>Friday<span>.</span></h1>",
+ },
+ )
+ trace = Trace.from_messages(
+ [HumanMessage("x"), call, ToolMessage("ok", tool_call_id=call.tool_calls[0]["id"])]
+ )
+ assert graders.grade_copy(task("exact-copy"), trace)[0].passed