Remove think tool and view bounds from JSON

The guided thinking within the tags works better and doesn't run the
risk of hitting request rate limits; the DR comment poster needs to use
SVG coordinates, not JSON.
This commit is contained in:
Shrikanth Upadhayaya 2025-04-02 12:03:17 -04:00
parent 5312e6cbea
commit 6b64bec258
No known key found for this signature in database
6 changed files with 13 additions and 40 deletions

View File

@ -4,7 +4,7 @@ from dataclasses import dataclass
from typing import Optional
from pydantic import BaseModel, Field
from pydantic_ai import Agent, RunContext
from pydantic_ai import Agent
from pydantic_ai.settings import ModelSettings
from lib import run_agent_with_retries
@ -61,7 +61,7 @@ First, review the full schematic in <thinking></thinking> tags. Consider your
notes, the overall purpose of the the design, and any issues you see in your
memory or the comments. Make sure the comments are relevant and not
inconsistent. Think through the comments and decide if they would be useful to
the junior engineer; if they aren't, feel free to remove them.
the junior engineer; if they aren't, feel free to remove them.
Once you are done thinking, respond in <output> tags in JSON following the
given schema:
@ -101,8 +101,6 @@ Notes for your review:
3. Your recommendations SHOULD include a reference to WHAT component, pin or
net should be reviewed.
4. The text in your comments MUST be in markdown.
5. You have access to a tool to give you more time to think about the
schematic. Use it if you need to.
"""
@ -114,17 +112,6 @@ final_agent = Agent(
)
@final_agent.tool()
async def think_tool(ctx: RunContext[FinalAgentDeps]):
"""
A tool to give the agent more time to think about the schematic.
"""
ctx.deps.logger.debug("Thinking.")
return "Hmm."
async def call(
memory: str,
comments: list[Comment],

17
lib.py
View File

@ -3,7 +3,6 @@
import asyncio
import logging
from dataclasses import dataclass
from typing import Any, Optional, Sequence
from xml.etree import ElementTree as ET
@ -104,13 +103,7 @@ def filter_schematic_json(schematic_json: dict[str, Any]) -> dict[str, Any]:
return filtered_json
@dataclass
class SVGPage:
svg_text: str
view_bounds: list[float]
def split_multipage_svg(svg_text: str) -> list[SVGPage]:
def split_multipage_svg(svg_text: str) -> list[str]:
"""
Split a multi-page SVG into individual SVG files, one for each page.
Uses ElementTree for proper XML parsing.
@ -138,7 +131,7 @@ def split_multipage_svg(svg_text: str) -> list[SVGPage]:
if current.tag.endswith("}style") and next_elem.tag.endswith("}g"):
page_pairs.append((current, next_elem))
output_files: list[SVGPage] = []
output_files = []
for i, (style_elem, g_elem) in enumerate(page_pairs):
new_svg = ET.Element("svg")
@ -166,11 +159,7 @@ def split_multipage_svg(svg_text: str) -> list[SVGPage]:
svg_str = ET.tostring(new_svg, encoding="unicode")
# viewbox is like "-1.346,3.734 421.792,272.694"
view_bounds = view_box.replace(",", " ").split(" ")
page = SVGPage(svg_text=svg_str, view_bounds=[float(x) for x in view_bounds])
output_files.append(page)
output_files.append(svg_str)
return output_files

13
main.py
View File

@ -10,7 +10,7 @@ import final_agent
import step_agent
from lib import filter_schematic_page, render_svg, split_multipage_svg
VERSION = (0, 4, 4)
VERSION = (0, 5, 0)
RETRY_DELAY = 60
"""
@ -72,19 +72,19 @@ async def main():
assert len(json_pages) == len(svg_pages)
page_paths = []
for i, (json_page, svg_page) in enumerate(zip(json_pages, svg_pages)):
for i, (json_page, svg_text) in enumerate(zip(json_pages, svg_pages)):
page_svg_path = os.path.join(temp_dir.name, f"page_{i + 1}.svg")
page_png_path = os.path.join(temp_dir.name, f"page_{i + 1}.png")
page_json_path = os.path.join(temp_dir.name, f"page_{i + 1}.json")
with open(page_svg_path, "w") as f:
f.write(svg_page.svg_text)
f.write(svg_text)
await render_svg(page_svg_path, page_png_path)
with open(page_json_path, "w") as f:
page_json = filter_schematic_page(json_page)
json.dump(page_json, f)
page_paths.append((page_json_path, page_png_path, svg_page.view_bounds))
page_paths.append((page_json_path, page_png_path))
logger.info(f"Wrote page {i + 1} to {page_json_path}")
@ -99,11 +99,9 @@ async def main():
current_memory = ""
current_comments = []
page_view_bounds = []
for i, (page_json_path, page_png_path, page_bounds) in enumerate(page_paths):
for i, (page_json_path, page_png_path) in enumerate(page_paths):
logger.info(f"Reviewing page {i + 1}/{len(page_paths)}")
page_view_bounds.append(page_bounds)
with open(page_json_path, "r") as f:
page_json = f.read()
@ -161,7 +159,6 @@ async def main():
sys.exit(1)
out_json = final_result.model_dump(mode="json")
out_json["page_view_bounds"] = page_view_bounds
with open(args.output_path, "w") as f:
json.dump(out_json, f, indent=4)

View File

@ -2,7 +2,7 @@
[project]
name = "llm-review"
version = "0.4.4"
version = "0.5.0"
readme = "README.md"
requires-python = ">=3.13"
dependencies = ["playwright>=1.51.0", "pydantic-ai>=0.0.41"]

View File

@ -25,7 +25,7 @@ class StepResponse(BaseModel):
comments: list[Comment] = Field(
...,
description="A list of comments to be made on the design for this page.",
description="A list of comments to be made on the design ONLY for this page.",
)

2
uv.lock generated
View File

@ -407,7 +407,7 @@ wheels = [
[[package]]
name = "llm-review"
version = "0.4.3"
version = "0.5.0"
source = { virtual = "." }
dependencies = [
{ name = "playwright" },