Skip to content

refactor: implement Work Order Agent MCP server and agent_hive integration#191

Open
ShuxinLin wants to merge 15 commits intomainfrom
refactor/reorg-wo-agent
Open

refactor: implement Work Order Agent MCP server and agent_hive integration#191
ShuxinLin wants to merge 15 commits intomainfrom
refactor/reorg-wo-agent

Conversation

@ShuxinLin
Copy link
Collaborator

@ShuxinLin ShuxinLin commented Mar 4, 2026

Summary

  • src/servers/wo/main.py — Full FastMCP server ported from api_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 by requires_wo_data).
  • src/tmp/agent_hive/tools/wo.py — Agent-hive tool registration (mirrors fmsr.py/tsfm.py pattern).
  • src/tmp/agent_hive/agents/wo_agent.pyWorderOrderAgent class satisfying the interface in run_track_1.py.
  • pyproject.toml — Adds wo-mcp-server CLI entry point.

MCP tools (ported from @validate_inputs functions in api_implementation_cbm.py)

Tool Original function
get_work_orders get_work_orders(equipment, date_range)
get_preventive_work_orders get_preventive_work_orders(equipment, date_range)
get_corrective_work_orders get_corrective_work_orders(equipment, date_range)
get_events get_events(equipment, date_range)
get_failure_codes get_failure_code()
get_work_order_distribution calculate_work_order_distribution(equipment, date_range)
predict_next_work_order predict_next_work_order_probability(equipment, date_range)
analyze_alert_to_failure analyze_alert_to_failure(equipment, alert_rule, date_range)

Key structural changes

  • Equipment / DateRange / Date objects → flat str parameters (MCP-friendly)
  • importlib.resources.path("woagent.event_forecasting.data", ...) → configurable WO_DATA_DIR env var (defaults to src/tmp/assetopsbench/sample_data/)
  • All CSVs 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 at the transport layer)

Test plan

  • uv run pytest src/servers/wo/tests/test_tools.py -v — 23 unit tests pass, 8 integration tests skipped
  • Set WO_DATA_DIR=src/tmp/assetopsbench/sample_data and rerun — integration tests execute
  • uv run wo-mcp-server starts without error
  • uv run pytest src/ -v -k "not integration" — no regressions in other servers

ShuxinLin added 15 commits March 4, 2026 13:59
…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>
…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>
@ShuxinLin ShuxinLin requested a review from DhavalRepo18 March 6, 2026 16:09
@DhavalRepo18
Copy link
Collaborator

@ShuxinLin I am delegating this task to @nianjunz, so he can confirm the basic modifications.

@DhavalRepo18
Copy link
Collaborator

@nianjunz, as a part of the review process, you should

  • review the code
  • run the code (a few more utterances)
  • evaluate whether it has any impact on your downstream evaluation process

Copy link
Collaborator

@DhavalRepo18 DhavalRepo18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made a first pass on the implementation.

@DhavalRepo18
Copy link
Collaborator

DhavalRepo18 commented Mar 9, 2026

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants