feat: enhance all multi-agent vision, reasoning, symbol, topology, and ingestion prompts with industrial engineering specifications

This commit is contained in:
Abhinav Gupta
2026-09-03 11:41:37 +05:30
parent 0722877947
commit f92e23accd
4 changed files with 136 additions and 96 deletions
+19 -16
View File
@@ -258,25 +258,28 @@ class IngestionAgent(BaseAgent):
Drawing-type detection is built into the schema and prompt — works for any discipline. Drawing-type detection is built into the schema and prompt — works for any discipline.
""" """
system_instruction = ( system_instruction = (
"You are a professional engineering document ingestion system. " "You are a senior engineering document control specialist. "
"Examine the provided engineering drawing image, look closely at the title block, " "Examine the engineering drawing canvas, focusing on the title block (bottom-right), "
"sheet headers, and drawing notes. Extract structured metadata accurately. " "drawing header frames, revision history tables, and drawing notes blocks. "
"Identify the drawing type from the drawing content and title — it may be a P&ID, " "Extract complete, standardized metadata across all engineering disciplines."
"Electrical Layout, Earthing Layout, SLD, HVAC, Structural, or other discipline."
) )
prompt = ( prompt = (
"Extract the following metadata from this engineering drawing. " "Dissect the engineering drawing title block and border frames to extract complete document metadata:\n\n"
"Look carefully at the title block (usually bottom-right) and all sheet headers:\n\n" "1. drawing_type: Standardized discipline category:\n"
"- drawing_type: One of: PID, PFD, ELECTRICAL_LAYOUT, EARTHING_LAYOUT, SLD, " " - PID: Piping and Instrumentation Diagram\n"
"HVAC_LAYOUT, STRUCTURAL_LAYOUT, ISOMETRIC, CABLE_SCHEDULE, GENERIC\n" " - PFD: Process Flow Diagram\n"
"- discipline: Engineering discipline (Process, Electrical, Mechanical, Civil, etc.)\n" " - ELECTRICAL_LAYOUT: Lighting, power, cable routing layout\n"
"- drawing_number: Unique document/sheet number from title block\n" " - EARTHING_LAYOUT: Grounding and lightning protection layout\n"
"- title: Full title as written on the drawing (e.g., LIGHTING LAYOUT - 1, EARTHING LAYOUT)\n" " - SLD: Single Line Diagram / Electrical schematic\n"
"- revision: Revision character or number (e.g., 0, 1, A, B)\n" " - HVAC_LAYOUT / STRUCTURAL_LAYOUT / ISOMETRIC / CABLE_SCHEDULE / GENERIC\n\n"
"- client_name: Owner or client name if shown\n" "2. drawing_number: Exact official drawing / document number (e.g., 26-00-14-101, DWG-EL-0042-01).\n"
"- page_count: Total sheets if multi-sheet package, otherwise 1\n\n" "3. title: Full primary title and subtitle as formatted in the title block (e.g., 'LIFT GAS COMPRESSOR SYSTEM', 'LIGHTING LAYOUT - LEVEL 1').\n"
f"Filename hint (may help identify drawing type): {filename or 'N/A'}" "4. discipline: Primary engineering discipline (Process, Piping, Electrical, Instrumentation, Mechanical, Civil/Structural).\n"
"5. revision: Latest revision code from the revision block (e.g., '0', '1', 'A', 'B', 'REV 02').\n"
"6. client_name: Facility owner, operator, or EPC contractor name from title block logo area.\n"
"7. page_count: Total sheet count if part of a multi-sheet drawing set (otherwise 1).\n\n"
f"Filename Hint: {filename or 'N/A'}"
) )
try: try:
+96 -71
View File
@@ -84,60 +84,56 @@ def _deduplicate_tiled_boxes(raw_boxes: List[Dict[str, Any]], iou_thresh: float
# ────────────────────────────────────────────────────────────────────────────── # ──────────────────────────────────────────────────────────────────────────────
_PID_TAG_CATEGORIES = ( _PID_TAG_CATEGORIES = (
" - EQUIPMENT_TAG: Compressors, motors, vessels, skids, coolers, filters " " - EQUIPMENT_TAG: Process equipment tags with or without area prefix (e.g. 26-KA-902 compressor, "
"(e.g., 26-KA-901, TK-101, P-101).\n" "26-CX-9021 coalescing filter, 26-HA-911 heat exchanger, 26-TK-9001 storage tank, 26-ST-9002 suction strainer, "
" - LINE_TAG: Piping run descriptions with size, fluid service, spec class " "26-PA-901A pump). Capture sub-trains (e.g. HA-911-C01, HA-911-C02) and extract all dense datasheet block parameters "
"(e.g., 8\"-PV-26-9035-FC11S-08, 3\"-VA-26-9121-AC21-00).\n" "(duty, design pressure, design temperature, flow rate, material, vendor, motor rating) into attributes.\n"
" - INSTRUMENT_TAG: Sensors, bubbles, transmitters, indicators " " - LINE_TAG: Complete piping line designations following ISA format [Size]-[Service]-[Area]-[Sequence]-[Spec]-[Insulation] "
"(e.g., PIT-9062, TIT-9057, PDIT-9054).\n" "(e.g. 8\"-PV-26-9035-FC11S-08, 10\"-VF-43-9027-AS20S-00, 3\"-VA-26-9121-AC21-00). Do NOT invent notes or note suffixes. "
" - VALVE_TAG: Manual, control, check, gate, globe, needle valves " "Reject electrical cables, transmitter loops, or motor tags from line list.\n"
"(e.g., 26GB9178, HV-101, XV-201).\n" " - INSTRUMENT_TAG: ISA 5.1 sensor bubbles, transmitters, switches, and relays (e.g. 26-PIT-9077, TIT-9057, "
" - PSV_TAG: Pressure Safety Valves (e.g., 26-PSV-9066A, PSV-101A).\n" "26-PDI-9054, 27-PY-0001BA/BB, ZIT-9011, VIT-9020). For split sibling tags ('BA/BB'), emit both individual items.\n"
" - NOTE: Plain English notes, descriptions, labels (e.g., HIGH POINT, NOTE 35).\n" " - VALVE_TAG: In-line manual and actuated valves with functional categorization (e.g. 26GB9178 Gate, 26CB9131 Check, "
" - RATING: Numeric specs like 150#, 2500#, pressure classes.\n" "43BL9070 Ball, HV-101 Hand Control, XV-201 Shutdown, 26-ND-901 Needle, 26-BF-902 Butterfly). Extract ANSI rating class (150#, 300#, 2500#).\n"
" - PSV_TAG: Pressure Safety Relief Valves (e.g. 26-PSV-9066A, PSV-9027A, PSV-9027B). Capture set pressure (e.g. 225.4 bar(g)), "
"inlet/outlet sizes, and relief header destination (e.g. HP Flare Header, LP Flare Header).\n"
" - NOTE: Engineering callouts, revision notes, hold notes, and drawing reference markers (e.g. 'SEE DWG', 'HOLD', 'NOTE 12').\n"
" - RATING: Pressure/temperature ratings, flange classes (150#, 300#, 600#, 900#, 1500#, 2500#, PN16, PN40) and setpoint values.\n"
) )
_ELECTRICAL_TAG_CATEGORIES = ( _ELECTRICAL_TAG_CATEGORIES = (
" - PANEL_TAG: Distribution boards, MDBs, LDBs, switchgear panels " " - PANEL_TAG: Distribution boards, main switchboards, MDBs, LDBs, MCCs, control panels "
"(e.g., DB-01, MDB-A, LDB-3, EMDB, SMDB).\n" "(e.g. DB-01, MDB-A, LDB-3, EMDB, SMDB, MCC-26).\n"
" - LUMINAIRE_TAG: Light fittings, lamps, luminaires " " - LUMINAIRE_TAG: Light fittings, lamps, emergency exit lights, floodlights (e.g. L-01, LS-201, TL-101, FL-01, EX-01).\n"
"(e.g., L-01, LS-201, TL-101, FL-01).\n" " - CIRCUIT_TAG: Electrical branch circuits, circuit breakers, MCBs, MCCBs, fuses (e.g. C-101, CB-01, MCB-1, RCCB-3, DB-1/R1).\n"
" - CIRCUIT_TAG: Electrical circuits, breakers, MCBs " " - ELEVATION_TAG: Elevation references and mounting heights (e.g. EL.101.445, TL 100.000, +2.400 AFF, +0.500 FFL).\n"
"(e.g., C-101, CB-01, MCB-1, RCCB-3).\n" " - EQUIPMENT_TAG: Motors, HVAC units, transformers, generators, UPS, AHUs (e.g. M-101, TR-01, AHU-01, GEN-01).\n"
" - ELEVATION_TAG: Elevation labels and level references " " - NOTE: Wiring specifications, installation notes, conduit sizes (e.g. 3x2.5mm² Cu/XLPE/PVC in 25mmØ conduit).\n"
"(e.g., EL.101.445, TL 100.000, EL +103.000).\n" " - RATING: Voltage, amperage, frequency ratings (e.g. 415V, 230V, 32A, 100A, 3Φ 50Hz, IP65, 2x36W).\n"
" - EQUIPMENT_TAG: Generic equipment tags (e.g., AHU-01, FAN-01, AC-01).\n"
" - NOTE: Wiring notes, area labels, installation notes.\n"
" - RATING: Electrical ratings (e.g., 415V, 32A, 3Φ).\n"
) )
_EARTHING_TAG_CATEGORIES = ( _EARTHING_TAG_CATEGORIES = (
" - EARTH_BAR_TAG: Earthing bars and main earth terminals " " - EARTH_BAR_TAG: Main earthing terminals, earth bars, clean earth bars (e.g. EB-01, EBM-01, MEB, EEB, TEB).\n"
"(e.g., EB-01, EBM-01, MEB).\n" " - EARTH_PIT_TAG: Earth test pits, earth electrodes, bore earth pits (e.g. EP-01, EP-A, TP-01, Earth Pit #4).\n"
" - EARTH_PIT_TAG: Earth electrodes and earth pits " " - BOND_CONDUCTOR_TAG: Earthing tape, bonding jumpers, grounding conductors (e.g. BC-01, EC-01, 50x6mm Cu Tape, 70mm² PVC Green/Yellow).\n"
"(e.g., EP-01, EP-A, earth pit).\n" " - EQUIPMENT_TAG: Structures, tanks, vessels, skids, motors, fence gates requiring grounding (e.g. TK-101, SK-01, Steel Column B4).\n"
" - BOND_CONDUCTOR_TAG: Bonding conductors and earth cables " " - ELEVATION_TAG: Ground elevation benchmarks and depth markings (e.g. EL.100.000, GL 0.000, -3.000m depth).\n"
"(e.g., BC-01, EC-01, earthing conductor).\n" " - NOTE: Resistance requirements and jointing specifications (e.g. '< 1.0 Ohm', 'Cadweld exothermic connection').\n"
" - EQUIPMENT_TAG: Equipment being earthed (e.g., structural members, tanks, panels).\n" " - RATING: Resistance and cross-sectional conductor ratings (e.g. 0.5 Ohm, 95mm², 120kA 1s).\n"
" - ELEVATION_TAG: Elevation labels (e.g., EL.101.445, TL 100.000).\n"
" - NOTE: Installation notes, material specs (e.g., 50x6mm Copper Tape).\n"
" - RATING: Resistance values, conductor sizes (e.g., <1 Ohm, 95mm²).\n"
) )
_SLD_TAG_CATEGORIES = ( _SLD_TAG_CATEGORIES = (
" - PANEL_TAG: Switchgear, busbars, transformers, MVDBs, LVDBs " " - PANEL_TAG: Switchboards, busbars, MV/LV switchgear, motor control centers (e.g. MVDB-01, LVDB-A, TR-01, MSB, 11kV BUS-A).\n"
"(e.g., MVDB-01, LVDB-A, TR-01, MSB).\n" " - CIRCUIT_TAG: Air circuit breakers (ACB), vacuum circuit breakers (VCB), MCCBs, isolators, contactors (e.g. ACB-01, VCB-02, Q1, F1).\n"
" - CIRCUIT_TAG: Feeders, breakers, contactors " " - EQUIPMENT_TAG: Heavy electrical loads, transformers, generators, variable frequency drives (VFD), motors (e.g. TR-01, M-101, VFD-01).\n"
"(e.g., ACB-01, MCCB-3, VCB-01, feeder).\n" " - RATING: Short circuit withstand, busbar current, voltage ratings (e.g. 11kV, 415V, 50kA 1s, 2500A, 500kVA, PF 0.85).\n"
" - EQUIPMENT_TAG: Motors, loads, generators (e.g., M-101, G-01).\n" " - NOTE: Protection relay settings, CT/PT ratios, interlock logic (e.g. 50/51 100/5A 5P20, Kast key interlock).\n"
" - RATING: Electrical ratings (e.g., 11kV, 415V, 500kVA, 1250A).\n"
" - NOTE: Protection settings, fault levels, cable sizes.\n"
) )
_GENERIC_TAG_CATEGORIES = ( _GENERIC_TAG_CATEGORIES = (
" - EQUIPMENT_TAG: Any equipment with a tag number (e.g., TK-101, P-101, E-201).\n" " - EQUIPMENT_TAG: Any tagged industrial equipment or mechanical assembly (e.g. TK-101, P-101, E-201, C-101).\n"
" - NOTE: Labels, descriptions, specifications.\n" " - NOTE: Descriptive engineering text, labels, instructions, material notes.\n"
" - RATING: Numeric specifications.\n" " - RATING: Physical, electrical, or thermal ratings.\n"
) )
_SYMBOL_VOCAB: Dict[str, str] = { _SYMBOL_VOCAB: Dict[str, str] = {
@@ -540,16 +536,29 @@ class TextRecognitionAgent(BaseAgent):
tag_categories = _get_tag_categories(drawing_type) tag_categories = _get_tag_categories(drawing_type)
reasoning_prompt = ( reasoning_prompt = (
f"You are an expert engineering data parser and reasoning engine for {drawing_type.replace('_', ' ')} drawings.\n" f"You are a senior process and electrical engineering data parser and reasoning engine analyzing a {drawing_type.replace('_', ' ')} drawing.\n"
"Below is the Layer 1 OCR output extracted from the drawing:\n" "Below is the Layer 1 raw OCR text elements extracted from the drawing:\n"
" <text> | conf=<confidence> | pos=(<center_x>, <center_y>)\n\n" " <text> | conf=<confidence> | pos=(<center_x>, <center_y>)\n\n"
f"RAW OCR TEXT FROM LAYER 1:\n{raw_text_block}\n\n" f"RAW OCR TEXT FROM LAYER 1:\n{raw_text_block}\n\n"
"PERFORM DEEP REASONING & REFINEMENT:\n" "EXECUTE RIGOROUS ENGINEERING REASONING & REFINEMENT:\n"
"1. FIX OCR TYPOS: Correct misread letters/digits (e.g., P1T-9055 -> PIT-9055, 0B-01 -> DB-01, E8-01 -> EB-01).\n" "1. FIX OCR TYPOS & DECIMAL POINTS:\n"
"2. RECOMBINE SPLIT TEXT: Re-assemble tags that were split across multiple OCR lines.\n" " - Correct misread characters (e.g., P1T-9055 -> PIT-9055, 0B-01 -> DB-01, E8-01 -> EB-01, FC115 -> FC11S, B\" -> 8\").\n"
"3. IDENTIFY MISPLACED DATA: Map nearby specifications (design pressure, design temp, wattage, rating, cable size, elevation, material, duty) into the parent tag's attributes dict.\n" " - Restore zero-prefixed missing decimal points in pressure ratings (e.g., '005BARG' -> '0.005 BARG', '050BARG' -> '0.50 BARG').\n"
"4. FIND MISSING TAGS/ENTITIES: Visually inspect the drawing image to find any missing tags or equipment referenced in callouts or note blocks.\n" "2. RECOMBINE SPATIALLY SPLIT TEXT:\n"
"5. CLASSIFY & STRUCTURE: Map every entity into ONE of the following categories:\n" " - Re-assemble multi-line piping strings (e.g., size '8\"', service 'PV', spec 'FC11S' on adjacent lines -> '8\"-PV-26-9035-FC11S-08').\n"
" - Re-assemble split valve and instrument tags (e.g., 'HV-' and '101' -> 'HV-101').\n"
"3. SPLIT SIBLING TAGS & INVERTED NOTATIONS:\n"
" - Split dual instrument transmitter tags (e.g., '27-PY-0001BA/BB' -> emit '27-PY-0001BA' and '27-PY-0001BB').\n"
" - Invert drawing-specific suction strainer tags (e.g., '9002 S 26' -> emit '26-ST-9002' as EQUIPMENT_TAG).\n"
"4. EQUIPMENT DATASHEET & ATTRIBUTE BINDING:\n"
" - Parse dense parameter blocks (Duty, Design Pressure, Design Temp, Flow Rate, Material, Vendor, Flange Rating) and inject them into the parent equipment/valve attributes dict.\n"
" - For PSVs, capture exact set pressure (e.g., '225.4 bar(g)'), inlet/outlet sizes, and relief header destination ('HP Flare Header').\n"
"5. ANTI-HALLUCINATION & STRICT SCHEMA VALIDATION:\n"
" - Do NOT invent placeholder suffixes ('...-NOTE', '...-TIT') in piping lines.\n"
" - Do NOT classify motor tags (e.g., '26-KA-902-M01') or instrument wires as lines.\n"
" - Ensure reference callouts ('FROM DWG', 'CONTINUED ON') are marked as reference notes.\n"
"6. CLASSIFY & STRUCTURE:\n"
" - Categorize every entity accurately into ONE of the following classes:\n"
+ tag_categories + "\n" + tag_categories + "\n"
"Return the cleaned, structured findings as a validated RawTextList JSON." "Return the cleaned, structured findings as a validated RawTextList JSON."
) )
@@ -558,8 +567,8 @@ class TextRecognitionAgent(BaseAgent):
schema=RawTextList, schema=RawTextList,
prompt=reasoning_prompt, prompt=reasoning_prompt,
system_instruction=( system_instruction=(
"You are an AI engineering data reasoning engine. Your goal is to find missing data, " "You are an expert AI engineering data reasoning engine. Your objective is to achieve 100% extraction fidelity: "
"correct OCR errors, map misplaced attributes, and output clean structured JSON." "correct all OCR errors, restore dropped decimals, bind datasheet attributes, reject hallucinations, and output clean structured JSON."
), ),
image_path=raw_image, image_path=raw_image,
provider=llm_provider, provider=llm_provider,
@@ -751,14 +760,24 @@ class SymbolRecognitionAgent(BaseAgent):
elif not (local_mode or symbol_engine == "local"): elif not (local_mode or symbol_engine == "local"):
prompt = ( prompt = (
f"You are an expert industrial vision detector specializing in ISA-5.1 and engineering symbol recognition for {dt_label} drawings.\n" f"You are a computer vision specialist in ISA-5.1 industrial symbol taxonomy and electrical schematics for {dt_label} drawings.\n\n"
f"Identify all graphical component symbols present in this drawing image.\n\n" "OBJECTIVE: Detect and localize all graphical components and symbols on the drawing canvas.\n\n"
f"SYMBOL TAXONOMY VOCABULARY:\n {symbol_vocab}\n\n" f"AUTHORIZED SYMBOL VOCABULARY:\n {symbol_vocab}\n\n"
"FOR EACH DETECTED SYMBOL PROVIDE:\n" "MORPHOLOGICAL SYMBOL RECOGNITION RULES:\n"
" 1. symbol_type: The exact symbol classification from the taxonomy vocabulary.\n" " • CHECK_VALVE: Two opposing triangles or a directional flap/arrowhead across a seat.\n"
" 2. inferred_tag: Nearest readable tag number/ID (e.g., 26CB9131, PIT-9055, DB-01, EP-01) if visible nearby.\n" " • GATE_VALVE: Two opposing triangles touching at vertex along a pipeline.\n"
" 3. ymin, xmin, ymax, xmax: Normalized bounding box coordinates between 0.0 and 1.0.\n\n" " • BALL_VALVE: Opposing triangles with a solid black/filled circle at center.\n"
"Return the list of detected symbols in structured JSON format." " • GLOBE_VALVE: Opposing triangles with an open circle at center.\n"
" • CONTROL_VALVE: Valve body attached to a top pneumatic diaphragm/dome or motor actuator.\n"
" • PSV / SAFETY_VALVE: Angled body with inlet on run and discharge elbow to header with spring bonnet.\n"
" • INST_BUBBLE: Circular bubbles (field mounted = plain circle, control room = horizontal line across circle).\n"
" • STRAINER: Y-shaped branch casing or in-line bucket strainer body (e.g. 26-ST-9002).\n"
" • EQUIPMENT: Major vessels, compressors (trapezoidal profile), pumps (circular impeller casing), heat exchangers.\n\n"
"FOR EACH DETECTED SYMBOL:\n"
" 1. symbol_type: Must match one authorized classification from the vocabulary.\n"
" 2. inferred_tag: Associated adjacent tag label (e.g. 26CB9131, 26-KA-902, 26-ST-9002) if legible.\n"
" 3. ymin, xmin, ymax, xmax: Normalized bounding box [0.0 to 1.0] tightly enclosing the symbol icon.\n\n"
"Return the full symbol inventory in structured JSON format conforming to RawSymbolList."
) )
try: try:
@@ -931,17 +950,23 @@ class PipelineRecognitionAgent(BaseAgent):
# Option B: Full Multimodal VLM Polyline Tracer or Hybrid CV + VLM # Option B: Full Multimodal VLM Polyline Tracer or Hybrid CV + VLM
elif not (local_mode or pipeline_engine == "proximity_tracer"): elif not (local_mode or pipeline_engine == "proximity_tracer"):
prompt = ( prompt = (
f"You are an expert topological pipeline and electrical connectivity tracer analyzing a {dt_label} drawing.\n\n" f"You are a principal process piping and electrical systems engineer analyzing topological connectivity on a {dt_label} drawing.\n\n"
"TASK 1 — TOPOLOGICAL RELATIONSHIPS:\n" "TASK 1 — TOPOLOGICAL CONNECTIVITY & STREAM GRAPH GENERATION:\n"
"Extract source→target connectivity pairs:\n" "Extract exact [source_tag] -> [target_tag] relationships adhering to physical flow directionality:\n"
" - MONITORS: Instrument or sensor monitoring a line or equipment.\n" " - INSTALLED_ON: In-line valves, check valves, control valves, strainers, or PSVs installed along a specific piping line.\n"
" - INSTALLED_ON: Valve or fitting installed on a line run.\n" " (Example: '26CB9131' INSTALLED_ON '8\"-PV-26-9035-FC11S-08', 'PSV-9027A' INSTALLED_ON '10\"-VF-43-9027-AS20S-00').\n"
" - CONNECTS_TO: Pipe, busbar, or cable connecting two pieces of equipment.\n" " *CRITICAL*: PSVs are installed on host process piping lines, NEVER arbitrarily mapped to distant vessels or coalescers.\n"
" - FEEDS: Distribution panel or switchboard feeding a circuit or breaker.\n" " - RELIEVES_TO: PSV discharge routing to flare or atmospheric relief headers (e.g. 'PSV-9027A' RELIEVES_TO 'HP Flare Header').\n"
" - EARTHED_TO: Equipment grounded to an earth bar or earth pit.\n\n" " - DRAINS_TO: Equipment drains and low-point purges routing to drain headers (e.g. '26-HA-911' DRAINS_TO 'CLOSED DRAIN').\n"
"TASK 2 — GEOMETRY & SHEET GRIDS:\n" " - MONITORS: Instrument sensors tapping into process lines or equipment nozzles (e.g. '26-PIT-9077' MONITORS '8\"-PV-26-9035-FC11S-08').\n"
"List the border grid sector designations (e.g., A1, B5, C9, D10) and trace any named piping runs or cable routes.\n\n" " - CONNECTS_TO: Continuous process piping connecting source equipment nozzles to destination equipment nozzles.\n"
"Return all findings in structured JSON format." " - FEEDS: Power distribution switchgear, MDBs, or panels feeding electrical branch circuits or loads.\n"
" - EARTHED_TO: Equipment or structures connected via bonding tape to earth bars or earth pits.\n\n"
"DIRECTIONALITY CONSTRAINTS:\n"
" - FLARE, HP FLARE, LP FLARE, CLOSED DRAIN, OPEN DRAIN, ATMOSPHERE, VENT, and SUMP are TERMINAL SINKS (must always be targets, never sources feeding process units).\n\n"
"TASK 2 — GEOMETRY & SHEET BORDER GRIDS:\n"
"Identify border grid sector designations (e.g., A1, B5, C9, D10) and trace continuous polyline coordinates for all major process streams.\n\n"
"Return all findings as validated JSON conforming to the RawPipelineList schema."
) )
try: try:
+11 -5
View File
@@ -180,14 +180,20 @@ class ReExtractorAgent(BaseAgent):
logger.warning(f"Local mode: No items found in crop for {target}. Using heuristic fallback.") logger.warning(f"Local mode: No items found in crop for {target}. Using heuristic fallback.")
else: else:
system_instruction = ( system_instruction = (
"You are an engineering scanner focusing on drawing sub-crops. " "You are an expert high-magnification engineering visual inspector. "
"Your job is to read blurry or tiny labels next to symbols that were " "Your objective is to examine zoomed-in sub-crops of dense P&ID or electrical drawings, "
"missed in the full layout scan." "resolving blurry, dense, or fragmented tags and validating missing in-line symbols and valve types."
) )
prompt = ( prompt = (
f"Examine this visual crop. We are missing details for a component suspect of tag '{target}'. " f"Perform high-resolution forensic inspection on this image crop around suspect tag/symbol '{target}'.\n\n"
f"Reason: {reason}. Extract the exact tag name, symbol type, description, and spec info." f"Inspection Trigger: {reason}\n\n"
"TASKS:\n"
"1. Read the complete alphanumeric tag ID without character dropouts (e.g., check for dense valve numbers like 26CB9131 or 26GB9178).\n"
"2. Identify the exact ISA symbol type (Gate Valve, Check Valve, Ball Valve, Control Valve, PSV, Instrument Bubble, Strainer).\n"
"3. Capture associated physical parameters (line size, ANSI rating class 150#/2500#, set pressure bar(g), or electrical rating).\n"
"4. Trace local host line attachment.\n\n"
"Return the extracted items conforming to ReExtractionPayload."
) )
if crop_path and os.path.exists(crop_path): if crop_path and os.path.exists(crop_path):
+10 -4
View File
@@ -87,13 +87,19 @@ class SupervisorAgent(BaseAgent):
Invokes Vision API to identify layout margins and divide the drawing. Invokes Vision API to identify layout margins and divide the drawing.
""" """
system_instruction = ( system_instruction = (
"You are an expert design engineer. Analyze the border grids of the P&ID drawing sheet " "You are a master engineering drawing layout analyst. "
"and segment the drawing layout into structured region cells." "Examine the spatial architecture of this engineering drawing sheet and segment it into "
"discrete functional zones (high-density process canvas, equipment datasheet/table blocks, "
"symbol legend, drawing notes/revisions, and title block)."
) )
prompt = ( prompt = (
"Look at the drawing boundaries. Identify the normalized bounding boxes [ymin, xmin, ymax, xmax] " "Partition the drawing canvas into normalized bounding boxes [ymin, xmin, ymax, xmax] (0.0 to 1.0):\n"
"for the three major grid cells containing high-density equipment/lines, legend region, and title block region." "1. Process Canvas / Main Schematic: The primary central drawing area containing equipment, piping, instruments, and circuits.\n"
"2. Equipment Datasheet / Parameter Blocks: Tabular parameter blocks containing engineering design specs (duty, flow, pressure, temperature, materials).\n"
"3. Legend & General Notes: Area containing symbol definitions, line type legends, and numbered project notes.\n"
"4. Title Block: Bottom-right metadata block with drawing number, client, project title, and revision history.\n\n"
"Return the localized grid coordinate regions conforming to LayoutSegmentation."
) )
try: try: