class MLflowBundle:
r"""无额外依赖的 MLflow / tracker run 载荷归一化工具 bundle。"""
def register(self, registry: ToolRegistry, context: BundleContext) -> None:
registry.add(
Tool(
name="normalize_mlflow_run",
description="把 MLflow run 或 tracker 事件载荷归一化为紧凑 run 事实。",
input_schema={
"type": "object",
"properties": {"payload": {"type": "object", "description": "MLflow run 或 tracker 事件 JSON。"}},
"required": ["payload"],
"additionalProperties": False,
},
handler=lambda payload: normalize_mlflow_run(payload),
)
)
registry.add(
Tool(
name="search_mlflow_experiments",
description="搜索 MLflow experiments,用于定位训练任务所在实验。",
input_schema={
"type": "object",
"properties": {
"query": {"type": "string", "description": "实验名称关键词。"},
"max_results": {"type": "integer", "description": "最多返回多少个实验,默认 20。"},
},
"additionalProperties": False,
},
handler=lambda query=None, max_results=20: _search_experiments(
context, query=query, max_results=max_results
),
)
)
registry.add(
Tool(
name="search_mlflow_runs",
description="搜索 MLflow runs,用于查看训练任务状态、指标、参数和最近运行。",
input_schema={
"type": "object",
"properties": {
"experiment_ids": {
"type": "array",
"items": {"type": "string"},
"description": "MLflow experiment_id 列表。",
},
"experiment_name": {"type": "string", "description": "实验名称;未给 ids 时可用。"},
"filter": {"type": "string", "description": "MLflow runs/search filter 字符串。"},
"max_results": {"type": "integer", "description": "最多返回多少个 run,默认 10。"},
"order_by": {
"type": "array",
"items": {"type": "string"},
"description": "MLflow order_by 列表。",
},
},
"additionalProperties": False,
},
handler=lambda experiment_ids=None, experiment_name=None, filter=None, max_results=10, order_by=None: (
_search_runs(
context,
experiment_ids=experiment_ids,
experiment_name=experiment_name,
filter=filter,
max_results=max_results,
order_by=order_by,
)
),
)
)
registry.add(
Tool(
name="get_mlflow_run",
description="读取单个 MLflow run 的状态、指标、参数、标签和 artifact URI。",
input_schema={
"type": "object",
"properties": {"run_id": {"type": "string", "description": "MLflow run_id。"}},
"required": ["run_id"],
"additionalProperties": False,
},
handler=lambda run_id: _get_run(context, run_id=run_id),
)
)