Computer-Use and Browser Agents › The grounding function

Michael BrenndoerferDecember 1, 20263 min read
Language AI HandbookAll chapters
Part 49 of 67Long-Horizon Agents and Interoperability
Chapter 373Computer-Use and Browser Agents › The grounding function
Reading section 6 of 15 · The grounding function · 3 minSection 6 of 15 · 3 min

Section 6 of 15 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The local policy case-folds and splits names on whitespace. For target term set AA and candidate term set BB, 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]
CollapseExpand
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 None
PythonIn [14]
CollapseExpand
obs = render(MockApp())

best, scored_candidates = ground("click", "Open task 2", obs)
ConsoleOut [15]
CollapseExpand
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]
CollapseExpand
Horizontal bars rank the three synthetic links by their overlap with Open task 2.
The token-overlap scorer gives the exact task label 1.0 and both other task labels 0.5. Equal-scoring alternatives illustrate why a tie needs more context.

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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy