monkeybrain-runtime 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- monkeybrain_runtime-1.0.0.dist-info/METADATA +76 -0
- monkeybrain_runtime-1.0.0.dist-info/RECORD +838 -0
- monkeybrain_runtime-1.0.0.dist-info/WHEEL +5 -0
- monkeybrain_runtime-1.0.0.dist-info/entry_points.txt +3 -0
- monkeybrain_runtime-1.0.0.dist-info/top_level.txt +2 -0
- services/__init__.py +8 -0
- services/agentos/__init__.py +0 -0
- services/agentos/main.py +1 -0
- services/assets/helpers/__init__.py +12 -0
- services/assets/helpers/device.py +59 -0
- services/assets/helpers/equipment.py +179 -0
- services/assets/helpers/instruments.py +72 -0
- services/assets/helpers/machines.py +183 -0
- services/assets/helpers/materials.py +76 -0
- services/assets/helpers/parts.py +116 -0
- services/assets/helpers/plc.py +134 -0
- services/assets/helpers/tags.py +108 -0
- services/assets/helpers/tools.py +101 -0
- services/assets/main.py +75 -0
- services/assets/models/__init__.py +12 -0
- services/assets/models/device.py +79 -0
- services/assets/models/equipment.py +222 -0
- services/assets/models/instruments.py +85 -0
- services/assets/models/machines.py +230 -0
- services/assets/models/material.py +266 -0
- services/assets/models/parts.py +96 -0
- services/assets/models/plc.py +264 -0
- services/assets/models/tags.py +76 -0
- services/assets/models/tools.py +179 -0
- services/assets/routers/__init__.py +12 -0
- services/assets/routers/classes.py +65 -0
- services/assets/routers/device.py +86 -0
- services/assets/routers/equipment.py +145 -0
- services/assets/routers/families.py +61 -0
- services/assets/routers/instruments.py +70 -0
- services/assets/routers/machines.py +136 -0
- services/assets/routers/materials.py +105 -0
- services/assets/routers/parts.py +130 -0
- services/assets/routers/plc.py +94 -0
- services/assets/routers/subclasses.py +68 -0
- services/assets/routers/tags.py +138 -0
- services/assets/routers/tools.py +113 -0
- services/auth/helpers/__init__.py +13 -0
- services/auth/helpers/approval_decisions.py +261 -0
- services/auth/helpers/audit_elasticsearch_sync.py +350 -0
- services/auth/helpers/departments.py +53 -0
- services/auth/helpers/graph_store.py +848 -0
- services/auth/helpers/influx_store.py +280 -0
- services/auth/helpers/me.py +33 -0
- services/auth/helpers/nats_consumer.py +618 -0
- services/auth/helpers/nats_store.py +242 -0
- services/auth/helpers/permissions.py +62 -0
- services/auth/helpers/roles.py +87 -0
- services/auth/helpers/store.py +54 -0
- services/auth/helpers/team_members.py +155 -0
- services/auth/helpers/teams.py +87 -0
- services/auth/helpers/tokens.py +71 -0
- services/auth/helpers/users.py +119 -0
- services/auth/helpers/websocket_broadcast.py +41 -0
- services/auth/main.py +88 -0
- services/auth/models/__init__.py +12 -0
- services/auth/models/departments.py +55 -0
- services/auth/models/login.py +20 -0
- services/auth/models/permissions.py +61 -0
- services/auth/models/roles.py +53 -0
- services/auth/models/session.py +26 -0
- services/auth/models/teamMembers.py +59 -0
- services/auth/models/teams.py +56 -0
- services/auth/models/users.py +77 -0
- services/auth/routers/__init__.py +14 -0
- services/auth/routers/auth.py +3839 -0
- services/auth/routers/departments.py +84 -0
- services/auth/routers/integration_config.py +703 -0
- services/auth/routers/me.py +28 -0
- services/auth/routers/permissions.py +96 -0
- services/auth/routers/roles.py +139 -0
- services/auth/routers/session.py +224 -0
- services/auth/routers/team_members.py +152 -0
- services/auth/routers/teams.py +112 -0
- services/auth/routers/users.py +131 -0
- services/auth/routers/websocket_events.py +247 -0
- services/batch_execution/__init__.py +19 -0
- services/batch_execution/pipeline_triggers/__init__.py +53 -0
- services/batch_execution/pipeline_triggers/pipeline_parameter_adjuster.py +440 -0
- services/batch_execution/pipeline_triggers/pipeline_trigger_engine.py +445 -0
- services/batch_execution/pipeline_triggers/re_evaluation_queue.py +341 -0
- services/batch_execution/pipeline_triggers/test_phase3_implementation.py +553 -0
- services/batch_execution/pipeline_triggers/workflow_reevaluator.py +367 -0
- services/batch_execution/smoke_test_e2e_feedback_loop.py +704 -0
- services/batch_execution/workflow_executor.py +478 -0
- services/changeover/helpers/__init__.py +11 -0
- services/changeover/helpers/changeover.py +87 -0
- services/changeover/helpers/changeover_common.py +55 -0
- services/changeover/helpers/changeover_events.py +66 -0
- services/changeover/helpers/changeover_kpis.py +33 -0
- services/changeover/helpers/changeover_matrix.py +60 -0
- services/changeover/helpers/changeover_procedures.py +164 -0
- services/changeover/helpers/changeover_windows.py +96 -0
- services/changeover/main.py +52 -0
- services/changeover/models/__init__.py +11 -0
- services/changeover/models/changeover.py +73 -0
- services/changeover/models/changeover_events.py +142 -0
- services/changeover/models/changeover_kpis.py +75 -0
- services/changeover/models/changeover_matrix.py +63 -0
- services/changeover/models/changeover_procedures.py +108 -0
- services/changeover/models/changeover_tasks.py +87 -0
- services/changeover/models/changeover_windows.py +72 -0
- services/changeover/routers/__init__.py +9 -0
- services/changeover/routers/changeover_events.py +127 -0
- services/changeover/routers/changeover_kpis.py +80 -0
- services/changeover/routers/changeover_matrix.py +80 -0
- services/changeover/routers/changeover_procedures.py +118 -0
- services/changeover/routers/changeover_windows.py +98 -0
- services/common/__init__.py +2 -0
- services/common/approval_chains.py +648 -0
- services/common/auth.py +56 -0
- services/common/cdc.py +52 -0
- services/common/compat.py +217 -0
- services/common/compliance.py +562 -0
- services/common/config.py +134 -0
- services/common/cors.py +17 -0
- services/common/data_transformation.py +195 -0
- services/common/db.py +577 -0
- services/common/embeddings.py +97 -0
- services/common/event_reducers.py +194 -0
- services/common/event_types.py +51 -0
- services/common/integration_ingestion.py +169 -0
- services/common/logging.py +204 -0
- services/common/models/__init__.py +2 -0
- services/common/models/databricks.py +25 -0
- services/common/models/enums.py +64 -0
- services/common/module_control.py +422 -0
- services/common/mongo_cdc_watcher.py +106 -0
- services/common/n8n_auth.py +22 -0
- services/common/neo4j_mirror.py +1087 -0
- services/common/ontology_registry.py +110 -0
- services/common/reasoning_traces.py +52 -0
- services/common/supply_chain_cdc.py +555 -0
- services/common/tracing.py +159 -0
- services/common/utils.py +30 -0
- services/customers/helpers/__init__.py +8 -0
- services/customers/helpers/customer_details.py +64 -0
- services/customers/helpers/customer_metadata.py +64 -0
- services/customers/helpers/customer_order_metrics.py +67 -0
- services/customers/helpers/customer_payment_data.py +67 -0
- services/customers/main.py +50 -0
- services/customers/models/__init__.py +8 -0
- services/customers/models/customer_details.py +42 -0
- services/customers/models/customer_metadata.py +97 -0
- services/customers/models/customer_order_metrics.py +86 -0
- services/customers/models/customer_payment_data.py +60 -0
- services/customers/routers/__init__.py +8 -0
- services/customers/routers/customer_details.py +88 -0
- services/customers/routers/customer_metadata.py +88 -0
- services/customers/routers/customer_order_metrics.py +88 -0
- services/customers/routers/customer_payment_data.py +88 -0
- services/documents/__init__.py +1 -0
- services/documents/helpers/__init__.py +6 -0
- services/documents/helpers/document_metadata.py +569 -0
- services/documents/helpers/document_workflows.py +215 -0
- services/documents/helpers/report_templates.py +113 -0
- services/documents/main.py +49 -0
- services/documents/models/__init__.py +6 -0
- services/documents/models/document_metadata.py +215 -0
- services/documents/models/document_workflows.py +136 -0
- services/documents/models/report_templates.py +132 -0
- services/documents/routers/__init__.py +6 -0
- services/documents/routers/document_metadata.py +654 -0
- services/documents/routers/document_workflows.py +146 -0
- services/documents/routers/report_templates.py +86 -0
- services/events/helpers/__init__.py +5 -0
- services/events/helpers/events.py +394 -0
- services/events/main.py +40 -0
- services/events/models/__init__.py +5 -0
- services/events/models/events.py +50 -0
- services/events/routers/__init__.py +6 -0
- services/events/routers/count_events.py +109 -0
- services/events/routers/events.py +75 -0
- services/events/seed_events.py +196 -0
- services/facilities/helpers/__init__.py +8 -0
- services/facilities/helpers/lines.py +74 -0
- services/facilities/helpers/locations.py +231 -0
- services/facilities/helpers/plants.py +59 -0
- services/facilities/helpers/stages.py +110 -0
- services/facilities/helpers/workstation.py +213 -0
- services/facilities/main.py +60 -0
- services/facilities/models/__init__.py +10 -0
- services/facilities/models/industrialLine.py +72 -0
- services/facilities/models/industrialPlant.py +164 -0
- services/facilities/models/locations.py +74 -0
- services/facilities/models/stages.py +92 -0
- services/facilities/models/worker.py +73 -0
- services/facilities/models/workstation.py +117 -0
- services/facilities/models/workstation_live_state.py +59 -0
- services/facilities/routers/__init__.py +8 -0
- services/facilities/routers/bays.py +81 -0
- services/facilities/routers/buildings.py +92 -0
- services/facilities/routers/floors.py +81 -0
- services/facilities/routers/lines.py +154 -0
- services/facilities/routers/locations.py +208 -0
- services/facilities/routers/plant.py +203 -0
- services/facilities/routers/rooms.py +81 -0
- services/facilities/routers/stages.py +152 -0
- services/facilities/routers/workstation.py +173 -0
- services/file/backup.py +71 -0
- services/file/main.py +45 -0
- services/file/recieve.py +54 -0
- services/file/send.py +55 -0
- services/file/src/core/config.py +90 -0
- services/file/src/core/keycloak.py +152 -0
- services/file/src/core/logging_config.py +9 -0
- services/file/src/core/security.py +33 -0
- services/file/src/helpers/cad_conversion.py +331 -0
- services/file/src/helpers/helpers.py +825 -0
- services/file/src/routes/cad_conversion.py +26 -0
- services/file/src/routes/files.py +136 -0
- services/file/src/routes/presigned.py +154 -0
- services/file/src/services/websocket.py +293 -0
- services/floor_layout/helpers/__init__.py +8 -0
- services/floor_layout/helpers/bays.py +92 -0
- services/floor_layout/helpers/buildings.py +54 -0
- services/floor_layout/helpers/floors.py +65 -0
- services/floor_layout/helpers/rooms.py +76 -0
- services/floor_layout/main.py +52 -0
- services/floor_layout/models/__init__.py +8 -0
- services/floor_layout/models/bays.py +65 -0
- services/floor_layout/models/buildings.py +52 -0
- services/floor_layout/models/floors.py +45 -0
- services/floor_layout/models/rooms.py +61 -0
- services/floor_layout/routers/__init__.py +9 -0
- services/floor_layout/routers/bays.py +143 -0
- services/floor_layout/routers/buildings.py +116 -0
- services/floor_layout/routers/floors.py +89 -0
- services/floor_layout/routers/locations.py +80 -0
- services/floor_layout/routers/rooms.py +134 -0
- services/inventory/helpers/__init__.py +13 -0
- services/inventory/helpers/cycle_counts.py +124 -0
- services/inventory/helpers/inventory_allocations.py +134 -0
- services/inventory/helpers/inventory_item_counts.py +114 -0
- services/inventory/helpers/inventory_item_quantities.py +114 -0
- services/inventory/helpers/inventory_items.py +103 -0
- services/inventory/helpers/inventory_stage_outputs.py +134 -0
- services/inventory/helpers/inventory_transactions.py +112 -0
- services/inventory/helpers/stock_adjustment_requests.py +101 -0
- services/inventory/helpers/warehouse_cycle_counts.py +133 -0
- services/inventory/helpers/warehouse_locations.py +213 -0
- services/inventory/helpers/warehouse_regulated_records.py +123 -0
- services/inventory/main.py +62 -0
- services/inventory/models/__init__.py +17 -0
- services/inventory/models/cycle_counts.py +99 -0
- services/inventory/models/inventory_allocations.py +121 -0
- services/inventory/models/inventory_common.py +65 -0
- services/inventory/models/inventory_enums.py +21 -0
- services/inventory/models/inventory_item_count.py +65 -0
- services/inventory/models/inventory_item_quantity.py +82 -0
- services/inventory/models/inventory_items.py +168 -0
- services/inventory/models/inventory_responses.py +44 -0
- services/inventory/models/inventory_stage_outputs.py +96 -0
- services/inventory/models/inventory_state.py +15 -0
- services/inventory/models/inventory_transactions.py +80 -0
- services/inventory/models/stock_adjustment_requests.py +109 -0
- services/inventory/models/warehouse_cycle_counts.py +119 -0
- services/inventory/models/warehouse_location_models.py +708 -0
- services/inventory/models/warehouse_regulated_records.py +358 -0
- services/inventory/routers/__init__.py +13 -0
- services/inventory/routers/cycle_counts.py +106 -0
- services/inventory/routers/inventory_allocations.py +125 -0
- services/inventory/routers/inventory_item_counts.py +105 -0
- services/inventory/routers/inventory_item_quantities.py +105 -0
- services/inventory/routers/inventory_items.py +109 -0
- services/inventory/routers/inventory_stage_outputs.py +122 -0
- services/inventory/routers/inventory_transactions.py +96 -0
- services/inventory/routers/stock_adjustment_requests.py +124 -0
- services/inventory/routers/warehouse_cycle_counts.py +124 -0
- services/inventory/routers/warehouse_locations.py +426 -0
- services/inventory/routers/warehouse_regulated_records.py +273 -0
- services/iot/helpers/__init__.py +8 -0
- services/iot/helpers/ble_device.py +87 -0
- services/iot/helpers/mqtt_bridge.py +115 -0
- services/iot/helpers/sensor_readings.py +63 -0
- services/iot/helpers/sensors.py +77 -0
- services/iot/helpers/servers.py +72 -0
- services/iot/helpers/uwb_device.py +95 -0
- services/iot/main.py +53 -0
- services/iot/models/__init__.py +8 -0
- services/iot/models/ble_device.py +118 -0
- services/iot/models/sensors.py +256 -0
- services/iot/models/servers.py +206 -0
- services/iot/models/uwb_device.py +106 -0
- services/iot/routers/__init__.py +8 -0
- services/iot/routers/ble_device.py +110 -0
- services/iot/routers/sensors.py +144 -0
- services/iot/routers/servers.py +141 -0
- services/iot/routers/uwb_device.py +148 -0
- services/module_control/__init__.py +1 -0
- services/module_control/helpers/__init__.py +1 -0
- services/module_control/helpers/integration_config.py +243 -0
- services/module_control/helpers/security.py +104 -0
- services/module_control/main.py +44 -0
- services/module_control/models/__init__.py +1 -0
- services/module_control/models/module_control.py +65 -0
- services/module_control/routers/__init__.py +1 -0
- services/module_control/routers/module_control.py +219 -0
- services/orders/helpers/__init__.py +11 -0
- services/orders/helpers/invoices.py +123 -0
- services/orders/helpers/order_customer_metrics.py +61 -0
- services/orders/helpers/order_details.py +71 -0
- services/orders/helpers/order_metadata.py +61 -0
- services/orders/helpers/order_payment_metadata.py +74 -0
- services/orders/helpers/orders.py +119 -0
- services/orders/helpers/sales_orders.py +136 -0
- services/orders/main.py +56 -0
- services/orders/models/__init__.py +11 -0
- services/orders/models/invoices.py +415 -0
- services/orders/models/order_customer_metrics.py +78 -0
- services/orders/models/order_details.py +46 -0
- services/orders/models/order_metadata.py +60 -0
- services/orders/models/order_payment_metadata.py +63 -0
- services/orders/models/orders.py +64 -0
- services/orders/models/sales_orders.py +130 -0
- services/orders/routers/__init__.py +11 -0
- services/orders/routers/invoices.py +111 -0
- services/orders/routers/order_customer_metrics.py +87 -0
- services/orders/routers/order_details.py +87 -0
- services/orders/routers/order_metadata.py +87 -0
- services/orders/routers/order_payment_metadata.py +87 -0
- services/orders/routers/orders.py +74 -0
- services/orders/routers/sales_orders.py +111 -0
- services/pm/helpers/__init__.py +14 -0
- services/pm/helpers/calendar_bookings.py +114 -0
- services/pm/helpers/calibration_point.py +110 -0
- services/pm/helpers/calibrations.py +196 -0
- services/pm/helpers/checklists.py +318 -0
- services/pm/helpers/cleaning.py +333 -0
- services/pm/helpers/downtime.py +376 -0
- services/pm/helpers/kanban_boards.py +186 -0
- services/pm/helpers/maintainance.py +177 -0
- services/pm/helpers/sop.py +1155 -0
- services/pm/helpers/sop_cdc.py +324 -0
- services/pm/helpers/weekly_schedules.py +79 -0
- services/pm/main.py +62 -0
- services/pm/models/__init__.py +14 -0
- services/pm/models/calendar_booking.py +82 -0
- services/pm/models/calibration_point.py +44 -0
- services/pm/models/calibrations.py +167 -0
- services/pm/models/checklists.py +117 -0
- services/pm/models/cleaning.py +203 -0
- services/pm/models/downtime.py +109 -0
- services/pm/models/kanban_board.py +178 -0
- services/pm/models/maintainanceLog.py +148 -0
- services/pm/models/sop.py +152 -0
- services/pm/models/weekly_schedule.py +91 -0
- services/pm/routers/__init__.py +14 -0
- services/pm/routers/calendar_bookings.py +143 -0
- services/pm/routers/calibration_point.py +94 -0
- services/pm/routers/calibrations.py +232 -0
- services/pm/routers/checklists.py +188 -0
- services/pm/routers/cleaning.py +127 -0
- services/pm/routers/downtime.py +143 -0
- services/pm/routers/kanban_boards.py +283 -0
- services/pm/routers/maintainance.py +241 -0
- services/pm/routers/sop.py +437 -0
- services/pm/routers/weekly_schedules.py +108 -0
- services/process_definitions/helpers/__init__.py +11 -0
- services/process_definitions/helpers/cpp_cqa_registry.py +120 -0
- services/process_definitions/helpers/mbmr_templates.py +107 -0
- services/process_definitions/helpers/packing_instructions.py +113 -0
- services/process_definitions/helpers/process_constraints.py +495 -0
- services/process_definitions/helpers/process_corrections.py +279 -0
- services/process_definitions/helpers/process_definition.py +996 -0
- services/process_definitions/helpers/process_node_catalog.py +786 -0
- services/process_definitions/helpers/process_post_checks.py +441 -0
- services/process_definitions/helpers/process_pre_checks.py +351 -0
- services/process_definitions/helpers/process_steps.py +220 -0
- services/process_definitions/main.py +71 -0
- services/process_definitions/models/__init__.py +13 -0
- services/process_definitions/models/cpp_cqa_registry.py +145 -0
- services/process_definitions/models/gxp_change_controls.py +38 -0
- services/process_definitions/models/gxp_risk_assessments.py +30 -0
- services/process_definitions/models/gxp_validation_evidence.py +33 -0
- services/process_definitions/models/mbmr_templates.py +173 -0
- services/process_definitions/models/packing_instructions.py +176 -0
- services/process_definitions/models/process_constraints.py +159 -0
- services/process_definitions/models/process_corrections.py +118 -0
- services/process_definitions/models/process_definition.py +685 -0
- services/process_definitions/models/process_definition_common.py +48 -0
- services/process_definitions/models/process_node_catalog.py +25 -0
- services/process_definitions/models/process_post_checks.py +171 -0
- services/process_definitions/models/process_pre_checks.py +168 -0
- services/process_definitions/models/process_steps.py +170 -0
- services/process_definitions/node_services/__init__.py +8 -0
- services/process_definitions/node_services/common.py +95 -0
- services/process_definitions/node_services/executor.py +499 -0
- services/process_definitions/node_services/flow_simulator.py +733 -0
- services/process_definitions/node_services/functions.py +193 -0
- services/process_definitions/node_services/messaging.py +44 -0
- services/process_definitions/node_services/models.py +221 -0
- services/process_definitions/node_services/network.py +161 -0
- services/process_definitions/node_services/parsers.py +87 -0
- services/process_definitions/node_services/sequence.py +95 -0
- services/process_definitions/node_services/storage.py +50 -0
- services/process_definitions/node_services/webhooks.py +52 -0
- services/process_definitions/routers/__init__.py +10 -0
- services/process_definitions/routers/cpp_cqa_registry.py +86 -0
- services/process_definitions/routers/mbmr_templates.py +84 -0
- services/process_definitions/routers/packing_instructions.py +84 -0
- services/process_definitions/routers/process_constraints.py +564 -0
- services/process_definitions/routers/process_corrections.py +343 -0
- services/process_definitions/routers/process_definition.py +992 -0
- services/process_definitions/routers/process_post_checks.py +529 -0
- services/process_definitions/routers/process_pre_checks.py +435 -0
- services/process_definitions/routers/process_steps.py +274 -0
- services/procurement/helpers/__init__.py +9 -0
- services/procurement/helpers/goods_receipts.py +240 -0
- services/procurement/helpers/purchase_order_shipping_information.py +85 -0
- services/procurement/helpers/purchase_orders.py +68 -0
- services/procurement/helpers/quality_control.py +235 -0
- services/procurement/helpers/sampling.py +404 -0
- services/procurement/main.py +52 -0
- services/procurement/models/__init__.py +9 -0
- services/procurement/models/goods_receipts.py +165 -0
- services/procurement/models/purchase_orders.py +54 -0
- services/procurement/models/quality_control.py +464 -0
- services/procurement/models/reinspection_records.py +28 -0
- services/procurement/models/sampling.py +262 -0
- services/procurement/models/shipping_information.py +51 -0
- services/procurement/routers/__init__.py +9 -0
- services/procurement/routers/goods_receipts.py +201 -0
- services/procurement/routers/purchase_orders.py +106 -0
- services/procurement/routers/quality_control.py +386 -0
- services/procurement/routers/sampling.py +296 -0
- services/procurement/routers/shipping_information.py +97 -0
- services/production/__init__.py +1 -0
- services/production/agents/__init__.py +5 -0
- services/production/agents/batch_planning_agent.py +815 -0
- services/production/models/__init__.py +25 -0
- services/production/models/batch.py +253 -0
- services/products/helpers/__init__.py +10 -0
- services/products/helpers/boms.py +100 -0
- services/products/helpers/drug_research.py +644 -0
- services/products/helpers/product_component.py +168 -0
- services/products/helpers/product_inventory.py +221 -0
- services/products/helpers/product_pricing.py +123 -0
- services/products/helpers/product_utils.py +32 -0
- services/products/helpers/products.py +81 -0
- services/products/main.py +59 -0
- services/products/models/__init__.py +9 -0
- services/products/models/drug_research.py +138 -0
- services/products/models/product_common.py +60 -0
- services/products/models/product_component.py +1028 -0
- services/products/models/product_inventory.py +118 -0
- services/products/models/product_pricing.py +73 -0
- services/products/models/products.py +151 -0
- services/products/routers/__init__.py +9 -0
- services/products/routers/boms.py +116 -0
- services/products/routers/drug_research.py +115 -0
- services/products/routers/product_components.py +123 -0
- services/products/routers/product_inventory.py +185 -0
- services/products/routers/product_pricing.py +136 -0
- services/products/routers/products.py +165 -0
- services/replenishment/__init__.py +1 -0
- services/replenishment/main.py +46 -0
- services/replenishment/routers/__init__.py +1 -0
- services/replenishment/routers/replenishment.py +20 -0
- services/shifts/helpers/__init__.py +7 -0
- services/shifts/helpers/shift_templates.py +124 -0
- services/shifts/helpers/shifts.py +79 -0
- services/shifts/helpers/timesheets.py +137 -0
- services/shifts/main.py +48 -0
- services/shifts/models/__init__.py +8 -0
- services/shifts/models/shift.py +62 -0
- services/shifts/models/shift_template.py +82 -0
- services/shifts/models/time_range.py +31 -0
- services/shifts/models/timesheet.py +196 -0
- services/shifts/routers/__init__.py +7 -0
- services/shifts/routers/shift_templates.py +97 -0
- services/shifts/routers/shifts.py +117 -0
- services/shifts/routers/timesheets.py +117 -0
- services/shipping/helpers/__init__.py +15 -0
- services/shipping/helpers/carrier.py +78 -0
- services/shipping/helpers/customs_declaration.py +104 -0
- services/shipping/helpers/delivery_note.py +99 -0
- services/shipping/helpers/package.py +95 -0
- services/shipping/helpers/pallet.py +85 -0
- services/shipping/helpers/route.py +93 -0
- services/shipping/helpers/shipping_information.py +82 -0
- services/shipping/helpers/shipping_provider_details.py +59 -0
- services/shipping/helpers/shipping_provider_metadata.py +59 -0
- services/shipping/helpers/vehicle.py +85 -0
- services/shipping/helpers/waybill.py +86 -0
- services/shipping/main.py +64 -0
- services/shipping/models/__init__.py +15 -0
- services/shipping/models/carrier.py +97 -0
- services/shipping/models/customs_declaration.py +138 -0
- services/shipping/models/delivery_note.py +163 -0
- services/shipping/models/package.py +152 -0
- services/shipping/models/pallet.py +137 -0
- services/shipping/models/route.py +120 -0
- services/shipping/models/shipping_information.py +55 -0
- services/shipping/models/shipping_provider_details.py +42 -0
- services/shipping/models/shipping_provider_metadata.py +54 -0
- services/shipping/models/vehicle.py +129 -0
- services/shipping/models/waybill.py +189 -0
- services/shipping/routers/__init__.py +15 -0
- services/shipping/routers/carrier.py +99 -0
- services/shipping/routers/customs_declaration.py +132 -0
- services/shipping/routers/delivery_note.py +150 -0
- services/shipping/routers/package.py +141 -0
- services/shipping/routers/pallet.py +108 -0
- services/shipping/routers/route.py +128 -0
- services/shipping/routers/shipping_information.py +97 -0
- services/shipping/routers/shipping_provider_details.py +80 -0
- services/shipping/routers/shipping_provider_metadata.py +80 -0
- services/shipping/routers/vehicle.py +117 -0
- services/shipping/routers/waybill.py +119 -0
- services/suppliers/helpers/__init__.py +13 -0
- services/suppliers/helpers/supplier_capabilities.py +58 -0
- services/suppliers/helpers/supplier_certifications.py +67 -0
- services/suppliers/helpers/supplier_details.py +58 -0
- services/suppliers/helpers/supplier_financials.py +58 -0
- services/suppliers/helpers/supplier_inventory.py +74 -0
- services/suppliers/helpers/supplier_locations.py +60 -0
- services/suppliers/helpers/supplier_pricing.py +69 -0
- services/suppliers/helpers/supplier_quality.py +69 -0
- services/suppliers/helpers/supplier_shipping.py +69 -0
- services/suppliers/main.py +60 -0
- services/suppliers/models/__init__.py +13 -0
- services/suppliers/models/supplier_capabilities.py +70 -0
- services/suppliers/models/supplier_certifications.py +64 -0
- services/suppliers/models/supplier_details.py +75 -0
- services/suppliers/models/supplier_financials.py +69 -0
- services/suppliers/models/supplier_inventory.py +76 -0
- services/suppliers/models/supplier_locations.py +70 -0
- services/suppliers/models/supplier_pricing.py +74 -0
- services/suppliers/models/supplier_quality.py +74 -0
- services/suppliers/models/supplier_shipping.py +76 -0
- services/suppliers/routers/__init__.py +13 -0
- services/suppliers/routers/supplier_capabilities.py +88 -0
- services/suppliers/routers/supplier_certifications.py +87 -0
- services/suppliers/routers/supplier_details.py +83 -0
- services/suppliers/routers/supplier_financials.py +83 -0
- services/suppliers/routers/supplier_inventory.py +105 -0
- services/suppliers/routers/supplier_locations.py +89 -0
- services/suppliers/routers/supplier_pricing.py +96 -0
- services/suppliers/routers/supplier_quality.py +96 -0
- services/suppliers/routers/supplier_shipping.py +96 -0
- services/supply_allocation/main.py +46 -0
- services/supply_allocation/routers/__init__.py +1 -0
- services/supply_allocation/routers/allocation.py +20 -0
- services/taxonomy/helpers/__init__.py +7 -0
- services/taxonomy/helpers/classes.py +48 -0
- services/taxonomy/helpers/family.py +53 -0
- services/taxonomy/helpers/subclass.py +58 -0
- services/taxonomy/main.py +48 -0
- services/taxonomy/models/__init__.py +7 -0
- services/taxonomy/models/classes.py +52 -0
- services/taxonomy/models/family.py +60 -0
- services/taxonomy/models/subclass.py +50 -0
- services/taxonomy/routers/__init__.py +7 -0
- services/taxonomy/routers/classes.py +78 -0
- services/taxonomy/routers/family.py +77 -0
- services/taxonomy/routers/subclass.py +82 -0
- services/warehouse_execution/__init__.py +1 -0
- services/warehouse_execution/main.py +46 -0
- services/warehouse_execution/routers/__init__.py +1 -0
- services/warehouse_execution/routers/execution.py +21 -0
- services/work_order_agent/__init__.py +17 -0
- services/work_order_agent/agent/__init__.py +17 -0
- services/work_order_agent/agent/work_order_agent.py +658 -0
- services/work_order_agent/tracking/__init__.py +101 -0
- services/work_order_agent/tracking/event_system.py +182 -0
- services/work_order_agent/tracking/state_machine.py +163 -0
- services/work_order_agent/tracking/state_machine_integrator.py +295 -0
- services/work_order_agent/tracking/test_phase2_implementation.py +302 -0
- services/work_order_agent/tracking/time_analysis.py +301 -0
- services/work_order_agent/tracking/tracked_work_order.py +255 -0
- services/work_order_agent/tracking/work_order_adapter.py +367 -0
- services/work_order_agent/tracking/work_order_batch_manager.py +406 -0
- services/work_order_agent/tracking/work_order_repository.py +431 -0
- services/workorders/helpers/__init__.py +5 -0
- services/workorders/helpers/area_room_usage_ledger.py +139 -0
- services/workorders/helpers/batch_execution_records.py +265 -0
- services/workorders/helpers/batch_release_workflows.py +158 -0
- services/workorders/helpers/batch_step_executions.py +145 -0
- services/workorders/helpers/equipment_usage_ledger.py +209 -0
- services/workorders/helpers/executed_bmr_records.py +170 -0
- services/workorders/helpers/executed_bpr_records.py +170 -0
- services/workorders/helpers/executed_instruction_evidence.py +155 -0
- services/workorders/helpers/ipc_result_records.py +134 -0
- services/workorders/helpers/production_batches.py +117 -0
- services/workorders/helpers/work_orders.py +367 -0
- services/workorders/helpers/yield_reconciliation_records.py +158 -0
- services/workorders/main.py +110 -0
- services/workorders/models/__init__.py +5 -0
- services/workorders/models/area_room_usage_ledger.py +154 -0
- services/workorders/models/batch_execution_records.py +575 -0
- services/workorders/models/batch_release_workflows.py +190 -0
- services/workorders/models/batch_step_executions.py +142 -0
- services/workorders/models/equipment_usage_ledger.py +144 -0
- services/workorders/models/executed_bmr_records.py +220 -0
- services/workorders/models/executed_bpr_records.py +220 -0
- services/workorders/models/executed_instruction_evidence.py +128 -0
- services/workorders/models/ipc_result_records.py +164 -0
- services/workorders/models/production_batches.py +181 -0
- services/workorders/models/work_orders.py +255 -0
- services/workorders/models/yield_reconciliation_records.py +175 -0
- services/workorders/routers/__init__.py +5 -0
- services/workorders/routers/area_room_usage_ledger.py +117 -0
- services/workorders/routers/batch_execution_records.py +103 -0
- services/workorders/routers/batch_release_workflows.py +86 -0
- services/workorders/routers/batch_step_executions.py +88 -0
- services/workorders/routers/equipment_usage_ledger.py +115 -0
- services/workorders/routers/executed_bmr_records.py +86 -0
- services/workorders/routers/executed_bpr_records.py +86 -0
- services/workorders/routers/executed_instruction_evidence.py +86 -0
- services/workorders/routers/ipc_result_records.py +86 -0
- services/workorders/routers/production_batches.py +86 -0
- services/workorders/routers/work_orders.py +257 -0
- services/workorders/routers/yield_reconciliation_records.py +86 -0
- src/broca/__init__.py +5 -0
- src/broca/agent.py +201 -0
- src/cerebellum/__init__.py +0 -0
- src/cerebellum/adapter.py +84 -0
- src/cerebellum/capabilities/__init__.py +0 -0
- src/cerebellum/capabilities/agent/__init__.py +0 -0
- src/cerebellum/capabilities/agent/agents.py +65 -0
- src/cerebellum/capabilities/ai/__init__.py +0 -0
- src/cerebellum/capabilities/ai/providers.py +106 -0
- src/cerebellum/capabilities/api/__init__.py +0 -0
- src/cerebellum/capabilities/api/graphql.py +35 -0
- src/cerebellum/capabilities/api/rest_api.py +45 -0
- src/cerebellum/capabilities/api/webhook.py +30 -0
- src/cerebellum/capabilities/browser/__init__.py +0 -0
- src/cerebellum/capabilities/browser/browsers.py +27 -0
- src/cerebellum/capabilities/cloud/__init__.py +0 -0
- src/cerebellum/capabilities/cloud/cloud.py +46 -0
- src/cerebellum/capabilities/communication/__init__.py +0 -0
- src/cerebellum/capabilities/communication/communication.py +62 -0
- src/cerebellum/capabilities/database/__init__.py +0 -0
- src/cerebellum/capabilities/database/elasticsearch.py +40 -0
- src/cerebellum/capabilities/database/influxdb.py +37 -0
- src/cerebellum/capabilities/database/mongodb.py +50 -0
- src/cerebellum/capabilities/database/neo4j.py +32 -0
- src/cerebellum/capabilities/database/redis.py +44 -0
- src/cerebellum/capabilities/enterprise/__init__.py +0 -0
- src/cerebellum/capabilities/enterprise/opensource.py +180 -0
- src/cerebellum/capabilities/enterprise/proprietary.py +313 -0
- src/cerebellum/capabilities/event_streaming/__init__.py +0 -0
- src/cerebellum/capabilities/event_streaming/streaming.py +38 -0
- src/cerebellum/capabilities/infrastructure/__init__.py +0 -0
- src/cerebellum/capabilities/infrastructure/infrastructure.py +30 -0
- src/cerebellum/capabilities/productivity/__init__.py +0 -0
- src/cerebellum/capabilities/productivity/productivity.py +158 -0
- src/cerebellum/capabilities/robotics/__init__.py +0 -0
- src/cerebellum/capabilities/robotics/robotics.py +124 -0
- src/cerebellum/capabilities/runtime/__init__.py +0 -0
- src/cerebellum/capabilities/runtime/runtimes.py +92 -0
- src/cerebellum/capabilities/search/__init__.py +0 -0
- src/cerebellum/capabilities/search/search.py +63 -0
- src/cerebellum/capabilities/source_control/__init__.py +0 -0
- src/cerebellum/capabilities/source_control/source_control.py +113 -0
- src/cerebellum/capabilities/storage/__init__.py +0 -0
- src/cerebellum/capabilities/storage/storage.py +94 -0
- src/cerebellum/capabilities/workflow/__init__.py +0 -0
- src/cerebellum/capabilities/workflow/workflows.py +49 -0
- src/cerebellum/capability.py +108 -0
- src/cerebellum/config.py +157 -0
- src/cerebellum/fallback.py +147 -0
- src/cerebellum/fallback_engine.py +121 -0
- src/cerebellum/key_manager.py +129 -0
- src/cerebellum/keystore.py +179 -0
- src/cerebellum/lifecycle.py +54 -0
- src/cerebellum/metadata.py +61 -0
- src/cerebellum/operator/base.py +25 -0
- src/cerebellum/peripheral.py +92 -0
- src/cerebellum/registry.py +98 -0
- src/cerebellum/resolve_entity_capability.py +259 -0
- src/cingulate/benchmark/__init__.py +23 -0
- src/cingulate/benchmark/reporter.py +102 -0
- src/cingulate/benchmark/runner.py +159 -0
- src/cingulate/benchmark/scenario_runner.py +150 -0
- src/cingulate/benchmark/validator.py +102 -0
- src/cingulate/governance/__init__.py +21 -0
- src/cingulate/governance/architecture_validator.py +194 -0
- src/cingulate/governance/compliance.py +104 -0
- src/cingulate/governance/governance.py +77 -0
- src/cingulate/governance/policy_registry.py +91 -0
- src/cortex/__init__.py +33 -0
- src/cortex/cost.py +71 -0
- src/cortex/counterfactual.py +162 -0
- src/cortex/digital_twin.py +90 -0
- src/cortex/experience.py +83 -0
- src/cortex/feedback.py +144 -0
- src/cortex/loss.py +116 -0
- src/cortex/prediction.py +142 -0
- src/cortex/replay.py +130 -0
- src/cortex/reward.py +113 -0
- src/cortex/simulator.py +102 -0
- src/cortex/world_model.py +180 -0
- src/cortex/world_model_simulation.py +1591 -0
- src/cortex/world_state.py +121 -0
- src/cortex/xavier.py +250 -0
- src/deepdive/__init__.py +29 -0
- src/deepdive/aggregation.py +113 -0
- src/deepdive/digital_twin_aggregator.py +128 -0
- src/deepdive/elasticsearch_adapter.py +110 -0
- src/deepdive/fleet_analytics.py +131 -0
- src/deepdive/knowledge_aggregator.py +130 -0
- src/homeostasis/__init__.py +19 -0
- src/homeostasis/control_plane.py +159 -0
- src/introspection/__init__.py +38 -0
- src/introspection/alerting.py +142 -0
- src/introspection/health.py +101 -0
- src/introspection/lemon.py +243 -0
- src/introspection/logging.py +147 -0
- src/introspection/metrics.py +106 -0
- src/introspection/tracing.py +162 -0
- src/monkey_brain/__init__.py +1 -0
- src/monkey_brain/api/main.py +148 -0
- src/monkey_brain/api/models.py +81 -0
- src/monkey_brain/api/routes/routes/keys.py +106 -0
- src/monkey_brain/api/routes/routes/run.py +169 -0
- src/monkey_brain/api/routes/routes/simulate.py +485 -0
- src/monkey_brain/dlm/__init__.py +44 -0
- src/monkey_brain/dlm/dlm.py +139 -0
- src/monkey_brain/dlm/gc.py +115 -0
- src/monkey_brain/dlm/lifecycle.py +149 -0
- src/monkey_brain/dlm/orphans.py +99 -0
- src/monkey_brain/dlm/storage.py +149 -0
- src/monkey_brain/dlm/ttl.py +140 -0
- src/monkey_brain/documents/__init__.py +0 -0
- src/monkey_brain/documents/document_ocr.py +6 -0
- src/monkey_brain/kernel/__init__.py +53 -0
- src/monkey_brain/kernel/capability_interface.py +144 -0
- src/monkey_brain/kernel/classifier/__init__.py +1 -0
- src/monkey_brain/kernel/classifier/embed_classifier.py +125 -0
- src/monkey_brain/kernel/classifier/intent_examples.py +106 -0
- src/monkey_brain/kernel/dag.py +23 -0
- src/monkey_brain/kernel/execution_state.py +257 -0
- src/monkey_brain/kernel/goal_planner.py +85 -0
- src/monkey_brain/kernel/goal_router.py +20 -0
- src/monkey_brain/kernel/goals/__init__.py +1 -0
- src/monkey_brain/kernel/goals/goal.py +130 -0
- src/monkey_brain/kernel/goals/goal_bootstrap.py +38 -0
- src/monkey_brain/kernel/goals/goal_classifier.py +132 -0
- src/monkey_brain/kernel/goals/goal_registry.py +75 -0
- src/monkey_brain/kernel/intents/__init__.py +1 -0
- src/monkey_brain/kernel/intents/event_adapter.py +246 -0
- src/monkey_brain/kernel/intents/helpers.py +13 -0
- src/monkey_brain/kernel/intents/intent_registry.py +705 -0
- src/monkey_brain/kernel/intents/intent_router.py +102 -0
- src/monkey_brain/kernel/intents/predicates/approval_create.py +9 -0
- src/monkey_brain/kernel/intents/predicates/approval_decision.py +9 -0
- src/monkey_brain/kernel/intents/predicates/approval_hold.py +9 -0
- src/monkey_brain/kernel/intents/predicates/approval_query.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_close.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_creation.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_delete.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_hold.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_record.py +9 -0
- src/monkey_brain/kernel/intents/predicates/batch_update.py +9 -0
- src/monkey_brain/kernel/intents/predicates/change_control.py +49 -0
- src/monkey_brain/kernel/intents/predicates/compliance_audit.py +14 -0
- src/monkey_brain/kernel/intents/predicates/decision_intelligence.py +9 -0
- src/monkey_brain/kernel/intents/predicates/drug_research.py +9 -0
- src/monkey_brain/kernel/intents/predicates/fuzzy_match.py +19 -0
- src/monkey_brain/kernel/intents/predicates/production_kpi.py +9 -0
- src/monkey_brain/kernel/intents/predicates/sop_create.py +9 -0
- src/monkey_brain/kernel/intents/predicates/sop_query.py +9 -0
- src/monkey_brain/kernel/intents/predicates/sop_update.py +9 -0
- src/monkey_brain/kernel/intents/predicates/warehouse_shipping.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_create.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_delete.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_hold.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_query.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_status.py +9 -0
- src/monkey_brain/kernel/intents/predicates/work_order_update.py +9 -0
- src/monkey_brain/kernel/intents/predicates/worker.py +9 -0
- src/monkey_brain/kernel/intents/telemetry_adapter.py +274 -0
- src/monkey_brain/kernel/intents/utils.py +68 -0
- src/monkey_brain/kernel/learning.py +98 -0
- src/monkey_brain/kernel/llm_explorer.py +188 -0
- src/monkey_brain/kernel/loss.py +81 -0
- src/monkey_brain/kernel/nlp/__init__.py +1 -0
- src/monkey_brain/kernel/nlp/compat.py +23 -0
- src/monkey_brain/kernel/nlp/models.py +10 -0
- src/monkey_brain/kernel/nlp/question_analyzer.py +203 -0
- src/monkey_brain/kernel/nlp/spacy_parser.py +53 -0
- src/monkey_brain/kernel/observer.py +97 -0
- src/monkey_brain/kernel/parser/__init__.py +3 -0
- src/monkey_brain/kernel/parser/ast.py +28 -0
- src/monkey_brain/kernel/parser/extractors/__init__.py +11 -0
- src/monkey_brain/kernel/parser/extractors/entities.py +21 -0
- src/monkey_brain/kernel/parser/extractors/filters.py +16 -0
- src/monkey_brain/kernel/parser/extractors/projections.py +36 -0
- src/monkey_brain/kernel/parser/extractors/verbs.py +31 -0
- src/monkey_brain/kernel/parser/parser.py +57 -0
- src/monkey_brain/kernel/parser/rules.py +75 -0
- src/monkey_brain/kernel/pipeline.py +44 -0
- src/monkey_brain/kernel/planner.py +57 -0
- src/monkey_brain/kernel/rl/__init__.py +33 -0
- src/monkey_brain/kernel/rl/learner.py +98 -0
- src/monkey_brain/kernel/rl/policy.py +254 -0
- src/monkey_brain/kernel/rl/reward.py +117 -0
- src/monkey_brain/kernel/rl/transition.py +112 -0
- src/monkey_brain/persistence/__init__.py +47 -0
- src/monkey_brain/persistence/adapters.py +49 -0
- src/monkey_brain/persistence/events.py +105 -0
- src/monkey_brain/persistence/manager.py +124 -0
- src/monkey_brain/persistence/mongodb_adapter.py +91 -0
- src/monkey_brain/persistence/redis_adapter.py +93 -0
- src/monkey_brain/persistence/reducer.py +111 -0
- src/monkey_brain/runtime/__init__.py +49 -0
- src/monkey_brain/runtime/depedencies.py +8 -0
- src/monkey_brain/runtime/engine.py +183 -0
- src/monkey_brain/runtime/message_bus.py +82 -0
- src/monkey_brain/runtime/process.py +144 -0
- src/monkey_brain/runtime/resource_manager.py +100 -0
- src/monkey_brain/runtime/routers.py +8 -0
- src/monkey_brain/runtime/runtime.py +199 -0
- src/monkey_brain/runtime/scheduler.py +165 -0
- src/monkey_brain/runtime/supervisor.py +133 -0
- src/monkey_brain/runtime/worker_pool.py +111 -0
- src/plasticity/seed/__init__.py +30 -0
- src/plasticity/seed/benchmark_generator.py +105 -0
- src/plasticity/seed/event_generator.py +122 -0
- src/plasticity/seed/scenario_builder.py +134 -0
- src/plasticity/seed/seed_data.py +206 -0
- src/plasticity/seed/seeder.py +122 -0
- src/plasticity/testing/__init__.py +28 -0
- src/plasticity/testing/performance.py +131 -0
- src/plasticity/testing/profiler.py +255 -0
- src/plasticity/testing/reporter.py +84 -0
- src/plasticity/testing/runner.py +209 -0
- src/sync/__init__.py +12 -0
- src/sync/cloud_aggregator.py +63 -0
- src/sync/edge_node.py +51 -0
- src/sync/sync_manager.py +74 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Query route — HTTP interface to the Cognitive Kernel.
|
|
2
|
+
|
|
3
|
+
This is a thin HTTP adapter. It parses requests, invokes the kernel,
|
|
4
|
+
and formats responses. No execution policy lives here.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import time as _time
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from fastapi import APIRouter, Depends, Request
|
|
14
|
+
|
|
15
|
+
from src.monkey_brain.kernel.classifier.embed_classifier import classify_intent
|
|
16
|
+
from src.monkey_brain.kernel.intents.intent_router import execute_intent, unsupported_intent_answer
|
|
17
|
+
from src.monkey_brain.runtime.depedencies import get_runtime
|
|
18
|
+
from src.monkey_brain.runtime.routers import get_mongo_client
|
|
19
|
+
|
|
20
|
+
import logging
|
|
21
|
+
_rlog = logging.getLogger("agentos.run").info
|
|
22
|
+
|
|
23
|
+
router = APIRouter()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ProfileEntry:
|
|
27
|
+
def __init__(self, phase: str, model: str = "", prompt_tokens: int = 0, completion_tokens: int = 0, ms: int = 0):
|
|
28
|
+
self.phase = phase
|
|
29
|
+
self.model = model
|
|
30
|
+
self.prompt_tokens = prompt_tokens
|
|
31
|
+
self.completion_tokens = completion_tokens
|
|
32
|
+
self.ms = ms
|
|
33
|
+
|
|
34
|
+
def to_dict(self) -> dict:
|
|
35
|
+
d = {"phase": self.phase, "ms": self.ms}
|
|
36
|
+
if self.model:
|
|
37
|
+
d["model"] = self.model
|
|
38
|
+
if self.prompt_tokens:
|
|
39
|
+
d["prompt_tokens"] = self.prompt_tokens
|
|
40
|
+
if self.completion_tokens:
|
|
41
|
+
d["completion_tokens"] = self.completion_tokens
|
|
42
|
+
return d
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
_profile_stack: list[list[ProfileEntry]] = []
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _profile_start() -> list[ProfileEntry]:
|
|
49
|
+
entries: list[ProfileEntry] = []
|
|
50
|
+
_profile_stack.append(entries)
|
|
51
|
+
return entries
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _profile_end() -> list[ProfileEntry]:
|
|
55
|
+
return _profile_stack.pop() if _profile_stack else []
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _profile_add(entry: ProfileEntry):
|
|
59
|
+
if _profile_stack:
|
|
60
|
+
_profile_stack[-1].append(entry)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
async def _llm_call(system: str, user: str, model: str = "") -> str | None:
|
|
64
|
+
"""Call LLM via OpenRouter first, fall back to Ollama."""
|
|
65
|
+
import os
|
|
66
|
+
import httpx
|
|
67
|
+
|
|
68
|
+
_t0 = _time.monotonic()
|
|
69
|
+
api_key = os.getenv("OPENROUTER_API_KEY", "")
|
|
70
|
+
if api_key:
|
|
71
|
+
try:
|
|
72
|
+
async with httpx.AsyncClient(timeout=60.0) as client:
|
|
73
|
+
response = await client.post(
|
|
74
|
+
"https://openrouter.ai/api/v1/chat/completions",
|
|
75
|
+
headers={
|
|
76
|
+
"Authorization": f"Bearer {api_key}",
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
},
|
|
79
|
+
json={
|
|
80
|
+
"model": model or os.getenv("OPENROUTER_MODEL", "openai/gpt-4o-mini"),
|
|
81
|
+
"messages": [
|
|
82
|
+
{"role": "system", "content": system},
|
|
83
|
+
{"role": "user", "content": user},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
)
|
|
87
|
+
if 200 <= response.status_code < 300:
|
|
88
|
+
data = response.json()
|
|
89
|
+
return data["choices"][0]["message"]["content"]
|
|
90
|
+
except Exception:
|
|
91
|
+
pass
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
import ollama
|
|
95
|
+
response = ollama.chat(
|
|
96
|
+
model="gemma3:latest",
|
|
97
|
+
messages=[
|
|
98
|
+
{"role": "system", "content": system},
|
|
99
|
+
{"role": "user", "content": user},
|
|
100
|
+
],
|
|
101
|
+
)
|
|
102
|
+
return response["message"]["content"]
|
|
103
|
+
except Exception:
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@router.post("/query")
|
|
108
|
+
async def query_agentos(
|
|
109
|
+
payload: Any,
|
|
110
|
+
mongo_client=Depends(get_mongo_client),
|
|
111
|
+
):
|
|
112
|
+
"""POST /query — classify intent, execute intent, return answer."""
|
|
113
|
+
_rlog(f"[query] question={payload.question!r:.100}")
|
|
114
|
+
_profile_start()
|
|
115
|
+
|
|
116
|
+
visible_question = payload.question.split("Graph Details", 1)[0].strip()
|
|
117
|
+
|
|
118
|
+
from src.monkey_brain.kernel.nlp.question_analyzer import analyze_question
|
|
119
|
+
question_analysis = analyze_question(visible_question)
|
|
120
|
+
|
|
121
|
+
classified_intent = classify_intent(visible_question, question_analysis)
|
|
122
|
+
_profile_add(ProfileEntry(
|
|
123
|
+
phase="Intent Classification",
|
|
124
|
+
model="embed_classifier",
|
|
125
|
+
ms=round((_time.monotonic() - _time.monotonic()) * 1000),
|
|
126
|
+
))
|
|
127
|
+
|
|
128
|
+
if not classified_intent:
|
|
129
|
+
return {
|
|
130
|
+
"question": payload.question,
|
|
131
|
+
"answer": "No intent could be classified for this question.",
|
|
132
|
+
"semantic_hits": [],
|
|
133
|
+
"graph_paths": [],
|
|
134
|
+
"citations": [],
|
|
135
|
+
"llm_answered": False,
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
result = await execute_intent(
|
|
139
|
+
mongo_client=mongo_client,
|
|
140
|
+
question=visible_question,
|
|
141
|
+
classified_intent=classified_intent,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
if result is None:
|
|
145
|
+
return {
|
|
146
|
+
"question": payload.question,
|
|
147
|
+
"answer": unsupported_intent_answer(classified_intent),
|
|
148
|
+
"semantic_hits": [],
|
|
149
|
+
"graph_paths": [],
|
|
150
|
+
"citations": [],
|
|
151
|
+
"llm_answered": False,
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
answer, semantic_hits, graph_paths, llm_answered = result
|
|
155
|
+
|
|
156
|
+
pe = _profile_end()
|
|
157
|
+
return {
|
|
158
|
+
"question": payload.question,
|
|
159
|
+
"answer": answer,
|
|
160
|
+
"semantic_hits": semantic_hits,
|
|
161
|
+
"graph_paths": graph_paths,
|
|
162
|
+
"citations": [],
|
|
163
|
+
"llm_answered": llm_answered,
|
|
164
|
+
"metadata": {
|
|
165
|
+
"intent": classified_intent.get("intent"),
|
|
166
|
+
"confidence": classified_intent.get("confidence"),
|
|
167
|
+
"profile": [e.to_dict() for e in pe] if pe else [],
|
|
168
|
+
},
|
|
169
|
+
}
|
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
"""simulate.py — AgentOS Simulation Route
|
|
2
|
+
|
|
3
|
+
Takes a prompt and runs it through the world-model simulator to produce
|
|
4
|
+
the predicted (ideal) state, calculate loss against actual query results,
|
|
5
|
+
and store Bellman transition values for the planner.
|
|
6
|
+
|
|
7
|
+
Loss = 1 - (simulator's predicted entities matching query's actual answer).
|
|
8
|
+
Two independent reads of the same DB, measuring if they agree.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import re
|
|
14
|
+
import logging
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from fastapi import APIRouter, Depends
|
|
18
|
+
from pydantic import BaseModel, Field
|
|
19
|
+
|
|
20
|
+
from src.monkey_brain.runtime.routers import get_mongo_client
|
|
21
|
+
from src.cortex.world_model_simulation import (
|
|
22
|
+
ENTITY_TRACKED_COLLECTIONS,
|
|
23
|
+
_capture_world_state,
|
|
24
|
+
_store_transition,
|
|
25
|
+
get_transition_values,
|
|
26
|
+
simulate,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
router = APIRouter()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# ---------------------------------------------------------------------------
|
|
35
|
+
# Request / Response models
|
|
36
|
+
# ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
class SimulateRequest(BaseModel):
|
|
39
|
+
question: str = Field(..., min_length=1, description="Free-text prompt to simulate")
|
|
40
|
+
context: dict[str, Any] | None = Field(
|
|
41
|
+
default=None,
|
|
42
|
+
description="Optional context dict passed through to the simulator",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class SimulateResponse(BaseModel):
|
|
47
|
+
simulation_id: str
|
|
48
|
+
question: str
|
|
49
|
+
predicted_state: dict[str, Any] | None = None
|
|
50
|
+
state_before: dict[str, Any] | None = None
|
|
51
|
+
state_delta: dict[str, Any] | None = None
|
|
52
|
+
impact_assessment: dict[str, Any] | None = None
|
|
53
|
+
grounding_score: float = 0.0
|
|
54
|
+
feasibility_verdict: str = "unknown"
|
|
55
|
+
layers_activated: dict[str, bool] | None = None
|
|
56
|
+
needs_correction: bool = False
|
|
57
|
+
correction_prompt: str | None = None
|
|
58
|
+
loss: dict[str, Any] | None = None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class CompareRequest(BaseModel):
|
|
62
|
+
question: str = Field(..., min_length=1)
|
|
63
|
+
context: dict[str, Any] | None = None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class CompareResponse(BaseModel):
|
|
67
|
+
question: str
|
|
68
|
+
predicted: dict[str, Any] | None = None
|
|
69
|
+
actual: dict[str, Any] | None = None
|
|
70
|
+
loss: dict[str, Any] | None = None
|
|
71
|
+
transition_stored: bool = False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class TransitionValuesResponse(BaseModel):
|
|
75
|
+
transitions: list[dict[str, Any]]
|
|
76
|
+
action_values: dict[str, Any]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# ---------------------------------------------------------------------------
|
|
80
|
+
# Helpers
|
|
81
|
+
# ---------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
def _extract_query_facts(answer: str) -> dict[str, Any]:
|
|
84
|
+
"""Extract factual claims from a query answer string.
|
|
85
|
+
|
|
86
|
+
Returns numbers, names, statuses, and collection-like facts found in text.
|
|
87
|
+
"""
|
|
88
|
+
numbers = set(re.findall(r'\b\d+\.?\d*\b', answer))
|
|
89
|
+
words = set(re.findall(r'[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*', answer))
|
|
90
|
+
statuses = set()
|
|
91
|
+
for s in ("Active", "Operational", "Completed", "In Progress", "Planned",
|
|
92
|
+
"Released", "Approved", "On Hold", "Cancelled", "Todo",
|
|
93
|
+
"Under QA Review", "Dispensing", "In Production", "Failed"):
|
|
94
|
+
if s.lower() in answer.lower():
|
|
95
|
+
statuses.add(s)
|
|
96
|
+
return {"numbers": numbers, "names": words, "statuses": statuses}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _compare_predicted_vs_actual(
|
|
100
|
+
predicted_state: dict[str, Any],
|
|
101
|
+
query_answer: str,
|
|
102
|
+
question: str,
|
|
103
|
+
) -> dict[str, Any]:
|
|
104
|
+
"""Compare simulator's entity snapshot against query's actual answer.
|
|
105
|
+
|
|
106
|
+
Focuses on RELEVANT collections only — what the question actually asks about.
|
|
107
|
+
Two independent reads of the same DB, measuring if they agree.
|
|
108
|
+
"""
|
|
109
|
+
entities = predicted_state.get("entities", {})
|
|
110
|
+
collections = predicted_state.get("collections", {})
|
|
111
|
+
query_facts = _extract_query_facts(query_answer)
|
|
112
|
+
q_lower = question.lower()
|
|
113
|
+
|
|
114
|
+
# --- Identify which collections matter for this question ---
|
|
115
|
+
_KEYWORD_MAP = {
|
|
116
|
+
"machine": ["pharmaceutical_machines"],
|
|
117
|
+
"equipment": ["pharmaceutical_equipment"],
|
|
118
|
+
"instrument": ["pharmaceutical_equipment", "instruments"],
|
|
119
|
+
"line": ["industrial_lines"],
|
|
120
|
+
"stage": ["industrial_stages"],
|
|
121
|
+
"workstation": ["industrial_workstations"],
|
|
122
|
+
"batch": ["production_batches", "batch_production_execution_records", "batch_step_executions"],
|
|
123
|
+
"work order": ["work_orders"],
|
|
124
|
+
"sop": ["sops"],
|
|
125
|
+
"change control": ["gxp_change_controls"],
|
|
126
|
+
"oee": ["industrial_lines", "industrial_stages"],
|
|
127
|
+
"mtbf": ["pharmaceutical_machines"],
|
|
128
|
+
"plant": ["industrial_plants"],
|
|
129
|
+
"worker": ["users"],
|
|
130
|
+
"operator": ["industrial_workstations"],
|
|
131
|
+
"status": ["pharmaceutical_machines", "industrial_workstations", "industrial_lines"],
|
|
132
|
+
"capa": ["gxp_change_controls"],
|
|
133
|
+
"maintenance": ["work_orders"],
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
relevant_cols: set[str] = set()
|
|
137
|
+
for kw, cols in _KEYWORD_MAP.items():
|
|
138
|
+
if kw in q_lower:
|
|
139
|
+
relevant_cols.update(cols)
|
|
140
|
+
|
|
141
|
+
# If no keyword matched, fall back to all entity-tracked collections
|
|
142
|
+
if not relevant_cols:
|
|
143
|
+
relevant_cols = set(entities.keys()) | set(collections.keys())
|
|
144
|
+
|
|
145
|
+
total_facts = 0
|
|
146
|
+
total_matches = 0
|
|
147
|
+
|
|
148
|
+
# --- Detect question type to avoid penalizing irrelevant dimensions ---
|
|
149
|
+
is_count_question = any(kw in q_lower for kw in ("how many", "count", "number of"))
|
|
150
|
+
is_name_question = any(kw in q_lower for kw in ("who", "which", "list", "show", "name", "what is", "what are", "what's"))
|
|
151
|
+
is_status_question = any(kw in q_lower for kw in ("status", "state", "condition"))
|
|
152
|
+
is_detail_question = any(kw in q_lower for kw in ("detail", "show", "tell me about", "describe"))
|
|
153
|
+
|
|
154
|
+
# --- Count matching (always relevant) ---
|
|
155
|
+
count_matches = 0
|
|
156
|
+
count_total = 0
|
|
157
|
+
count_details: list[dict] = []
|
|
158
|
+
for col in sorted(relevant_cols):
|
|
159
|
+
info = collections.get(col, {})
|
|
160
|
+
count = info.get("count", 0)
|
|
161
|
+
if count > 0:
|
|
162
|
+
count_total += 1
|
|
163
|
+
matched = str(count) in query_facts["numbers"]
|
|
164
|
+
if matched:
|
|
165
|
+
count_matches += 1
|
|
166
|
+
count_details.append({"collection": col, "count": count, "found_in_answer": matched})
|
|
167
|
+
|
|
168
|
+
total_facts += count_total
|
|
169
|
+
total_matches += count_matches
|
|
170
|
+
|
|
171
|
+
# --- Name matching (skip for pure count questions) ---
|
|
172
|
+
name_matches = 0
|
|
173
|
+
name_total = 0
|
|
174
|
+
name_details: list[dict] = []
|
|
175
|
+
if not is_count_question:
|
|
176
|
+
for col in sorted(relevant_cols):
|
|
177
|
+
info = entities.get(col, {})
|
|
178
|
+
sim_names = set(info.get("names", []))
|
|
179
|
+
if not sim_names:
|
|
180
|
+
continue
|
|
181
|
+
name_total += len(sim_names)
|
|
182
|
+
matched_names = [n for n in sim_names if n.lower() in query_answer.lower()]
|
|
183
|
+
name_matches += len(matched_names)
|
|
184
|
+
name_details.append({
|
|
185
|
+
"collection": col,
|
|
186
|
+
"sim_names": sorted(sim_names),
|
|
187
|
+
"names_in_answer": sorted(matched_names),
|
|
188
|
+
})
|
|
189
|
+
total_facts += name_total
|
|
190
|
+
total_matches += name_matches
|
|
191
|
+
|
|
192
|
+
# --- Status matching (only for status/relevant questions) ---
|
|
193
|
+
status_matches = 0
|
|
194
|
+
status_total = 0
|
|
195
|
+
status_details: list[dict] = []
|
|
196
|
+
if is_status_question or is_detail_question:
|
|
197
|
+
for col in sorted(relevant_cols):
|
|
198
|
+
info = entities.get(col, {})
|
|
199
|
+
sim_statuses = set(info.get("statuses", {}).keys())
|
|
200
|
+
if not sim_statuses:
|
|
201
|
+
continue
|
|
202
|
+
for s in sim_statuses:
|
|
203
|
+
status_total += 1
|
|
204
|
+
if s.lower() in query_answer.lower():
|
|
205
|
+
status_matches += 1
|
|
206
|
+
status_details.append({
|
|
207
|
+
"collection": col,
|
|
208
|
+
"sim_statuses": sorted(sim_statuses),
|
|
209
|
+
"statuses_in_answer": sorted(s for s in sim_statuses if s.lower() in query_answer.lower()),
|
|
210
|
+
})
|
|
211
|
+
total_facts += status_total
|
|
212
|
+
total_matches += status_matches
|
|
213
|
+
loss = round(1.0 - (total_matches / total_facts), 4) if total_facts else 1.0
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
"loss": loss,
|
|
217
|
+
"total_facts": total_facts,
|
|
218
|
+
"matching_facts": total_matches,
|
|
219
|
+
"count_accuracy": round(count_matches / count_total, 4) if count_total else 0.0,
|
|
220
|
+
"name_accuracy": round(name_matches / name_total, 4) if name_total else 0.0,
|
|
221
|
+
"status_accuracy": round(status_matches / status_total, 4) if status_total else 0.0,
|
|
222
|
+
"count_matches": count_matches,
|
|
223
|
+
"name_matches": name_matches,
|
|
224
|
+
"status_matches": status_matches,
|
|
225
|
+
"relevant_collections": sorted(relevant_cols),
|
|
226
|
+
"count_details": count_details,
|
|
227
|
+
"name_details": name_details,
|
|
228
|
+
"status_details": status_details,
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# ---------------------------------------------------------------------------
|
|
233
|
+
# Endpoints
|
|
234
|
+
# ---------------------------------------------------------------------------
|
|
235
|
+
|
|
236
|
+
@router.post("/simulate", response_model=SimulateResponse)
|
|
237
|
+
async def run_simulation(
|
|
238
|
+
payload: SimulateRequest,
|
|
239
|
+
mongo_client=Depends(get_mongo_client),
|
|
240
|
+
):
|
|
241
|
+
"""Simulate a prompt and return the predicted (ideal) state."""
|
|
242
|
+
ctx = payload.context or {}
|
|
243
|
+
if "db" not in ctx and mongo_client is not None:
|
|
244
|
+
from services.common.config import settings
|
|
245
|
+
ctx["db"] = mongo_client[settings.DB_NAME]
|
|
246
|
+
|
|
247
|
+
result = await simulate(payload.question, context=ctx)
|
|
248
|
+
|
|
249
|
+
return SimulateResponse(
|
|
250
|
+
simulation_id=result.get("simulation_id", ""),
|
|
251
|
+
question=payload.question,
|
|
252
|
+
predicted_state=result.get("state_after"),
|
|
253
|
+
state_before=result.get("state_before"),
|
|
254
|
+
state_delta=result.get("state_delta"),
|
|
255
|
+
impact_assessment=result.get("impact_assessment"),
|
|
256
|
+
grounding_score=result.get("grounding_score", 0.0),
|
|
257
|
+
feasibility_verdict=result.get("feasibility_verdict", "unknown"),
|
|
258
|
+
layers_activated=result.get("layers_activated"),
|
|
259
|
+
needs_correction=result.get("needs_correction", False),
|
|
260
|
+
correction_prompt=result.get("correction_prompt"),
|
|
261
|
+
loss=result.get("loss"),
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
@router.post("/compare", response_model=CompareResponse)
|
|
266
|
+
async def compare_sim_vs_query(
|
|
267
|
+
payload: CompareRequest,
|
|
268
|
+
mongo_client=Depends(get_mongo_client),
|
|
269
|
+
):
|
|
270
|
+
"""Compare simulator's predicted state against query's actual answer.
|
|
271
|
+
|
|
272
|
+
Flow:
|
|
273
|
+
1. Capture simulator's entity snapshot (predicted state)
|
|
274
|
+
2. Run query to get actual answer
|
|
275
|
+
3. Compare: does the query's answer agree with the simulator's data?
|
|
276
|
+
4. Store Bellman transition with the computed loss
|
|
277
|
+
"""
|
|
278
|
+
from services.common.config import settings
|
|
279
|
+
|
|
280
|
+
db = None
|
|
281
|
+
if mongo_client is not None:
|
|
282
|
+
db = mongo_client[settings.DB_NAME]
|
|
283
|
+
|
|
284
|
+
# Step 1: Capture predicted state from simulator
|
|
285
|
+
ctx = payload.context or {}
|
|
286
|
+
if "db" not in ctx and db is not None:
|
|
287
|
+
ctx["db"] = db
|
|
288
|
+
|
|
289
|
+
sim_result = await simulate(payload.question, context=ctx)
|
|
290
|
+
predicted_state = sim_result.get("state_after") or sim_result.get("state_before") or {}
|
|
291
|
+
|
|
292
|
+
# Step 2: Run query to get actual answer via HTTP
|
|
293
|
+
query_answer = ""
|
|
294
|
+
try:
|
|
295
|
+
import httpx
|
|
296
|
+
from services.common.config import settings
|
|
297
|
+
|
|
298
|
+
query_url = f"http://localhost:{settings.PORT if hasattr(settings, 'PORT') else 8032}/api/v1/agentos/query"
|
|
299
|
+
async with httpx.AsyncClient(timeout=180.0) as client:
|
|
300
|
+
resp = await client.post(query_url, json={
|
|
301
|
+
"question": payload.question,
|
|
302
|
+
"top_k": 8,
|
|
303
|
+
"use_retrieval": False,
|
|
304
|
+
"use_memory": False,
|
|
305
|
+
"bypass_cache": True,
|
|
306
|
+
})
|
|
307
|
+
if resp.status_code == 200:
|
|
308
|
+
query_data = resp.json()
|
|
309
|
+
query_answer = query_data.get("answer", "")
|
|
310
|
+
except Exception as exc:
|
|
311
|
+
logger.warning("Compare: query execution failed: %s", exc)
|
|
312
|
+
|
|
313
|
+
# Step 3: Compare predicted vs actual
|
|
314
|
+
loss_result = _compare_predicted_vs_actual(predicted_state, query_answer, payload.question)
|
|
315
|
+
|
|
316
|
+
# Step 3.5: Determine pipeline name from question
|
|
317
|
+
pipeline_name = ""
|
|
318
|
+
try:
|
|
319
|
+
from src.monkey_brain.kernel.classifier.embed_classifier import classify_intent
|
|
320
|
+
from src.monkey_brain.kernel.goal_router import route_question
|
|
321
|
+
from src.monkey_brain.kernel.nlp.question_analyzer import analyze_question
|
|
322
|
+
qa = analyze_question(payload.question)
|
|
323
|
+
ci = classify_intent(payload.question, qa)
|
|
324
|
+
if ci and ci.get("confidence", 0) >= 0.3:
|
|
325
|
+
goal = route_question(payload.question, ci)
|
|
326
|
+
pipeline_name = goal.expert or goal.pipeline_id or ci.get("intent", "")
|
|
327
|
+
logger.info("[compare] pipeline_name=%r for question=%r", pipeline_name, payload.question[:60])
|
|
328
|
+
except Exception as exc:
|
|
329
|
+
logger.warning("[compare] pipeline classification failed: %s", exc)
|
|
330
|
+
|
|
331
|
+
# Step 4: Store Bellman transition with correct pipeline_name
|
|
332
|
+
transition_stored = False
|
|
333
|
+
if db is not None:
|
|
334
|
+
try:
|
|
335
|
+
action = payload.question[:200]
|
|
336
|
+
await _store_transition(
|
|
337
|
+
db,
|
|
338
|
+
simulation_id=sim_result.get("simulation_id", ""),
|
|
339
|
+
prompt=payload.question,
|
|
340
|
+
action=action,
|
|
341
|
+
pipeline_name=pipeline_name,
|
|
342
|
+
state_before=predicted_state,
|
|
343
|
+
state_after={"query_answer": query_answer[:2000]},
|
|
344
|
+
loss_result=loss_result,
|
|
345
|
+
grounding_score=sim_result.get("grounding_score", 0.0),
|
|
346
|
+
feasibility_verdict=sim_result.get("feasibility_verdict", "unknown"),
|
|
347
|
+
)
|
|
348
|
+
transition_stored = True
|
|
349
|
+
except Exception as exc:
|
|
350
|
+
logger.warning("Compare: transition store failed: %s", exc)
|
|
351
|
+
|
|
352
|
+
return CompareResponse(
|
|
353
|
+
question=payload.question,
|
|
354
|
+
predicted=predicted_state,
|
|
355
|
+
actual={"query_answer": query_answer[:2000]},
|
|
356
|
+
loss=loss_result,
|
|
357
|
+
transition_stored=transition_stored,
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
@router.get("/transitions", response_model=TransitionValuesResponse)
|
|
362
|
+
async def list_transition_values(
|
|
363
|
+
action: str | None = None,
|
|
364
|
+
limit: int = 100,
|
|
365
|
+
mongo_client=Depends(get_mongo_client),
|
|
366
|
+
):
|
|
367
|
+
"""Retrieve Bellman transition values for the planner."""
|
|
368
|
+
db = None
|
|
369
|
+
if mongo_client is not None:
|
|
370
|
+
from services.common.config import settings
|
|
371
|
+
db = mongo_client[settings.DB_NAME]
|
|
372
|
+
|
|
373
|
+
result = await get_transition_values(db, action=action, limit=limit)
|
|
374
|
+
return TransitionValuesResponse(**result)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
# ---------------------------------------------------------------------------
|
|
378
|
+
# Test endpoint — full Bellman cycle verification
|
|
379
|
+
# ---------------------------------------------------------------------------
|
|
380
|
+
|
|
381
|
+
class BellmanCycleResponse(BaseModel):
|
|
382
|
+
question: str
|
|
383
|
+
pipeline_name: str
|
|
384
|
+
simulate: dict[str, Any]
|
|
385
|
+
query_answer_preview: str
|
|
386
|
+
loss: dict[str, Any]
|
|
387
|
+
transition: dict[str, Any]
|
|
388
|
+
bellman_values: dict[str, Any]
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
@router.post("/test-bellman-cycle", response_model=BellmanCycleResponse)
|
|
392
|
+
async def test_bellman_cycle(
|
|
393
|
+
question: str = "How many machines are in the system?",
|
|
394
|
+
mongo_client=Depends(get_mongo_client),
|
|
395
|
+
):
|
|
396
|
+
"""Run a sample pipeline through the full Bellman cycle and return results.
|
|
397
|
+
|
|
398
|
+
Verifies: simulate → query → loss → transition store → transition lookup.
|
|
399
|
+
"""
|
|
400
|
+
from services.common.config import settings
|
|
401
|
+
|
|
402
|
+
db = None
|
|
403
|
+
if mongo_client is not None:
|
|
404
|
+
db = mongo_client[settings.DB_NAME]
|
|
405
|
+
|
|
406
|
+
# Step 1: Simulate
|
|
407
|
+
ctx = {"db": db} if db is not None else {}
|
|
408
|
+
sim_result = await simulate(question, context=ctx)
|
|
409
|
+
|
|
410
|
+
# Step 2: Query
|
|
411
|
+
query_answer = ""
|
|
412
|
+
try:
|
|
413
|
+
import httpx
|
|
414
|
+
async with httpx.AsyncClient(timeout=180.0) as client:
|
|
415
|
+
resp = await client.post(
|
|
416
|
+
f"http://localhost:{settings.PORT if hasattr(settings, 'PORT') else 8032}/api/v1/agentos/query",
|
|
417
|
+
json={"question": question, "top_k": 8, "use_retrieval": False,
|
|
418
|
+
"use_memory": False, "bypass_cache": True},
|
|
419
|
+
)
|
|
420
|
+
if resp.status_code == 200:
|
|
421
|
+
query_answer = resp.json().get("answer", "")
|
|
422
|
+
except Exception:
|
|
423
|
+
pass
|
|
424
|
+
|
|
425
|
+
# Step 3: Loss
|
|
426
|
+
predicted_state = sim_result.get("state_after") or sim_result.get("state_before") or {}
|
|
427
|
+
loss_result = _compare_predicted_vs_actual(predicted_state, query_answer, question)
|
|
428
|
+
|
|
429
|
+
# Step 4: Store transition
|
|
430
|
+
pipeline_name = ""
|
|
431
|
+
try:
|
|
432
|
+
from src.monkey_brain.kernel.classifier.embed_classifier import classify_intent
|
|
433
|
+
from src.monkey_brain.kernel.goal_router import route_question
|
|
434
|
+
from src.monkey_brain.kernel.nlp.question_analyzer import analyze_question
|
|
435
|
+
qa = analyze_question(question)
|
|
436
|
+
ci = classify_intent(question, qa)
|
|
437
|
+
if ci and ci.get("confidence", 0) >= 0.3:
|
|
438
|
+
goal = route_question(question, ci)
|
|
439
|
+
pipeline_name = goal.expert or goal.pipeline_id or ci.get("intent", "")
|
|
440
|
+
except Exception:
|
|
441
|
+
pass
|
|
442
|
+
|
|
443
|
+
transition_stored = False
|
|
444
|
+
if db is not None:
|
|
445
|
+
try:
|
|
446
|
+
await _store_transition(
|
|
447
|
+
db,
|
|
448
|
+
simulation_id=sim_result.get("simulation_id", ""),
|
|
449
|
+
prompt=question,
|
|
450
|
+
action=question[:200],
|
|
451
|
+
pipeline_name=pipeline_name,
|
|
452
|
+
state_before=predicted_state,
|
|
453
|
+
state_after={"query_answer": query_answer[:2000]},
|
|
454
|
+
loss_result=loss_result,
|
|
455
|
+
grounding_score=sim_result.get("grounding_score", 0.0),
|
|
456
|
+
feasibility_verdict=sim_result.get("feasibility_verdict", "unknown"),
|
|
457
|
+
)
|
|
458
|
+
transition_stored = True
|
|
459
|
+
except Exception:
|
|
460
|
+
pass
|
|
461
|
+
|
|
462
|
+
# Step 5: Lookup transition values
|
|
463
|
+
bellman_values = {}
|
|
464
|
+
if db is not None:
|
|
465
|
+
try:
|
|
466
|
+
tv = await get_transition_values(db, pipeline_name=pipeline_name, limit=10)
|
|
467
|
+
bellman_values = tv.get("action_values", {})
|
|
468
|
+
except Exception:
|
|
469
|
+
pass
|
|
470
|
+
|
|
471
|
+
return BellmanCycleResponse(
|
|
472
|
+
question=question,
|
|
473
|
+
pipeline_name=pipeline_name,
|
|
474
|
+
simulate={
|
|
475
|
+
"simulation_id": sim_result.get("simulation_id"),
|
|
476
|
+
"grounding_score": sim_result.get("grounding_score"),
|
|
477
|
+
"feasibility_verdict": sim_result.get("feasibility_verdict"),
|
|
478
|
+
"layers_activated": sim_result.get("layers_activated"),
|
|
479
|
+
"entity_count": len(predicted_state.get("entities", {})),
|
|
480
|
+
},
|
|
481
|
+
query_answer_preview=query_answer[:500],
|
|
482
|
+
loss=loss_result,
|
|
483
|
+
transition={"stored": transition_stored, "pipeline_name": pipeline_name},
|
|
484
|
+
bellman_values=bellman_values,
|
|
485
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""DLM — Data Lifecycle Manager for AgentOS.
|
|
2
|
+
|
|
3
|
+
Manages the lifecycle of all runtime data.
|
|
4
|
+
Ensures AgentOS remains performant and storage-efficient.
|
|
5
|
+
|
|
6
|
+
Provides:
|
|
7
|
+
- TTL Management
|
|
8
|
+
- Garbage Collection
|
|
9
|
+
- Storage Monitoring
|
|
10
|
+
- Orphan Detection
|
|
11
|
+
- Lifecycle Policies
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from src.monkey_brain.dlm.dlm import Dlm
|
|
15
|
+
from src.monkey_brain.dlm.lifecycle import (
|
|
16
|
+
LifecyclePolicy,
|
|
17
|
+
StorageClass,
|
|
18
|
+
ExpirationAction,
|
|
19
|
+
get_policy,
|
|
20
|
+
DATA_POLICIES,
|
|
21
|
+
)
|
|
22
|
+
from src.monkey_brain.dlm.ttl import TtlManager, TtlEntry
|
|
23
|
+
from src.monkey_brain.dlm.gc import GarbageCollector, CollectionResult
|
|
24
|
+
from src.monkey_brain.dlm.storage import StorageMonitor, StorageQuota, StorageSnapshot
|
|
25
|
+
from src.monkey_brain.dlm.orphans import OrphanDetector, Orphan, OrphanScanResult
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"Dlm",
|
|
29
|
+
"LifecyclePolicy",
|
|
30
|
+
"StorageClass",
|
|
31
|
+
"ExpirationAction",
|
|
32
|
+
"get_policy",
|
|
33
|
+
"DATA_POLICIES",
|
|
34
|
+
"TtlManager",
|
|
35
|
+
"TtlEntry",
|
|
36
|
+
"GarbageCollector",
|
|
37
|
+
"CollectionResult",
|
|
38
|
+
"StorageMonitor",
|
|
39
|
+
"StorageQuota",
|
|
40
|
+
"StorageSnapshot",
|
|
41
|
+
"OrphanDetector",
|
|
42
|
+
"Orphan",
|
|
43
|
+
"OrphanScanResult",
|
|
44
|
+
]
|