11""" DiagramAnalyst — explains/describes the diagram on the canvas.
22
3- Fetches canvas elements via get_canvas_elements tool and provides analysis .
3+ Canvas elements are pre-fetched by the orchestrator and passed as canvas_elements_json .
44Read-only agent: no modification tools.
55"""
66
@@ -12,12 +12,11 @@ node DiagramAnalyst {
1212 has api_key : str = " " ;
1313 has llm : Any = None ;
1414
15- def explain (message : str , conversation_log : str ) -> str
15+ def explain (message : str , conversation_log : str , canvas_elements_json : str ) -> str
1616 by self .llm(
17- tools = [use_canvas_tool],
18- max_react_iterations = 2 ,
17+ tools = [],
1918 incl_info = {
20- " available_canvas_tools " : [t for t in _analyst_provider.list_tools() if t[ " name " ] in ANALYST_TOOLS ] ,
19+ " canvas_elements_json " : canvas_elements_json ,
2120 " conversation" : conversation_log
2221 }
2322 );
@@ -26,10 +25,7 @@ node DiagramAnalyst {
2625sem DiagramAnalyst .explain = """
2726Explain the JaSketch canvas diagram to the user.
2827
29- Workflow:
30- 1. Call use_canvas_tool("get_canvas_elements", "{} ") to fetch the current diagram
31- 2. Analyze the elements to understand the diagram structure
32- 3. Explain to the user what the diagram shows, its purpose, key components, and relationships
28+ Canvas data is already provided in `canvas_elements_json` from context — parse it directly.
3329
3430Element Types and Key Fields (runtime format):
3531 - rectangle / circle / diamond: x, y, width, height, shapeText (label inside shape), color, fillColor, boundElements (list of connected arrow IDs)
@@ -41,39 +37,16 @@ Element Types and Key Fields (runtime format):
4137 - freehand: x, y, points (free-drawn path)
4238
4339Your Task:
44- 1. Fetch canvas elements via use_canvas_tool("get_canvas_elements", "{}")
40+ 1. Parse canvas_elements_json from incl_info to extract the "elements" array
4541 2. Identify shapes (by type + shapeText labels) and connections (arrows via startBinding/endBinding elementIds)
4642 3. Understand the overall diagram structure: what it represents, its purpose, layout
4743 4. Explain clearly: what diagram this is, what it shows, key components, and how they relate
4844
45+ If canvas_elements_json is empty or has no elements, explain that the canvas is currently empty.
46+
4947Read-only: explain only, do NOT attempt to modify the canvas.
5048
5149User message: {{message}}
5250
5351Respond now.
5452""" ;
55-
56- # ── Tool binding (populated by orchestrator before each call) ──────────────────
57-
58- glob ANALYST_TOOLS: list [str ] = [" get_canvas_elements" ];
59-
60- glob _analyst_provider: Any = None ;
61-
62- def use_canvas_tool (name : str , arguments : str ) -> str {
63- args: dict = {};
64- try {
65- if isinstance (arguments, dict ) { args = arguments; }
66- elif arguments { args = json.loads(arguments); }
67- } except Exception { args = {}; }
68- return _analyst_provider.call_tool(name, args);
69- }
70- sem use_canvas_tool = " Call a canvas tool by name. Only use tools listed in available_canvas_tools from context." ;
71- sem use_canvas_tool .name = " Tool name — must exactly match one of the names in available_canvas_tools." ;
72- sem use_canvas_tool .arguments = " JSON object string matching the inputSchema of the named tool. Build from the schema in available_canvas_tools." ;
73-
74- # ── Provider injection (called by orchestrator) ────────────────────────────────
75-
76- def _set_analyst_provider (provider : Any) -> None {
77- global _analyst_provider;
78- _analyst_provider = provider;
79- }
0 commit comments