MCPcopy
hub / github.com/IBM/AssetOpsBench / _serialize_trajectory

Function _serialize_trajectory

src/observability/persistence.py:89–104  ·  view source on GitHub ↗

Reduce a trajectory to plain JSON-friendly Python. Handles the two shapes in this repo: SDK runners' ``Trajectory`` dataclass, and plan-execute's ``list[StepResult]`` (also dataclasses).

(trajectory: Any)

Source from the content-addressed store, hash-verified

87
88
89def _serialize_trajectory(trajectory: Any) -> Any:
90 """Reduce a trajectory to plain JSON-friendly Python.
91
92 Handles the two shapes in this repo: SDK runners' ``Trajectory``
93 dataclass, and plan-execute's ``list[StepResult]`` (also dataclasses).
94 """
95 if trajectory is None:
96 return None
97 if dataclasses.is_dataclass(trajectory):
98 return dataclasses.asdict(trajectory)
99 if isinstance(trajectory, list):
100 return [
101 dataclasses.asdict(item) if dataclasses.is_dataclass(item) else item
102 for item in trajectory
103 ]
104 return trajectory

Callers 1

persist_trajectoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected