From f70a09886aeef54b9e8038b2e3837aa496a905da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Sun, 15 Mar 2026 15:05:37 +0100 Subject: [PATCH] feat: expose CAD dimensions (mm) in chat agent tools - search_products now returns dim_x_mm, dim_y_mm, dim_z_mm from cad_files.mesh_attributes->'dimensions_mm' - query_database tool description updated with cad_files schema including mesh_attributes->'dimensions_mm' path - AI can now answer "what's the biggest product?" using real dimensions Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/app/services/chat_service.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/app/services/chat_service.py b/backend/app/services/chat_service.py index 3d7cf2e..3ff842e 100644 --- a/backend/app/services/chat_service.py +++ b/backend/app/services/chat_service.py @@ -219,7 +219,7 @@ TOOLS = [ "type": "function", "function": { "name": "query_database", - "description": "Execute a read-only SQL SELECT query against the database. Key columns: products(id, name, pim_id, category_key, cad_file_id, is_active), orders(id, order_number, status, tenant_id), order_lines(id, order_id, product_id, render_status, material_override, render_overrides). Use :tenant_id parameter for tenant filtering. Category is 'category_key' not 'category'.", + "description": "Execute a read-only SQL SELECT query against the database. Key tables/columns: products(id, name, pim_id, category_key, cad_file_id, is_active, tenant_id), orders(id, order_number, status, tenant_id), order_lines(id, order_id, product_id, render_status, material_override, render_overrides), cad_files(id, mesh_attributes->'dimensions_mm' with {x,y,z} in mm, parsed_objects, processing_status). To get product dimensions: JOIN cad_files cf ON cf.id = p.cad_file_id and use cf.mesh_attributes->'dimensions_mm'. Use :tenant_id parameter for tenant filtering. Category is 'category_key' not 'category'.", "parameters": { "type": "object", "properties": { @@ -327,7 +327,10 @@ async def _tool_search_products(db: AsyncSession, tenant_id: str, query: str = " sql = """ SELECT p.id, p.name, p.pim_id, p.category_key, p.baureihe, p.cad_file_id IS NOT NULL AS has_step, - cf.processing_status + cf.processing_status, + cf.mesh_attributes->'dimensions_mm'->>'x' AS dim_x_mm, + cf.mesh_attributes->'dimensions_mm'->>'y' AS dim_y_mm, + cf.mesh_attributes->'dimensions_mm'->>'z' AS dim_z_mm FROM products p LEFT JOIN cad_files cf ON cf.id = p.cad_file_id WHERE p.tenant_id = :tenant_id