refactor: implement Work Order Agent MCP server and agent_hive integration#191
Open
refactor: implement Work Order Agent MCP server and agent_hive integration#191
Conversation
…ation - Add src/servers/wo/main.py: FastMCP server with 3 tools (list_equipment, get_work_orders, summarize_work_orders) backed by the sample CSV dataset - Add src/servers/wo/tests/: conftest with mock_df fixture and 12 unit tests covering all tools; integration tests gated by requires_wo_data marker - Add src/tmp/agent_hive/tools/wo.py: agent_hive tool registration module (mirrors fmsr.py / tsfm.py pattern) referencing external woagent package - Add src/tmp/agent_hive/agents/wo_agent.py: WorderOrderAgent class backed by ReactReflectXenAgent, matching the interface expected by run_track tests - Register wo-mcp-server CLI entry point in pyproject.toml Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
…on_cbm Port all @validate_inputs functions from src/tmp/workorder_agent/event_forecasting/apis/api_implementation_cbm.py to FastMCP tools, replacing the earlier placeholder stub. Tools (8 total): - get_work_orders — all WOs for equipment in date range - get_preventive_work_orders — preventive WOs only - get_corrective_work_orders — corrective WOs only - get_events — all events (WO / alert / anomaly) - get_failure_codes — full failure code catalogue - get_work_order_distribution — counts per (primary, secondary) code pair - predict_next_work_order — Markov-chain transition probability - analyze_alert_to_failure — alert-rule → maintenance transition stats Key structural changes vs. original: - Equipment/DateRange/Date objects → flat string parameters (MCP-friendly) - importlib.resources.path() → configurable WO_DATA_DIR env var (defaults to src/tmp/assetopsbench/sample_data/) - All data loaded lazily, missing files degrade gracefully - Pickle-file return values → typed Pydantic BaseModel responses - analyze_alert_to_failure now returns the computed transition result instead of None - validate_inputs decorator removed (MCP enforces types) - Tests updated: 23 unit tests + 8 integration tests (requires_wo_data) Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
- Add src/couchdb/init_wo.py: loads all WO CSVs into a CouchDB `workorder` database with _dataset discriminator field and Mango indexes - Rewrite src/servers/wo/data.py: lazy couchdb3 connection, load() queries via Mango find instead of reading CSVs - Fix src/servers/wo/tools.py: use rule_id column (was rule) for alert_events - Update tests: mock_data patches servers.wo.tools.load directly; replace requires_wo_data marker with requires_couchdb; all 23 unit tests pass Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
…ompose - Add src/couchdb/init_asset_data.py: loads IoT sensor JSON into CouchDB (decouples data loading from couchdb_setup.sh) - Simplify couchdb_setup.sh: only writes local.ini and starts CouchDB - Add db-init service to docker-compose.yaml: python:3.12-slim container that runs after couchdb is healthy, calling both init_asset_data.py and init_wo.py Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
…ontainer Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
…derAgent Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
…check connectivity, fix history date validation order Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
…ver and tests Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
CouchDB rejects document fields starting with '_' (reserved for _id, _rev, etc.). Rename the collection discriminator field from _dataset to dataset in both init_wo.py and data.py. Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
Add wo-mcp-server to DEFAULT_SERVER_PATHS so WorkOrderAgent tools are available to plan-execute without requiring --server overrides. Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
…UCTIONS.md - Add WorkOrder query examples (work order count, PM vs CM split, alert-to-failure probability, multi-step distribution + prediction) - Clarify that plan-execute spawns MCP servers on-demand; no manual server startup required - Fix .env.public: replace COUCHDB_DBNAME with IOT_DBNAME + WO_DBNAME - Add src/tmp/ to .gitignore Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
Collaborator
|
@ShuxinLin I am delegating this task to @nianjunz, so he can confirm the basic modifications. |
Collaborator
|
@nianjunz, as a part of the review process, you should
|
DhavalRepo18
requested changes
Mar 9, 2026
DhavalRepo18
reviewed
Mar 9, 2026
DhavalRepo18
requested changes
Mar 9, 2026
Collaborator
DhavalRepo18
left a comment
There was a problem hiding this comment.
I have made a first pass on the implementation.
Collaborator
|
@ShuxinLin While reviewing this task, we are now putting the WO data inside CouchDB, so we gave the tool to access the data as and when needed. How this approach will work, let say
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/servers/wo/main.py— Full FastMCP server ported fromapi_implementation_cbm.py, replacing the earlier placeholder stub. Implements 8 MCP tools (see below).src/servers/wo/tests/— 23 unit tests + 8 integration tests (gated byrequires_wo_data).src/tmp/agent_hive/tools/wo.py— Agent-hive tool registration (mirrorsfmsr.py/tsfm.pypattern).src/tmp/agent_hive/agents/wo_agent.py—WorderOrderAgentclass satisfying the interface inrun_track_1.py.pyproject.toml— Addswo-mcp-serverCLI entry point.MCP tools (ported from
@validate_inputsfunctions inapi_implementation_cbm.py)get_work_ordersget_work_orders(equipment, date_range)get_preventive_work_ordersget_preventive_work_orders(equipment, date_range)get_corrective_work_ordersget_corrective_work_orders(equipment, date_range)get_eventsget_events(equipment, date_range)get_failure_codesget_failure_code()get_work_order_distributioncalculate_work_order_distribution(equipment, date_range)predict_next_work_orderpredict_next_work_order_probability(equipment, date_range)analyze_alert_to_failureanalyze_alert_to_failure(equipment, alert_rule, date_range)Key structural changes
Equipment/DateRange/Dateobjects → flatstrparameters (MCP-friendly)importlib.resources.path("woagent.event_forecasting.data", ...)→ configurableWO_DATA_DIRenv var (defaults tosrc/tmp/assetopsbench/sample_data/)BaseModelresponsesanalyze_alert_to_failurenow returns the computed transition result instead ofNone@validate_inputsdecorator removed (MCP enforces types at the transport layer)Test plan
uv run pytest src/servers/wo/tests/test_tools.py -v— 23 unit tests pass, 8 integration tests skippedWO_DATA_DIR=src/tmp/assetopsbench/sample_dataand rerun — integration tests executeuv run wo-mcp-serverstarts without erroruv run pytest src/ -v -k "not integration"— no regressions in other servers