Computer-Use and Browser Agents › The grounding function
Language AI HandbookAll chapters The local policy case-folds and splits names on whitespace. For target term set and candidate term set , the score is their intersection size divided by their union size when both sets are nonempty. Both are sets of words under this tokenizer. The value ranges from zero to one. An exact term-set match scores one. Word order, repetitions and negation are outside the representation, which is why the matcher is appropriate only for this narrow fixture.
The score orders enabled controls of a supported role. It applies a threshold of 0.5 and refuses ties for the best score. Refusal lets a policy add a qualifying label or surface the ambiguity. The example uses a fixed threshold for teaching. A real application can select a threshold on held-out controls and inspect both incorrect acceptance and incorrect rejection.
PythonIn [13]Expand
def _norm(value):
return " ".join(value.casefold().split())
def score_element(target, element):
a = set(_norm(target).split())
b = set(_norm(element.name).split())
return len(a & b) / len(a | b) if a and b else 0.0
def ground(action_kind, target, obs):
roles = {"click": {"button", "link"}}
scored = sorted(
[
(score_element(target, e), e)
for e in obs.elements
if e.enabled and e.role in roles.get(action_kind, set())
],
key=lambda pair: (-pair[0], pair[1].id),
)
if not scored or scored[0][0] < 0.5:
return None, scored
if len(scored) > 1 and isclose(scored[0][0], scored[1][0]):
return None, scored
return scored[0][1], scored
def choose(obs, *labels):
for label in labels:
element, _ = ground("click", label, obs)
if element is not None:
return Action(obs.epoch, "click", element.id)
return NonePythonIn [14]Expand
obs = render(MockApp())
best, scored_candidates = ground("click", "Open task 2", obs)ConsoleOut [15]Expand
Chosen: Open task 2
Scores: [('Open task 2', 1.0), ('Open task 1', 0.5), ('Open task 3', 0.5)]The exact Open task 2 label has all three requested terms. Other task labels share open and task but add a different third term. The intersection has two terms and the union four, giving each alternative 0.5. If the request drops the task number, all three controls tie and the policy selects no control.
VisualizationOut [16]Expand

Why categories first, then names
Filtering by role and enabled state narrows candidate ranking. The runtime still tests the selected element independently. It checks the actual operation and identity, because the role and name delivered to a policy are observation data. An inactive Mark done button stays disabled even if a stale observation showed it enabled.
The sorted scores can reveal whether the requested control was missing, suffered a lexical mismatch, or tied with another one. They do not establish that the operation will succeed or is authorized. If adding region context improves the observed match, the application should still assess final state after the operation.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!