Skip to main content
Glama

wait_for

Idempotent

Polls engine fields, instances, OCR text, new log lines, or window titles until a condition holds, returning a pass/fail/unverifiable verdict with evidence to prevent false failures in asynchronous game flows.

Instructions

轮询等待条件成立并给出证据包(验收闭环里「等到可以判了」那一步)。五种条件:field / instances / ocr / log / window。返回三态 verdict(pass / fail / unverifiable —— 把「没法判」与「没通过」严格区分)+ polls / evidence;超时如实报 fail,不静默当通过。注意 kind="log" 等的是新增(先记基线再等增量),不是「当前存在」。

为什么必须有它:游戏是异步的 —— 点完按钮要等界面出来、场景加载要 等几秒。不等待就直接断言,会得到大量假失败(其实只是还没加载完)。 同类工具(MaaFramework)把它写成一句伪代码: while(!hit && !timeout) { 检查; sleep(rate_limit); }。

支持的条件(kind)覆盖三类信号,优先用引擎信号,少用像素:

kind

判据

需要哪些参数

field

某字段的值等于 equals

name/field/equals(instance 不需要:会先用 find_instances 找)

instances

某类的活实例数 ≥ min_count

name(可选 namespace/image)

ocr

屏幕上 OCR 到 target 文本

target(可选 region/window)

log

日志里新增匹配 pattern 的行

target=日志路径,pattern

window

出现标题含 target 的窗口

target

kind='log' 等的是「新增」,不是「存在」(这条是真机实战踩出来的): 第一次轮询会记下基线匹配数,之后超过基线才算成立。 否则旧日志里早就有的匹配行会让它在 1ms 内返回 pass, 而本次操作根本没发生(实测:日志里已有 5 条「已修改 精核」时确实如此)。 要判「当前是否已有」请直接用 probe_log,不要用 wait_for。

返回值就是证据包(不是光秃秃的布尔): · ok —— 条件成立了 · verdict —— pass / fail / unverifiable 三态。 unverifiable 表示「没法判」(例如依赖不可用、探针不上线), 与 fail(判了、没成立)严格区分 —— 把「没法判」说成「没通过」 会让 Agent 去修一个根本不存在的缺陷。超时如实报 fail。 · polls / elapsed_ms / interval_ms —— 轮询了几次、花了多久 · evidence —— 每次轮询的实测值(最后若干次),可核查 · hint —— 超时时给出下一步建议

Args: kind: 上面五种之一。 target: ocr / window 的目标文本。 region: ocr 用:"x,y,w,h" 屏幕绝对坐标。 window: ocr 用:窗口标题子串。 name/namespace/image: field / instances 的类定位参数。 field: field 用:字段名。 equals: field 用:期望值(按字段类型比较)。 pattern: log 用:日志正则。必须同时给 target(日志路径)。 timeout_ms: 总超时(默认 20000)。 interval_ms: 轮询间隔(默认 500)。别设太小 —— 徒增开销。 min_count: instances 用的实例数下限(默认 1)。

Returns: {ok, verdict, kind, polls, elapsed_ms, evidence, last, hint?}

Input Schema

NameRequiredDescriptionDefault
kindYes
nameNo
fieldNo
imageNo
equalsNo
regionNo
targetNo
windowNo
patternNo
min_countNo
namespaceNo
timeout_msNo
interval_msNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the annotations, which only declare idempotent/non-destructive/openWorld. The description discloses polling cadence and defaults, the three-state verdict and why `unverifiable` is distinct from `fail`, the guarantee that a timeout reports fail rather than silently passing, and the baseline-then-increment semantics of `kind=log` — a real behavioral trap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The core purpose is front-loaded in bold and the table is an efficient structure. Some material is expendable — the MaaFramework pseudocode quote and the repeated explanation of the log baseline (once in the table, once in its own bold paragraph) cost space without adding decisions.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 13-param, no-output-schema polling tool, everything an agent needs is present: condition kinds, per-kind params, return shape, tri-state semantics, timeout behavior, and the failure mode that motivates the tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description carries the entire burden, and it does: each `kind` is mapped to its required parameters, per-param meaning is given (`region` as "x,y,w,h" absolute coords, `pattern` as regex requiring `target`), and defaults for timeout/interval/min_count are stated. It stops short of documenting every one of the 13 params exhaustively (e.g. `namespace`/`image` are only grouped under class-location), which keeps it at 4.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening line states a specific verb and resource ("poll-wait for a condition to hold, return an evidence bundle") and names the pipeline step it serves. The kind table makes the five condition types concrete, and the text explicitly distinguishes it from sibling tools `probe_log` and `verify_state`.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use (async waits after button clicks, scene loads) and when not to (use `probe_log` to test whether something already exists, not `wait_for`). It also gives a cross-cutting selection rule: prefer engine signals over pixel/OCR signals.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.