Skip to content

Low-token accessibility trees for long browser research sessions (minimal encoding, inline cap, snapshot search) #503

Done

Description

@edjash

Problem

Using get_app_state to drive Chrome for sustained web research costs a lot of context, even with include_screenshot: false and interactive_only: true:

  • A typical results page fills the 32 KB inline budget on every look (~31 KB / ~9k tokens per call), whatever the agent actually needs from it.
  • The text a research agent wants (prices, descriptions, listing titles) usually sits past the inline prefix, so the agent either pages through the cached tree with get_tree_page (hundreds of KB on a large page) or needs shell access to search the spill file.
  • interactive_only: true filters the tree before it is cached and spilled, so the page text it drops cannot be retrieved from that snapshot at all. A second, unfiltered get_app_state replaces the snapshot, so the indices the agent was about to click become invalid.
  • Compact nodes still carry object_ref, depth, parent_index, bounds, actions, child_count and routine states (enabled, visible, showing, ...), which navigation rarely needs.

Measured on eBay with v0.7.60 (Debian 13, GNOME 48 on X11, Chrome with --force-renderer-accessibility): a search-and-listing sequence (find the search box, search, read listing titles and prices, open the first listing, read its title and price) moved ~404 KB of tool results in 20 calls, 10 of them get_tree_page paging calls. That was with the agent keeping one snapshot per page so its indices stayed valid.

Proposal

Opt-in additions that keep the whole tree in the local snapshot and let the agent retrieve only what it needs. Existing behaviour, including action resolution on interactive_only snapshots, is unchanged.

  1. tree_detail: "minimal" | "compact" | "full" on get_app_state, get_tree_page and post-action include_tree. Minimal nodes are {index, role, name, text (when it differs from the name, U+FFFC removed), value, states (non-routine only)}. The existing NodeDetail plumbing (inline result, spill file, paging, TreeShape) already carries an encoding choice, so this is a new variant and its encoder.
  2. max_tree_bytes on get_app_state and post-action include_tree: caps the inline tree (default and ceiling stay 32000). 0 returns no nodes, but the call still reads the desktop, caches the whole tree under a new snapshot_id and writes the spill file. Errors, warnings, truncation and the readiness block are unaffected.
  3. Search in get_tree_page: query (case-insensitive text in name, text or description), role, and within (an element_index subtree). It filters the cached snapshot without re-reading the desktop, keeps snapshot_id checks, and pages the matches as today. within is applied on the whole tree, so a plain container (a results list) still bounds a search of the interactive view.
  4. interactive_only keeps the whole tree for searching only. The snapshot keeps the interactive view exactly as today, and every action (element_index, selectors, bounds, recovery) resolves against it unchanged. The whole compacted tree is stored beside it and read only by get_tree_page when a filter or interactive_only: false is passed. One snapshot can then serve navigation and research, without a second get_app_state replacing the indices the agent is about to click. Existing callers see no difference.

The same eBay sequence with these options: ~41 KB in 15 calls, about 10x less tool-response text than the MCP-only baseline. (An agent with shell access could search the spill file instead of paging. These options give a similar saving through MCP alone.) A research step becomes get_app_state {interactive_only, tree_detail: "minimal", max_tree_bytes: 0} (~1.7 KB), then get_tree_page {query: "£", interactive_only: false, tree_detail: "minimal"}.

I have an implementation with tests and can open a PR if this direction works for you.

Related observations (not part of the proposal)

  • CallToolResult::structured (rmcp 3.9) sends each result both as a text block and as structuredContent. Claude Code passed one copy to the model in my tests, so this did not affect token use there, but other hosts may count both.
  • get_app_state for an app name that matches nothing reports only "Captured 0 accessibility nodes", with no explicit "no app matched" error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions