Write tool result and tool_metadata to METADATA.json. Matches BaseTool._update_exec_metadata(): - tool_metadata: list of dicts with tool_name, output_type, elapsed_time (destination connector reads output_type from here) - total_elapsed_time: cumulative elapsed time
(
fs: Any, execution_data_dir: str, _data: dict, elapsed_time: float = 0.0
)
| 834 | |
| 835 | |
| 836 | def _write_tool_result( |
| 837 | fs: Any, execution_data_dir: str, _data: dict, elapsed_time: float = 0.0 |
| 838 | ) -> None: |
| 839 | """Write tool result and tool_metadata to METADATA.json. |
| 840 | |
| 841 | Matches BaseTool._update_exec_metadata(): |
| 842 | - tool_metadata: list of dicts with tool_name, output_type, elapsed_time |
| 843 | (destination connector reads output_type from here) |
| 844 | - total_elapsed_time: cumulative elapsed time |
| 845 | """ |
| 846 | metadata_path: Path | None = None |
| 847 | try: |
| 848 | metadata_path = Path(execution_data_dir) / "METADATA.json" |
| 849 | |
| 850 | # Read existing metadata if present |
| 851 | existing: dict = {} |
| 852 | if fs.exists(metadata_path): |
| 853 | try: |
| 854 | existing_raw = fs.read(path=metadata_path, mode="r") |
| 855 | if existing_raw: |
| 856 | existing = json.loads(existing_raw) |
| 857 | except Exception: |
| 858 | pass |
| 859 | |
| 860 | # Add tool_metadata (matches BaseTool._update_exec_metadata) |
| 861 | # The destination connector reads output_type from tool_metadata[-1] |
| 862 | tool_meta_entry = { |
| 863 | "tool_name": "structure_tool", |
| 864 | "output_type": "JSON", |
| 865 | "elapsed_time": elapsed_time, |
| 866 | } |
| 867 | if "tool_metadata" not in existing: |
| 868 | existing["tool_metadata"] = [tool_meta_entry] |
| 869 | else: |
| 870 | existing["tool_metadata"].append(tool_meta_entry) |
| 871 | |
| 872 | existing["total_elapsed_time"] = ( |
| 873 | existing.get("total_elapsed_time", 0.0) + elapsed_time |
| 874 | ) |
| 875 | |
| 876 | fs.write( |
| 877 | path=metadata_path, |
| 878 | mode="w", |
| 879 | data=json.dumps(existing, indent=2), |
| 880 | ) |
| 881 | except Exception as e: |
| 882 | logger.error( |
| 883 | "Failed to write tool result to METADATA.json at '%s': %s", |
| 884 | metadata_path, |
| 885 | e, |
| 886 | exc_info=True, |
| 887 | ) |
no test coverage detected