@beeos-ai/device-agent 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/adapters/agent-gateway-client.d.ts +6 -68
- package/dist/adapters/agent-gateway-client.js +7 -67
- package/dist/adapters/agent-gateway-client.js.map +1 -1
- package/dist/adapters/device-compat.d.ts +1 -2
- package/dist/adapters/device-compat.js +2 -52
- package/dist/adapters/device-compat.js.map +1 -1
- package/dist/agent-runtime/action-guard.js +92 -17
- package/dist/agent-runtime/action-guard.js.map +1 -1
- package/dist/agent-runtime/adapters/base.d.ts +13 -9
- package/dist/agent-runtime/adapters/base.js.map +1 -1
- package/dist/agent-runtime/adapters/general-flash.d.ts +3 -3
- package/dist/agent-runtime/adapters/general-flash.js +2 -2
- package/dist/agent-runtime/adapters/general-flash.js.map +1 -1
- package/dist/agent-runtime/adapters/native-tools.d.ts +56 -0
- package/dist/agent-runtime/adapters/native-tools.js +416 -0
- package/dist/agent-runtime/adapters/native-tools.js.map +1 -0
- package/dist/agent-runtime/adapters/openai.d.ts +1 -2
- package/dist/agent-runtime/adapters/openai.js +5 -5
- package/dist/agent-runtime/adapters/openai.js.map +1 -1
- package/dist/agent-runtime/adapters/pro.d.ts +7 -37
- package/dist/agent-runtime/adapters/pro.js +7 -249
- package/dist/agent-runtime/adapters/pro.js.map +1 -1
- package/dist/agent-runtime/advanced/app-card.js +9 -2
- package/dist/agent-runtime/advanced/app-card.js.map +1 -1
- package/dist/agent-runtime/advanced/subgoal-verifier.d.ts +1 -0
- package/dist/agent-runtime/advanced/subgoal-verifier.js +30 -36
- package/dist/agent-runtime/advanced/subgoal-verifier.js.map +1 -1
- package/dist/agent-runtime/advanced/task-state.js +4 -9
- package/dist/agent-runtime/advanced/task-state.js.map +1 -1
- package/dist/agent-runtime/agent-runner.d.ts +2 -11
- package/dist/agent-runtime/agent-runner.js +69 -34
- package/dist/agent-runtime/agent-runner.js.map +1 -1
- package/dist/agent-runtime/core.d.ts +24 -46
- package/dist/agent-runtime/core.js +161 -228
- package/dist/agent-runtime/core.js.map +1 -1
- package/dist/agent-runtime/execution-checks.d.ts +40 -0
- package/dist/agent-runtime/execution-checks.js +133 -0
- package/dist/agent-runtime/execution-checks.js.map +1 -0
- package/dist/agent-runtime/execution-mode.d.ts +1 -8
- package/dist/agent-runtime/execution-mode.js +10 -30
- package/dist/agent-runtime/execution-mode.js.map +1 -1
- package/dist/agent-runtime/feedback.d.ts +4 -28
- package/dist/agent-runtime/feedback.js +4 -26
- package/dist/agent-runtime/feedback.js.map +1 -1
- package/dist/agent-runtime/form-prerequisites.d.ts +3 -0
- package/dist/agent-runtime/form-prerequisites.js +52 -0
- package/dist/agent-runtime/form-prerequisites.js.map +1 -0
- package/dist/agent-runtime/index.d.ts +2 -8
- package/dist/agent-runtime/index.js +2 -8
- package/dist/agent-runtime/index.js.map +1 -1
- package/dist/agent-runtime/{modes/orchestrator → knowledge}/app-guide.d.ts +1 -1
- package/dist/agent-runtime/{modes/orchestrator → knowledge}/app-guide.js +1 -1
- package/dist/agent-runtime/knowledge/app-guide.js.map +1 -0
- package/dist/agent-runtime/models/base.d.ts +3 -1
- package/dist/agent-runtime/models/client.js +30 -9
- package/dist/agent-runtime/models/client.js.map +1 -1
- package/dist/agent-runtime/models/reasoning.d.ts +10 -0
- package/dist/agent-runtime/models/reasoning.js +29 -0
- package/dist/agent-runtime/models/reasoning.js.map +1 -0
- package/dist/agent-runtime/models/runtime-registry.d.ts +2 -1
- package/dist/agent-runtime/models/runtime-registry.js +4 -2
- package/dist/agent-runtime/models/runtime-registry.js.map +1 -1
- package/dist/agent-runtime/models/vlm/autoglm.js +6 -2
- package/dist/agent-runtime/models/vlm/autoglm.js.map +1 -1
- package/dist/agent-runtime/models/vlm/base.js +1 -12
- package/dist/agent-runtime/models/vlm/base.js.map +1 -1
- package/dist/agent-runtime/models/vlm/index.d.ts +0 -4
- package/dist/agent-runtime/models/vlm/index.js +0 -4
- package/dist/agent-runtime/models/vlm/index.js.map +1 -1
- package/dist/agent-runtime/modes/hybrid/index.d.ts +2 -12
- package/dist/agent-runtime/modes/hybrid/index.js +10 -27
- package/dist/agent-runtime/modes/hybrid/index.js.map +1 -1
- package/dist/agent-runtime/modes/hybrid/planner/base.d.ts +4 -44
- package/dist/agent-runtime/modes/hybrid/planner/base.js +3 -21
- package/dist/agent-runtime/modes/hybrid/planner/base.js.map +1 -1
- package/dist/agent-runtime/modes/hybrid/planner/llm-planner.d.ts +1 -1
- package/dist/agent-runtime/modes/hybrid/planner/llm-planner.js +9 -6
- package/dist/agent-runtime/modes/hybrid/planner/llm-planner.js.map +1 -1
- package/dist/agent-runtime/modes/hybrid/planner/prompts.d.ts +1 -17
- package/dist/agent-runtime/modes/hybrid/planner/prompts.js +65 -160
- package/dist/agent-runtime/modes/hybrid/planner/prompts.js.map +1 -1
- package/dist/agent-runtime/plan-executor.d.ts +13 -14
- package/dist/agent-runtime/plan-executor.js +236 -122
- package/dist/agent-runtime/plan-executor.js.map +1 -1
- package/dist/agent-runtime/pro-memory.js +1 -1
- package/dist/agent-runtime/pro-memory.js.map +1 -1
- package/dist/agent-runtime/pro-operator.js +8 -2
- package/dist/agent-runtime/pro-operator.js.map +1 -1
- package/dist/agent-runtime/pro-perception.d.ts +1 -0
- package/dist/agent-runtime/pro-perception.js +4 -2
- package/dist/agent-runtime/pro-perception.js.map +1 -1
- package/dist/agent-runtime/pro-target-check.d.ts +2 -2
- package/dist/agent-runtime/pro-target-check.js +102 -17
- package/dist/agent-runtime/pro-target-check.js.map +1 -1
- package/dist/agent-runtime/prompts/operator.d.ts +2 -0
- package/dist/agent-runtime/prompts/operator.js +69 -0
- package/dist/agent-runtime/prompts/operator.js.map +1 -0
- package/dist/agent-runtime/prompts/verification.d.ts +2 -0
- package/dist/agent-runtime/prompts/verification.js +52 -0
- package/dist/agent-runtime/prompts/verification.js.map +1 -0
- package/dist/agent-runtime/skills/replay.d.ts +4 -14
- package/dist/agent-runtime/skills/replay.js +46 -27
- package/dist/agent-runtime/skills/replay.js.map +1 -1
- package/dist/agent-runtime/tool-batch.d.ts +10 -0
- package/dist/agent-runtime/tool-batch.js +51 -0
- package/dist/agent-runtime/tool-batch.js.map +1 -0
- package/dist/agent-runtime/visual-state.d.ts +2 -0
- package/dist/agent-runtime/visual-state.js +24 -0
- package/dist/agent-runtime/visual-state.js.map +1 -0
- package/dist/agent-runtime/vlm.d.ts +1 -1
- package/dist/agent-runtime/vlm.js +1 -1
- package/dist/api.js +3 -1
- package/dist/api.js.map +1 -1
- package/dist/app/agent-host.js +6 -2
- package/dist/app/agent-host.js.map +1 -1
- package/dist/app/multi-device-host.js +4 -5
- package/dist/app/multi-device-host.js.map +1 -1
- package/dist/app/session-manager.d.ts +3 -45
- package/dist/app/session-manager.js +8 -9
- package/dist/app/session-manager.js.map +1 -1
- package/dist/bootstrap.js +25 -84
- package/dist/bootstrap.js.map +1 -1
- package/dist/config/loader.js +12 -1
- package/dist/config/loader.js.map +1 -1
- package/dist/config/schema.d.ts +7 -2
- package/dist/config/schema.js +8 -5
- package/dist/config/schema.js.map +1 -1
- package/dist/core/abortable-read.d.ts +1 -0
- package/dist/core/abortable-read.js +24 -0
- package/dist/core/abortable-read.js.map +1 -0
- package/dist/device/ui-xml.d.ts +4 -0
- package/dist/device/ui-xml.js +35 -13
- package/dist/device/ui-xml.js.map +1 -1
- package/dist/fleet/adapters/process/node-process-manager.d.ts +2 -1
- package/dist/fleet/adapters/process/node-process-manager.js +11 -19
- package/dist/fleet/adapters/process/node-process-manager.js.map +1 -1
- package/dist/inbound/acp/handlers/models.js +11 -8
- package/dist/inbound/acp/handlers/models.js.map +1 -1
- package/dist/inbound/acp/handlers/session.d.ts +1 -4
- package/dist/inbound/acp/handlers/session.js +3 -6
- package/dist/inbound/acp/handlers/session.js.map +1 -1
- package/dist/inbound/bma/agent.d.ts +47 -0
- package/dist/inbound/bma/agent.js +130 -0
- package/dist/inbound/bma/agent.js.map +1 -0
- package/dist/inbound/bma/command.d.ts +15 -0
- package/dist/inbound/bma/command.js +98 -0
- package/dist/inbound/bma/command.js.map +1 -0
- package/dist/inbound/bma/model-proxy.d.ts +22 -0
- package/dist/inbound/bma/model-proxy.js +130 -0
- package/dist/inbound/bma/model-proxy.js.map +1 -0
- package/dist/inbound/cli/main.js +12 -2
- package/dist/inbound/cli/main.js.map +1 -1
- package/dist/inbound/cli/run-artifacts.js +16 -7
- package/dist/inbound/cli/run-artifacts.js.map +1 -1
- package/dist/inbound/cli/run-command.d.ts +7 -0
- package/dist/inbound/cli/run-command.js +37 -29
- package/dist/inbound/cli/run-command.js.map +1 -1
- package/dist/index.d.ts +1 -10
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/mcp-client/autospawn.d.ts +7 -9
- package/dist/mcp-client/autospawn.js +16 -12
- package/dist/mcp-client/autospawn.js.map +1 -1
- package/dist/mcp-client/client.d.ts +6 -3
- package/dist/mcp-client/client.js +31 -13
- package/dist/mcp-client/client.js.map +1 -1
- package/dist/mcp-client/runtime.d.ts +5 -2
- package/dist/plugins/agent-sync/index.d.ts +32 -17
- package/dist/plugins/agent-sync/index.js +223 -232
- package/dist/plugins/agent-sync/index.js.map +1 -1
- package/dist/plugins/message-bus/inbound.d.ts +0 -32
- package/dist/plugins/message-bus/inbound.js +3 -0
- package/dist/plugins/message-bus/inbound.js.map +1 -1
- package/dist/plugins/message-bus/ms-channel-notifier.d.ts +1 -0
- package/dist/plugins/message-bus/ms-channel-notifier.js +16 -8
- package/dist/plugins/message-bus/ms-channel-notifier.js.map +1 -1
- package/dist/plugins/native-chat/deadline.d.ts +2 -0
- package/dist/plugins/native-chat/deadline.js +16 -0
- package/dist/plugins/native-chat/deadline.js.map +1 -0
- package/dist/plugins/native-chat/index.d.ts +46 -0
- package/dist/plugins/native-chat/index.js +331 -0
- package/dist/plugins/native-chat/index.js.map +1 -0
- package/dist/plugins/native-chat/reply-stream.d.ts +50 -0
- package/dist/plugins/native-chat/reply-stream.js +81 -0
- package/dist/plugins/native-chat/reply-stream.js.map +1 -0
- package/dist/plugins/native-chat/session-notifier.d.ts +16 -0
- package/dist/plugins/native-chat/session-notifier.js +130 -0
- package/dist/plugins/native-chat/session-notifier.js.map +1 -0
- package/dist/ports/agent-core.d.ts +2 -0
- package/dist/ports/agent-host.d.ts +2 -0
- package/dist/ports/agent-host.js +0 -21
- package/dist/ports/agent-host.js.map +1 -1
- package/dist/ports/device.d.ts +0 -1
- package/dist/ports/device.js +0 -1
- package/dist/ports/device.js.map +1 -1
- package/dist/runtime-authority/device-prompt.gen.d.ts +54 -0
- package/dist/runtime-authority/device-prompt.gen.js +19 -0
- package/dist/runtime-authority/device-prompt.gen.js.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +5 -3
- package/dist/adapters/device-desktop.d.ts +0 -49
- package/dist/adapters/device-desktop.js +0 -132
- package/dist/adapters/device-desktop.js.map +0 -1
- package/dist/agent-runtime/factory.d.ts +0 -24
- package/dist/agent-runtime/factory.js +0 -25
- package/dist/agent-runtime/factory.js.map +0 -1
- package/dist/agent-runtime/models/vlm/guiowl.d.ts +0 -1
- package/dist/agent-runtime/models/vlm/guiowl.js +0 -249
- package/dist/agent-runtime/models/vlm/guiowl.js.map +0 -1
- package/dist/agent-runtime/models/vlm/maiui.d.ts +0 -1
- package/dist/agent-runtime/models/vlm/maiui.js +0 -142
- package/dist/agent-runtime/models/vlm/maiui.js.map +0 -1
- package/dist/agent-runtime/models/vlm/qwen38.d.ts +0 -1
- package/dist/agent-runtime/models/vlm/qwen38.js +0 -241
- package/dist/agent-runtime/models/vlm/qwen38.js.map +0 -1
- package/dist/agent-runtime/models/vlm/qwenvl.d.ts +0 -1
- package/dist/agent-runtime/models/vlm/qwenvl.js +0 -202
- package/dist/agent-runtime/models/vlm/qwenvl.js.map +0 -1
- package/dist/agent-runtime/modes/orchestrator/app-guide.js.map +0 -1
- package/dist/agent-runtime/modes/orchestrator/index.d.ts +0 -41
- package/dist/agent-runtime/modes/orchestrator/index.js +0 -218
- package/dist/agent-runtime/modes/orchestrator/index.js.map +0 -1
- package/dist/agent-runtime/modes/orchestrator/prompt.d.ts +0 -7
- package/dist/agent-runtime/modes/orchestrator/prompt.js +0 -53
- package/dist/agent-runtime/modes/orchestrator/prompt.js.map +0 -1
- package/dist/agent-runtime/reflection.d.ts +0 -100
- package/dist/agent-runtime/reflection.js +0 -241
- package/dist/agent-runtime/reflection.js.map +0 -1
- package/dist/agent-runtime/reflectors/action-reflector.d.ts +0 -97
- package/dist/agent-runtime/reflectors/action-reflector.js +0 -234
- package/dist/agent-runtime/reflectors/action-reflector.js.map +0 -1
- package/dist/agent-runtime/reflectors/policy.d.ts +0 -56
- package/dist/agent-runtime/reflectors/policy.js +0 -111
- package/dist/agent-runtime/reflectors/policy.js.map +0 -1
- package/dist/agent-runtime/reflectors/trajectory-reflector.d.ts +0 -93
- package/dist/agent-runtime/reflectors/trajectory-reflector.js +0 -224
- package/dist/agent-runtime/reflectors/trajectory-reflector.js.map +0 -1
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* agent-runtime/reflection — hierarchical reflection layer for AgentLoop.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors the Python reference at
|
|
5
|
-
* /Users/heat/workspace/deviceagent_research/deviceagent/agent_runtime/loop/reflection.py
|
|
6
|
-
*
|
|
7
|
-
* Phase-1 reflector is heuristic-only (cheap):
|
|
8
|
-
* - **Action reflection** — 4 identical actions in a row → stall.
|
|
9
|
-
* - **Trajectory reflection** — ≥5 screenshots in the last 6 steps → stall
|
|
10
|
-
* (the model is staring at the screen instead of acting).
|
|
11
|
-
* - **Pre-action sanity** — block obviously-broken `nextAction` candidates
|
|
12
|
-
* *before* dispatch (zero-cost; mirrors mobile-use `enable_pre_reflection`).
|
|
13
|
-
* - **Model-based action reflection** is plumbed via `IActionReflector` —
|
|
14
|
-
* composed by AgentLoop after `act()` returns, gated by confidence /
|
|
15
|
-
* `actionResult` so the heuristic layer fires first.
|
|
16
|
-
*/
|
|
17
|
-
import type { Action } from "@beeos-ai/device-common";
|
|
18
|
-
import type { IActionReflector } from "./reflectors/action-reflector.js";
|
|
19
|
-
import type { ITrajectoryReflector } from "./reflectors/trajectory-reflector.js";
|
|
20
|
-
import type { IModelAdapter, StepHistory } from "./adapters/base.js";
|
|
21
|
-
/**
|
|
22
|
-
* Veto reason returned by {@link HierarchicalReflector.maybeBlockAction}.
|
|
23
|
-
* - `reason` — short human-readable string, copied into the next StepHistory
|
|
24
|
-
* rationale so the grounder sees *why* its previous attempt was blocked.
|
|
25
|
-
* - `code` — stable identifier for telemetry / metrics tagging.
|
|
26
|
-
*
|
|
27
|
-
* `no_progress_repeat` is the hash-aware successor to
|
|
28
|
-
* `double_tap_same_coords` — emitted when {@link StepHistory.screenStateHashBefore}
|
|
29
|
-
* equals {@link StepHistory.screenStateHashAfter} (i.e. the previous
|
|
30
|
-
* action did not change the screen) and the next action is a near-repeat
|
|
31
|
-
* of it. The legacy `double_tap_same_coords` code is preserved as the
|
|
32
|
-
* fallback for pure-vision adapters that don't produce a `uiDump` hash.
|
|
33
|
-
*/
|
|
34
|
-
export interface PreActionVeto {
|
|
35
|
-
code: "double_type_without_focus" | "double_tap_same_coords" | "no_progress_repeat" | "blind_swipe" | "vlm_emitted_shell";
|
|
36
|
-
reason: string;
|
|
37
|
-
}
|
|
38
|
-
export interface HierarchicalReflectorOptions {
|
|
39
|
-
/** Optional VLM adapter — reserved for future model-based reflection hooks. */
|
|
40
|
-
adapter?: IModelAdapter;
|
|
41
|
-
/**
|
|
42
|
-
* Optional model-based reflector composed after `act()` returns. AgentLoop
|
|
43
|
-
* calls `actionReflector?.shouldReflect(...)` first; the heuristic veto
|
|
44
|
-
* still runs before any model invocation.
|
|
45
|
-
*/
|
|
46
|
-
actionReflector?: IActionReflector;
|
|
47
|
-
/**
|
|
48
|
-
* Optional trajectory reflector (Phase 2.2). AgentLoop fires it every N
|
|
49
|
-
* steps to assess global progress; bail-out verdicts (`off_track` /
|
|
50
|
-
* `stuck`) are converted into a reflection veto so the PlanExecutor can
|
|
51
|
-
* trigger a replan.
|
|
52
|
-
*/
|
|
53
|
-
trajectoryReflector?: ITrajectoryReflector;
|
|
54
|
-
}
|
|
55
|
-
export declare class HierarchicalReflector {
|
|
56
|
-
private readonly adapter?;
|
|
57
|
-
readonly actionReflector?: IActionReflector;
|
|
58
|
-
readonly trajectoryReflector?: ITrajectoryReflector;
|
|
59
|
-
constructor(adapterOrOptions?: IModelAdapter | HierarchicalReflectorOptions);
|
|
60
|
-
/**
|
|
61
|
-
* Returns a non-empty veto reason when the loop should stop, or `null` if
|
|
62
|
-
* the run is healthy and may continue.
|
|
63
|
-
*/
|
|
64
|
-
maybeVeto(history: StepHistory[], step: number, _maxSteps: number): string | null;
|
|
65
|
-
/**
|
|
66
|
-
* Pre-action sanity — block obviously-broken `nextAction` candidates
|
|
67
|
-
* **before** AgentLoop dispatches them to MCP. Returns a veto when the
|
|
68
|
-
* action looks like a known-bad pattern; the AgentLoop should then skip
|
|
69
|
-
* the dispatch and record the step with `actionResult: "skipped"`.
|
|
70
|
-
*
|
|
71
|
-
* Rules (cover ~80% of common grounder mistakes — see plan Task 1.3):
|
|
72
|
-
* 1. Two consecutive `type` actions with no intervening `tap` /
|
|
73
|
-
* `long_press` → focus probably wasn't established (mobile-use
|
|
74
|
-
* `pre_reflection` rule).
|
|
75
|
-
* 2. Two consecutive `tap` actions that produced no screen change.
|
|
76
|
-
* Hash-aware: when {@link StepHistory.screenStateHashBefore} ===
|
|
77
|
-
* {@link StepHistory.screenStateHashAfter} on the previous step,
|
|
78
|
-
* the action evidently did nothing, so a repeat (within 24 px) is
|
|
79
|
-
* futile — emit `no_progress_repeat`. Pure-vision adapters with no
|
|
80
|
-
* hash fall back to the legacy 8 px `double_tap_same_coords` rule.
|
|
81
|
-
* 3. Two consecutive `swipe` actions in the same direction without an
|
|
82
|
-
* intervening `screenshot` → blind scrolling without re-grounding.
|
|
83
|
-
* 4. The grounder emitted `execute_command` (the VLM should never
|
|
84
|
-
* produce shell). This is exactly the "Baidu image" failure mode
|
|
85
|
-
* that motivated this rule set.
|
|
86
|
-
*
|
|
87
|
-
* Hash guard (applies to rules 1 / 2 / 3): when we have a `uiDump`-
|
|
88
|
-
* derived `screenStateHashBefore` AND a `screenStateHashAfter` for the
|
|
89
|
-
* previous step AND they differ, the previous action evidently
|
|
90
|
-
* produced screen progress, so we let the next action through even if
|
|
91
|
-
* it superficially repeats the prior one. This eliminates the "model
|
|
92
|
-
* tried again with a tiny perturbation but the screen actually
|
|
93
|
-
* advanced" false-positive that motivated the KISS hardening pass.
|
|
94
|
-
*
|
|
95
|
-
* Heuristics are conservative — when in doubt, return `null` (let the
|
|
96
|
-
* action through). Repeated stalls are still caught by `maybeVeto`.
|
|
97
|
-
*/
|
|
98
|
-
maybeBlockAction(history: StepHistory[], nextAction: Action): PreActionVeto | null;
|
|
99
|
-
}
|
|
100
|
-
export declare function actionsEqual(a: Action, b: Action): boolean;
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* agent-runtime/reflection — hierarchical reflection layer for AgentLoop.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors the Python reference at
|
|
5
|
-
* /Users/heat/workspace/deviceagent_research/deviceagent/agent_runtime/loop/reflection.py
|
|
6
|
-
*
|
|
7
|
-
* Phase-1 reflector is heuristic-only (cheap):
|
|
8
|
-
* - **Action reflection** — 4 identical actions in a row → stall.
|
|
9
|
-
* - **Trajectory reflection** — ≥5 screenshots in the last 6 steps → stall
|
|
10
|
-
* (the model is staring at the screen instead of acting).
|
|
11
|
-
* - **Pre-action sanity** — block obviously-broken `nextAction` candidates
|
|
12
|
-
* *before* dispatch (zero-cost; mirrors mobile-use `enable_pre_reflection`).
|
|
13
|
-
* - **Model-based action reflection** is plumbed via `IActionReflector` —
|
|
14
|
-
* composed by AgentLoop after `act()` returns, gated by confidence /
|
|
15
|
-
* `actionResult` so the heuristic layer fires first.
|
|
16
|
-
*/
|
|
17
|
-
export class HierarchicalReflector {
|
|
18
|
-
adapter;
|
|
19
|
-
actionReflector;
|
|
20
|
-
trajectoryReflector;
|
|
21
|
-
constructor(adapterOrOptions) {
|
|
22
|
-
if (adapterOrOptions && "name" in adapterOrOptions) {
|
|
23
|
-
this.adapter = adapterOrOptions;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const opts = adapterOrOptions ?? {};
|
|
27
|
-
this.adapter = opts.adapter;
|
|
28
|
-
this.actionReflector = opts.actionReflector;
|
|
29
|
-
this.trajectoryReflector = opts.trajectoryReflector;
|
|
30
|
-
}
|
|
31
|
-
void this.adapter; // reserved for future model-based reflection
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns a non-empty veto reason when the loop should stop, or `null` if
|
|
35
|
-
* the run is healthy and may continue.
|
|
36
|
-
*/
|
|
37
|
-
maybeVeto(history, step, _maxSteps) {
|
|
38
|
-
if (step <= 2 || history.length === 0)
|
|
39
|
-
return null;
|
|
40
|
-
const last = history[history.length - 1].action;
|
|
41
|
-
if (!last)
|
|
42
|
-
return null;
|
|
43
|
-
// Action reflection — 4 identical actions in a row.
|
|
44
|
-
const recent = history
|
|
45
|
-
.slice(-4)
|
|
46
|
-
.map((h) => h.action)
|
|
47
|
-
.filter((a) => a !== null);
|
|
48
|
-
if (recent.length === 4 && recent.every((a) => actionsEqual(a, recent[0]))) {
|
|
49
|
-
return `stalled: action ${recent[0].type} repeated 4 consecutive times`;
|
|
50
|
-
}
|
|
51
|
-
// [已弃用] screenshot-heavy stall 检测:连续6步中有5个 screenshot 动作时终止。
|
|
52
|
-
// 当前所有适配器(autoglm、general 等)截图均由 AgentLoop 被动触发,
|
|
53
|
-
// 模型不会主动发出 screenshot 动作,此规则永远不会触发,故弃用。
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Pre-action sanity — block obviously-broken `nextAction` candidates
|
|
58
|
-
* **before** AgentLoop dispatches them to MCP. Returns a veto when the
|
|
59
|
-
* action looks like a known-bad pattern; the AgentLoop should then skip
|
|
60
|
-
* the dispatch and record the step with `actionResult: "skipped"`.
|
|
61
|
-
*
|
|
62
|
-
* Rules (cover ~80% of common grounder mistakes — see plan Task 1.3):
|
|
63
|
-
* 1. Two consecutive `type` actions with no intervening `tap` /
|
|
64
|
-
* `long_press` → focus probably wasn't established (mobile-use
|
|
65
|
-
* `pre_reflection` rule).
|
|
66
|
-
* 2. Two consecutive `tap` actions that produced no screen change.
|
|
67
|
-
* Hash-aware: when {@link StepHistory.screenStateHashBefore} ===
|
|
68
|
-
* {@link StepHistory.screenStateHashAfter} on the previous step,
|
|
69
|
-
* the action evidently did nothing, so a repeat (within 24 px) is
|
|
70
|
-
* futile — emit `no_progress_repeat`. Pure-vision adapters with no
|
|
71
|
-
* hash fall back to the legacy 8 px `double_tap_same_coords` rule.
|
|
72
|
-
* 3. Two consecutive `swipe` actions in the same direction without an
|
|
73
|
-
* intervening `screenshot` → blind scrolling without re-grounding.
|
|
74
|
-
* 4. The grounder emitted `execute_command` (the VLM should never
|
|
75
|
-
* produce shell). This is exactly the "Baidu image" failure mode
|
|
76
|
-
* that motivated this rule set.
|
|
77
|
-
*
|
|
78
|
-
* Hash guard (applies to rules 1 / 2 / 3): when we have a `uiDump`-
|
|
79
|
-
* derived `screenStateHashBefore` AND a `screenStateHashAfter` for the
|
|
80
|
-
* previous step AND they differ, the previous action evidently
|
|
81
|
-
* produced screen progress, so we let the next action through even if
|
|
82
|
-
* it superficially repeats the prior one. This eliminates the "model
|
|
83
|
-
* tried again with a tiny perturbation but the screen actually
|
|
84
|
-
* advanced" false-positive that motivated the KISS hardening pass.
|
|
85
|
-
*
|
|
86
|
-
* Heuristics are conservative — when in doubt, return `null` (let the
|
|
87
|
-
* action through). Repeated stalls are still caught by `maybeVeto`.
|
|
88
|
-
*/
|
|
89
|
-
maybeBlockAction(history, nextAction) {
|
|
90
|
-
if (!nextAction)
|
|
91
|
-
return null;
|
|
92
|
-
// Rule 4 — VLM emitted shell. Always block, regardless of hash data.
|
|
93
|
-
if (nextAction.type === "execute_command") {
|
|
94
|
-
return {
|
|
95
|
-
code: "vlm_emitted_shell",
|
|
96
|
-
reason: "grounder emitted execute_command — VLMs should never produce shell; planner should route shell via tools",
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
if (history.length === 0)
|
|
100
|
-
return null;
|
|
101
|
-
const prev = lastNonNullStep(history);
|
|
102
|
-
if (!prev)
|
|
103
|
-
return null;
|
|
104
|
-
// Hash guard — if we KNOW the previous action moved the screen, skip
|
|
105
|
-
// every "no progress" check below. Absent hash data we fall back to
|
|
106
|
-
// the legacy coordinate / direction heuristics so pure-vision
|
|
107
|
-
// adapters (Open-AutoGLM, UI-TARS) keep working.
|
|
108
|
-
const haveHash = prev.entry.screenStateHashBefore !== undefined &&
|
|
109
|
-
prev.entry.screenStateHashAfter !== undefined;
|
|
110
|
-
const screenChanged = haveHash && prev.entry.screenStateHashBefore !== prev.entry.screenStateHashAfter;
|
|
111
|
-
const screenUnchanged = haveHash && prev.entry.screenStateHashBefore === prev.entry.screenStateHashAfter;
|
|
112
|
-
// Rule 1 — double-type without re-focus. If the previous `type`
|
|
113
|
-
// visibly altered the screen (e.g. text actually appeared), don't
|
|
114
|
-
// block; the grounder may legitimately want to keep typing.
|
|
115
|
-
// Rule 1 — 仅当两次 type 内容完全相同时才触发(重复卡死)。
|
|
116
|
-
// 原逻辑依赖 !screenChanged,无 hash 时永远为 true,会误杀合法的追加输入。
|
|
117
|
-
if (nextAction.type === "type" &&
|
|
118
|
-
prev.action.type === "type" &&
|
|
119
|
-
nextAction.payload.text ===
|
|
120
|
-
prev.action.payload.text) {
|
|
121
|
-
return {
|
|
122
|
-
code: "double_type_without_focus",
|
|
123
|
-
reason: "two consecutive `type` actions with identical text — likely a stuck loop, focus probably wasn't established",
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
// Rule 2 — repeated tap.
|
|
127
|
-
// * with hash data: only block when the prior tap produced ZERO
|
|
128
|
-
// screen change (`no_progress_repeat`). Tolerance widens to 24 px
|
|
129
|
-
// because the model often nudges the tap by a few pixels on
|
|
130
|
-
// retry without changing semantics.
|
|
131
|
-
// * without hash data: legacy 8 px `double_tap_same_coords` rule.
|
|
132
|
-
if (nextAction.type === "tap" &&
|
|
133
|
-
prev.action.type === "tap" &&
|
|
134
|
-
isPointTarget(nextAction.target) &&
|
|
135
|
-
isPointTarget(prev.action.target)) {
|
|
136
|
-
const dx = Math.abs(nextAction.target.x - prev.action.target.x);
|
|
137
|
-
const dy = Math.abs(nextAction.target.y - prev.action.target.y);
|
|
138
|
-
if (haveHash) {
|
|
139
|
-
if (screenUnchanged && dx <= 24 && dy <= 24) {
|
|
140
|
-
return {
|
|
141
|
-
code: "no_progress_repeat",
|
|
142
|
-
reason: `repeated tap near (${prev.action.target.x},${prev.action.target.y}) — previous tap produced no screen change`,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
// hash known + screen progressed (or coords too far apart) → allow
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
// legacy fallback for pure-vision adapters — 此阶段暂不开启(无 hash 数据时对 autoglm 等纯视觉适配器过于激进)
|
|
149
|
-
// if (dx <= 8 && dy <= 8) {
|
|
150
|
-
// return {
|
|
151
|
-
// code: "double_tap_same_coords",
|
|
152
|
-
// reason: `two consecutive tap on (${prev.action.target.x},${prev.action.target.y}) → looks like a misclassified double_tap`,
|
|
153
|
-
// };
|
|
154
|
-
// }
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
// [已弃用] Rule 3 — blind_swipe:连续同向 swipe 且中间无 screenshot 时触发。
|
|
158
|
-
// 依赖 !screenChanged,无 hash 时永远为 true,会误杀合法的连续滚动操作。
|
|
159
|
-
// AgentLoop 被动截图不计入 sawScreenshotBetween,导致条件永远满足,故弃用。
|
|
160
|
-
// if (
|
|
161
|
-
// nextAction.type === "swipe" &&
|
|
162
|
-
// prev.action.type === "swipe" &&
|
|
163
|
-
// isBoxTarget(nextAction.target) &&
|
|
164
|
-
// isBoxTarget(prev.action.target) &&
|
|
165
|
-
// !screenChanged
|
|
166
|
-
// ) {
|
|
167
|
-
// const sameDir =
|
|
168
|
-
// sign(nextAction.target.x2 - nextAction.target.x1) ===
|
|
169
|
-
// sign(prev.action.target.x2 - prev.action.target.x1) &&
|
|
170
|
-
// sign(nextAction.target.y2 - nextAction.target.y1) ===
|
|
171
|
-
// sign(prev.action.target.y2 - prev.action.target.y1);
|
|
172
|
-
// const sawScreenshotBetween = anyActionBetween(
|
|
173
|
-
// history,
|
|
174
|
-
// prev.idx,
|
|
175
|
-
// history.length,
|
|
176
|
-
// (a) => a.type === "screenshot",
|
|
177
|
-
// );
|
|
178
|
-
// if (sameDir && !sawScreenshotBetween) {
|
|
179
|
-
// return {
|
|
180
|
-
// code: "blind_swipe",
|
|
181
|
-
// reason:
|
|
182
|
-
// "swipe in the same direction as the previous step with no intervening screenshot or scroll progress — re-ground before scrolling further",
|
|
183
|
-
// };
|
|
184
|
-
// }
|
|
185
|
-
// }
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/* -------------------------------------------------------------------------- */
|
|
190
|
-
/* helpers */
|
|
191
|
-
/* -------------------------------------------------------------------------- */
|
|
192
|
-
export function actionsEqual(a, b) {
|
|
193
|
-
if (a.type !== b.type)
|
|
194
|
-
return false;
|
|
195
|
-
if (!targetsEqual(a.target, b.target))
|
|
196
|
-
return false;
|
|
197
|
-
return jsonEquals(a.payload, b.payload);
|
|
198
|
-
}
|
|
199
|
-
function targetsEqual(a, b) {
|
|
200
|
-
if (!a && !b)
|
|
201
|
-
return true;
|
|
202
|
-
if (!a || !b)
|
|
203
|
-
return false;
|
|
204
|
-
if (a.kind !== b.kind)
|
|
205
|
-
return false;
|
|
206
|
-
return jsonEquals(a, b);
|
|
207
|
-
}
|
|
208
|
-
function jsonEquals(a, b) {
|
|
209
|
-
if (Object.is(a, b))
|
|
210
|
-
return true;
|
|
211
|
-
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null)
|
|
212
|
-
return false;
|
|
213
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
214
|
-
}
|
|
215
|
-
function isPointTarget(t) {
|
|
216
|
-
return !!t && t.kind === "point";
|
|
217
|
-
}
|
|
218
|
-
function isBoxTarget(t) {
|
|
219
|
-
return !!t && t.kind === "box";
|
|
220
|
-
}
|
|
221
|
-
function sign(n) {
|
|
222
|
-
return n > 0 ? 1 : n < 0 ? -1 : 0;
|
|
223
|
-
}
|
|
224
|
-
function lastNonNullStep(history) {
|
|
225
|
-
for (let i = history.length - 1; i >= 0; i--) {
|
|
226
|
-
const entry = history[i];
|
|
227
|
-
const a = entry.action;
|
|
228
|
-
if (a)
|
|
229
|
-
return { idx: i, entry, action: a };
|
|
230
|
-
}
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
function anyActionBetween(history, startExclusive, endExclusive, pred) {
|
|
234
|
-
for (let i = startExclusive + 1; i < endExclusive; i++) {
|
|
235
|
-
const a = history[i].action;
|
|
236
|
-
if (a && pred(a))
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
//# sourceMappingURL=reflection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reflection.js","sourceRoot":"","sources":["../../src/agent-runtime/reflection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAiDH,MAAM,OAAO,qBAAqB;IACf,OAAO,CAAiB;IAChC,eAAe,CAAoB;IACnC,mBAAmB,CAAwB;IAEpD,YAAY,gBAA+D;QACzE,IAAI,gBAAgB,IAAI,MAAM,IAAK,gBAAkC,EAAE,CAAC;YACtE,IAAI,CAAC,OAAO,GAAG,gBAAiC,CAAC;QACnD,CAAC;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-
/**
|
|
2
|
-
* agent-runtime/reflectors/action-reflector — model-based action reflection.
|
|
3
|
-
*
|
|
4
|
-
* Phase 1.4 of the device-agent reflector upgrade plan
|
|
5
|
-
* ([../../../../../../.cursor/plans/device-agent-reflector-skills_d5599350.plan.md]).
|
|
6
|
-
*
|
|
7
|
-
* Goal: catch *the same step* the grounder just emitted when it's likely
|
|
8
|
-
* wrong (low confidence, or the MCP `act` failed) and feed back a textual
|
|
9
|
-
* verdict the next predict call can read. Concretely:
|
|
10
|
-
* - heuristic veto (`HierarchicalReflector.maybeVeto`) runs first and
|
|
11
|
-
* terminates the loop with a hard stop on stalls;
|
|
12
|
-
* - if the heuristics are quiet, we ask the action reflector whether to
|
|
13
|
-
* take a closer look. The default {@link LLMActionReflector} fires on
|
|
14
|
-
* `actionResult === "act_failed"` OR on low-confidence predictions
|
|
15
|
-
* OR (as a defensive fallback) on a small whitelist of high-risk verbs
|
|
16
|
-
* so we still help even when the adapter doesn't expose logprobs.
|
|
17
|
-
* - the reflector verdict is **advisory**: a `passed: false` result is
|
|
18
|
-
* spliced into the next StepHistory rationale ("act_failed: …") so the
|
|
19
|
-
* grounder retries with that context. We do NOT terminate the loop —
|
|
20
|
-
* stalls are still the heuristic layer's job.
|
|
21
|
-
*
|
|
22
|
-
* The cost model is documented in
|
|
23
|
-
* `agents/device-agent/docs/reflectors.md` (Phase 2.4). Per-task budget
|
|
24
|
-
* with default config is ≤ 4 cheap text glm-4-flash calls / task, ~600-1200
|
|
25
|
-
* input tokens / 50 output tokens each.
|
|
26
|
-
*/
|
|
27
|
-
import OpenAI from "openai";
|
|
28
|
-
import type { Action } from "@beeos-ai/device-common";
|
|
29
|
-
import type { ModelUsage, Prediction, StepHistory } from "../adapters/base.js";
|
|
30
|
-
/** Verbs that warrant a reflection on Branch C of the logprobs spike. */
|
|
31
|
-
export declare const HIGH_RISK_VERBS: ReadonlySet<Action["type"]>;
|
|
32
|
-
export type ActionReflectorGating = "logprob" | "logprob-degraded" | "whitelist";
|
|
33
|
-
export interface ActionReflectCtx {
|
|
34
|
-
/** Goal of the surrounding task. */
|
|
35
|
-
goal: string;
|
|
36
|
-
/** Up to N previous step entries (most recent last). */
|
|
37
|
-
history: StepHistory[];
|
|
38
|
-
/** The prediction we want to reflect on. */
|
|
39
|
-
prediction: Prediction;
|
|
40
|
-
/** Last observation summary (no base64 — text only). */
|
|
41
|
-
observationSummary: string;
|
|
42
|
-
}
|
|
43
|
-
export interface ActionReflectVerdict {
|
|
44
|
-
/**
|
|
45
|
-
* `true` — reflector agrees with the action; nothing to do.
|
|
46
|
-
* `false` — reflector flagged the action; the AgentLoop should record
|
|
47
|
-
* `act_failed: <reason>` and let the grounder retry.
|
|
48
|
-
*/
|
|
49
|
-
passed: boolean;
|
|
50
|
-
reason: string;
|
|
51
|
-
usage: ModelUsage;
|
|
52
|
-
}
|
|
53
|
-
export interface IActionReflector {
|
|
54
|
-
/**
|
|
55
|
-
* Should the loop invoke {@link reflect} on this prediction? Cheap to
|
|
56
|
-
* call — only returns true on the small subset that warrants the LLM
|
|
57
|
-
* round-trip.
|
|
58
|
-
*/
|
|
59
|
-
shouldReflect(history: StepHistory[], lastPrediction: Prediction, actionResult: StepHistory["actionResult"]): boolean;
|
|
60
|
-
/** Run the actual reflection. */
|
|
61
|
-
reflect(ctx: ActionReflectCtx, signal?: AbortSignal): Promise<ActionReflectVerdict>;
|
|
62
|
-
/** Optional cleanup. */
|
|
63
|
-
close?(): Promise<void>;
|
|
64
|
-
}
|
|
65
|
-
export interface LLMActionReflectorOptions {
|
|
66
|
-
/** Override `process.env.PLANNER_BASE_URL` (planner endpoint reused). */
|
|
67
|
-
baseUrl?: string;
|
|
68
|
-
apiKey?: string;
|
|
69
|
-
/** Defaults to `glm-4-flash`. */
|
|
70
|
-
modelName?: string;
|
|
71
|
-
/** Confidence threshold; predictions below this fire the reflector. Defaults 0.6. */
|
|
72
|
-
confidenceThreshold?: number;
|
|
73
|
-
/**
|
|
74
|
-
* Spike branch (see {@link ActionReflectorGating}). Defaults to "whitelist"
|
|
75
|
-
* which is the safe fallback when the AutoGLM-Phone-9B endpoint doesn't
|
|
76
|
-
* expose logprobs.
|
|
77
|
-
*/
|
|
78
|
-
gating?: ActionReflectorGating;
|
|
79
|
-
/** Sampling temperature. Defaults to 0. */
|
|
80
|
-
temperature?: number;
|
|
81
|
-
/** Max output tokens. Defaults to 80. */
|
|
82
|
-
maxTokens?: number;
|
|
83
|
-
/** Reused OpenAI client for tests. */
|
|
84
|
-
client?: OpenAI;
|
|
85
|
-
}
|
|
86
|
-
export declare class LLMActionReflector implements IActionReflector {
|
|
87
|
-
readonly name = "llm-action-reflector";
|
|
88
|
-
private readonly client;
|
|
89
|
-
private readonly modelName;
|
|
90
|
-
private readonly confidenceThreshold;
|
|
91
|
-
private readonly gating;
|
|
92
|
-
private readonly maxTokens;
|
|
93
|
-
private readonly temperature;
|
|
94
|
-
constructor(opts?: LLMActionReflectorOptions);
|
|
95
|
-
shouldReflect(_history: StepHistory[], lastPrediction: Prediction, actionResult: StepHistory["actionResult"]): boolean;
|
|
96
|
-
reflect(ctx: ActionReflectCtx, signal?: AbortSignal): Promise<ActionReflectVerdict>;
|
|
97
|
-
}
|