Skip to content

Commit 92b9e3f

Browse files
committed
Add portable agent-trajectory trace (record / replay)
1 parent 2c3bd47 commit 92b9e3f

15 files changed

Lines changed: 280 additions & 1 deletion

File tree

README/WHATS_NEW_zh-CN.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 本次更新 — AutoControl
22

3+
## 本次更新 (2026-06-23) — 可携式 Agent 轨迹记录(录制与重播)
4+
5+
记录 agent 的观测→动作步骤并重播。完整参考:[`docs/source/Zh/doc/new_features/v154_features_doc.rst`](../docs/source/Zh/doc/new_features/v154_features_doc.rst)
6+
7+
- **`record_step` / `to_jsonl` / `from_jsonl` / `replay_trace`**(`AC_replay_trace`):`agent_trace` 记录 OTel span(观测性)、`trajectory_eval` 只评分、`semantic_recording` 重播人类宏——都不是可重播的观测→动作转录。本功能是 OmniTool 风格的 `{step, observation, action, result}` JSONL,加确定性重播驱动器(可注入 `runner`、无需即时模型)。执行器命令透过执行器重播每一步的 AC 动作。纯标准库、可无头测试;可从 agent 执行建立回归 / 训练数据集。
8+
39
## 本次更新 (2026-06-23) — 动作前接地防护
410

511
拒绝越界点击;把接近偏离者吸附到真正的元素。完整参考:[`docs/source/Zh/doc/new_features/v153_features_doc.rst`](../docs/source/Zh/doc/new_features/v153_features_doc.rst)

README/WHATS_NEW_zh-TW.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 本次更新 — AutoControl
22

3+
## 本次更新 (2026-06-23) — 可攜式 Agent 軌跡記錄(錄製與重播)
4+
5+
記錄 agent 的觀測→動作步驟並重播。完整參考:[`docs/source/Zh/doc/new_features/v154_features_doc.rst`](../docs/source/Zh/doc/new_features/v154_features_doc.rst)
6+
7+
- **`record_step` / `to_jsonl` / `from_jsonl` / `replay_trace`**(`AC_replay_trace`):`agent_trace` 記錄 OTel span(觀測性)、`trajectory_eval` 只評分、`semantic_recording` 重播人類巨集——都不是可重播的觀測→動作轉錄。本功能是 OmniTool 風格的 `{step, observation, action, result}` JSONL,加決定性重播驅動器(可注入 `runner`、無需即時模型)。執行器命令透過執行器重播每一步的 AC 動作。純標準函式庫、可無頭測試;可從 agent 執行建立回歸 / 訓練資料集。
8+
39
## 本次更新 (2026-06-23) — 動作前接地防護
410

511
拒絕越界點擊;把接近偏離者吸附到真正的元素。完整參考:[`docs/source/Zh/doc/new_features/v153_features_doc.rst`](../docs/source/Zh/doc/new_features/v153_features_doc.rst)

WHATS_NEW.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# What's New — AutoControl
22

3+
## What's new (2026-06-23) — Portable Agent-Trajectory Trace (Record & Replay)
4+
5+
Log an agent's observation→action steps and replay them. Full reference: [`docs/source/Eng/doc/new_features/v154_features_doc.rst`](docs/source/Eng/doc/new_features/v154_features_doc.rst).
6+
7+
- **`record_step` / `to_jsonl` / `from_jsonl` / `replay_trace`** (`AC_replay_trace`): `agent_trace` records OTel spans (observability), `trajectory_eval` only scores, `semantic_recording` replays human macros — none is a replayable obs→action transcript. This is the OmniTool-style `{step, observation, action, result}` JSONL with a deterministic replay driver (injectable `runner`, no live model). The executor command replays each step's AC action through the executor. Pure-stdlib, headless-testable; build regression / training datasets from agent runs.
8+
39
## What's new (2026-06-23) — Pre-Action Grounding Guard
410

511
Reject out-of-bounds clicks; snap near-misses onto the real element. Full reference: [`docs/source/Eng/doc/new_features/v153_features_doc.rst`](docs/source/Eng/doc/new_features/v153_features_doc.rst).
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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**.

