|
| 1 | +Portable Agent-Trajectory Trace (Record & Replay) |
| 2 | +================================================= |
| 3 | + |
| 4 | +``agent_trace`` records OpenTelemetry GenAI *spans* (tokens / latency / cost) — that is |
| 5 | +observability, not a replayable observation→action transcript; ``trajectory_eval`` |
| 6 | +*scores* a trajectory but defines no persisted format and cannot replay it; and |
| 7 | +``semantic_recording`` replays recorded *human input macros*, not *agent* decisions. |
| 8 | +This adds the OmniTool-style "log the trajectory to build a replay / training dataset" |
| 9 | +format: ``{step, observation, action, result}`` JSONL with a deterministic replay |
| 10 | +driver. |
| 11 | + |
| 12 | +Pure-stdlib JSONL; the replay driver takes an injectable ``runner`` (no live model), so |
| 13 | +it is fully unit-testable. Imports no ``PySide6``. |
| 14 | + |
| 15 | +Headless API |
| 16 | +------------ |
| 17 | + |
| 18 | +.. code-block:: python |
| 19 | +
|
| 20 | + from je_auto_control import record_step, to_jsonl, from_jsonl, replay_trace |
| 21 | +
|
| 22 | + trace = [] |
| 23 | + record_step(trace, observation="login screen", |
| 24 | + action=["AC_click_mouse", {"x": 120, "y": 80}]) |
| 25 | + record_step(trace, observation="typed user", action=["AC_write", |
| 26 | + {"write_string": "alice"}], result={"ok": True}) |
| 27 | +
|
| 28 | + open("run.jsonl", "w").write(to_jsonl(trace)) # persist a dataset |
| 29 | +
|
| 30 | + # Later — replay every step through any runner (here a fake for tests). |
| 31 | + results = replay_trace(from_jsonl(open("run.jsonl").read()), |
| 32 | + runner=lambda action: do(action)) |
| 33 | +
|
| 34 | +``record_step`` appends an indexed ``{step, observation, action[, result]}`` entry; |
| 35 | +``to_jsonl`` / ``from_jsonl`` round-trip the trace as newline-delimited JSON; |
| 36 | +``replay_trace`` runs each step's ``action`` through ``runner(action)`` and returns the |
| 37 | +``{step, action, result}`` outcomes in order. |
| 38 | + |
| 39 | +Executor command |
| 40 | +---------------- |
| 41 | + |
| 42 | +``AC_replay_trace`` replays a ``trace`` (JSON array or JSONL) by running each step's |
| 43 | +``action`` (an AC action list) through the executor, returning ``{count, results}``. It |
| 44 | +is exposed as the MCP tool ``ac_replay_trace`` (side-effecting) and as a Script Builder |
| 45 | +command under **Flow**. |
0 commit comments