Normalize data agent records output path
This commit is contained in:
+31
-5
@@ -1207,7 +1207,11 @@ def _data_agent_prepare_generation_plan_tool(arguments: dict[str, Any], context:
|
||||
turn_mix=_require_string(arguments, 'turn_mix'),
|
||||
coverage=_require_string(arguments, 'coverage'),
|
||||
exclusions=_require_string(arguments, 'exclusions'),
|
||||
output_path=_data_agent_output_path(_require_string(arguments, 'output_path'), context),
|
||||
output_path=_data_agent_output_path(
|
||||
_require_string(arguments, 'output_path'),
|
||||
context,
|
||||
canonical_filename='records.jsonl',
|
||||
),
|
||||
target_definitions=_optional_target_definitions(arguments.get('target_definitions')),
|
||||
notes=notes,
|
||||
confirmed_goal_id=confirmed_goal_id or None,
|
||||
@@ -1480,10 +1484,15 @@ def _export_dataset_records_tool(arguments: dict[str, Any], context: ToolExecuti
|
||||
raise ToolExecutionError('overwrite must be a boolean')
|
||||
try:
|
||||
records = records_from_tool_argument(arguments['records'])
|
||||
canonical_filename = 'records.json' if output_format == 'json' else 'records.jsonl'
|
||||
payload = export_dataset_records(
|
||||
records,
|
||||
root=str(context.root),
|
||||
output_path=_data_agent_output_path(_require_string(arguments, 'output_path'), context),
|
||||
output_path=_data_agent_output_path(
|
||||
_require_string(arguments, 'output_path'),
|
||||
context,
|
||||
canonical_filename=canonical_filename,
|
||||
),
|
||||
output_format=output_format,
|
||||
require_validation_ok=require_validation_ok,
|
||||
overwrite=overwrite,
|
||||
@@ -1493,15 +1502,32 @@ def _export_dataset_records_tool(arguments: dict[str, Any], context: ToolExecuti
|
||||
return json.dumps(payload, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
def _data_agent_output_path(output_path: str, context: ToolExecutionContext) -> str:
|
||||
"""把数据 Agent 产物默认路由到当前用户/会话的 output 目录。"""
|
||||
def _data_agent_output_path(
|
||||
output_path: str,
|
||||
context: ToolExecutionContext,
|
||||
*,
|
||||
canonical_filename: str | None = None,
|
||||
) -> str:
|
||||
"""把数据 Agent 产物默认路由到当前用户/会话的 output 目录。
|
||||
|
||||
canonical_filename 用于强制收口最终 records 文件名,避免模型按数据集名
|
||||
自行创建子目录或临时文件名,导致产物位置不稳定。
|
||||
"""
|
||||
|
||||
raw = output_path.strip()
|
||||
path = Path(raw).expanduser()
|
||||
|
||||
output_root = _data_agent_session_output_root(context)
|
||||
if canonical_filename:
|
||||
resolved = (output_root / canonical_filename).resolve(strict=False)
|
||||
try:
|
||||
return resolved.relative_to(context.root).as_posix()
|
||||
except ValueError:
|
||||
return resolved.as_posix()
|
||||
|
||||
if path.is_absolute() or path.parts[:1] == ('.port_sessions',):
|
||||
return raw
|
||||
|
||||
output_root = _data_agent_session_output_root(context)
|
||||
parts = path.parts
|
||||
suffix = Path(*parts[1:]) if parts and parts[0] in {'output', 'outputs'} else path
|
||||
resolved = (output_root / suffix).resolve(strict=False)
|
||||
|
||||
Reference in New Issue
Block a user