docs/source/Eng/eng_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Comprehensive guides for all AutoControl features.
176176
doc/new_features/v151_features_doc
177177
doc/new_features/v152_features_doc
178178
doc/new_features/v153_features_doc
179+
doc/new_features/v154_features_doc
179180
doc/ocr_backends/ocr_backends_doc
180181
doc/observability/observability_doc
181182
doc/operations_layer/operations_layer_doc
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
可攜式 Agent 軌跡記錄(錄製與重播)
2+
====================================
3+
4+
``agent_trace`` 記錄 OpenTelemetry GenAI *span*(符記 / 延遲 / 成本)——那是觀測性,不是可重播的觀測→動作轉錄;
5+
``trajectory_eval`` *評分*軌跡但未定義持久格式也無法重播;``semantic_recording`` 重播錄製的*人類輸入巨集*,而非
6+
*agent* 決策。本功能加入 OmniTool 風格的「記錄軌跡以建立重播 / 訓練資料集」格式:``{step, observation, action,
7+
result}`` JSONL,加上決定性的重播驅動器。
8+
9+
純標準函式庫 JSONL;重播驅動器接受可注入的 ``runner``(無需即時模型),因此完全可單元測試。不匯入 ``PySide6``。
10+
11+
無頭 API
12+
--------
13+
14+
.. code-block:: python
15+
16+
from je_auto_control import record_step, to_jsonl, from_jsonl, replay_trace
17+
18+
trace = []
19+
record_step(trace, observation="login screen",
20+
action=["AC_click_mouse", {"x": 120, "y": 80}])
21+
record_step(trace, observation="typed user", action=["AC_write",
22+
{"write_string": "alice"}], result={"ok": True})
23+
24+
open("run.jsonl", "w").write(to_jsonl(trace)) # 持久化資料集
25+
26+
# 之後——透過任意 runner 重播每一步(此處為測試用 fake)。
27+
results = replay_trace(from_jsonl(open("run.jsonl").read()),
28+
runner=lambda action: do(action))
29+
30+
``record_step`` 附加一個有索引的 ``{step, observation, action[, result]}`` 條目;``to_jsonl`` / ``from_jsonl`` 以
31+
換行分隔 JSON 往返;``replay_trace`` 透過 ``runner(action)`` 執行每一步的 ``action``,並依序回傳
32+
``{step, action, result}`` 結果。
33+
34+
執行器命令
35+
----------
36+
37+
``AC_replay_trace`` 透過執行器執行每一步的 ``action``(AC 動作清單)來重播 ``trace``(JSON 陣列或 JSONL),回傳
38+
``{count, results}``。它以 MCP 工具 ``ac_replay_trace``(有副作用)以及 Script Builder 中 **Flow** 分類下的命令提供。

docs/source/Zh/zh_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ AutoControl 所有功能的完整使用指南。
176176
doc/new_features/v151_features_doc
177177
doc/new_features/v152_features_doc
178178
doc/new_features/v153_features_doc
179+
doc/new_features/v154_features_doc
179180
doc/ocr_backends/ocr_backends_doc
180181
doc/observability/observability_doc
181182
doc/operations_layer/operations_layer_doc

je_auto_control/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@
373373
from je_auto_control.utils.action_grounding import (
374374
in_bounds, snap_to_element, validate_action,
375375
)
376+
# Portable agent-trajectory trace (record observation->action steps, replay)
377+
from je_auto_control.utils.agent_replay import (
378+
from_jsonl, record_step, replay_trace, to_jsonl,
379+
)
376380
# CI workflow annotations (GitHub Actions)
377381
from je_auto_control.utils.ci_annotations import (
378382
emit_annotations, format_annotation,
@@ -1257,6 +1261,10 @@ def start_autocontrol_gui(*args, **kwargs):
12571261
"in_bounds",
12581262
"snap_to_element",
12591263
"validate_action",
1264+
"record_step",
1265+
"to_jsonl",
1266+
"from_jsonl",
1267+
"replay_trace",
12601268
"emit_annotations", "format_annotation",
12611269
"ClipboardHistory", "default_clipboard_history",
12621270
"analyze_heal_log", "heal_stats", "scan_secrets",

je_auto_control/gui/script_builder/command_schema.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,14 @@ def _add_flow_specs(specs: List[CommandSpec]) -> None:
899899
),
900900
description="Aggregate many checks and report all failures (not just first).",
901901
))
902+
specs.append(CommandSpec(
903+
"AC_replay_trace", "Flow", "Replay Agent Trace",
904+
fields=(
905+
FieldSpec("trace", FieldType.STRING,
906+
placeholder='[{"action":["AC_click_mouse",{...}]}]'),
907+
),
908+
description="Replay a recorded trajectory's actions through the executor.",
909+
))
902910
specs.append(CommandSpec(
903911
"AC_wait_pixel", "Flow", "Wait for Pixel",
904912
fields=(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Portable agent-trajectory trace (record observation->action steps, replay)."""
2+
from je_auto_control.utils.agent_replay.agent_replay import (
3+
from_jsonl, record_step, replay_trace, to_jsonl,
4+
)
5+
6+
__all__ = ["from_jsonl", "record_step", "replay_trace", "to_jsonl"]

0 commit comments

Comments
 (0)