Skip to content

Optimize new snapshot system #79

Description

@braden-seaborn

Snapshot Data Optimization & Compression

Objective

Implement configuration-driven filtering and compression so each snapshot keeps only the data an agent truly needs, hitting our low-token budget without losing interactive context.


Technical Approach

1. Configuration-Based Exclusion System

  • Negative Filtering – declare what to drop instead of what to keep.
  • Hierarchical Rules – exclusions can apply at any DOM level.
  • Dynamic Filtering – decide at runtime using element properties.
  • Token Budget Management – hard limits prevent snapshot bloat.

2. Data-Compression Strategies

Element-Level Compression

{
  "exclusions": {
    "unnecessaryAttributes": ["data-*", "style", "class"],
    "emptyElements": true,
    "hiddenElements": true,
    "decorativeElements": ["img", "svg", "span.icon"]
  },
  "compression": {
    "textTruncation": 100,
    "attributeShortening": true,
    "positionRounding": 2
  }
}

Structural Optimization

  • Flattening – drop useless nesting around leaf nodes.
  • Deduplication – merge identical siblings.
  • Reference Compression – replace verbose IDs with short hashes.
  • Selective Depth – stop traversal early in non-interactive branches.

Implementation Features

Configuration Schema

  • Exclusion patterns for tags, classes, attributes.
  • Compression levels: aggressive, balanced, minimal.
  • Token-budget ceiling with overflow handling.
  • Whitelist / blacklist support for must-keep elements.

Compression Algorithms

  • Attribute Filtering – strip non-essential attrs.
  • Text Compression – truncate with ellipsis beyond N chars.
  • Position Optimization – round coords/dims to N decimals.
  • Reference Encoding – generate minimal unique refs.

Smart Exclusion Rules

const exclusionRules = {
  // Ignore low-value elements
  skipIfEmpty: ['div', 'span', 'p'],
  skipIfHidden: true,
  skipDecorative: ['.icon', '.decoration', '.spacer'],

  // Text handling
  textLimit: 100,
  preserveKeywords: ['submit', 'apply', 'next', 'continue']
};

Expected Optimizations

Optimization Type Before After (Example) Token Savings
Unnecessary Attributes 100 % captured ≈30 % filtered ~70 %
Decorative Elements All included Smart exclusion 40-60 %
Text Content Full strings Truncated/summarized 50-80 %
Positional Data Exact coords Rounded values 20-30 %

Configuration Examples

Aggressive Compression

{
  "mode": "aggressive",
  "tokenBudget": 500,
  "preserveOnly": ["interactive", "form", "navigation"],
  "textLimit": 50
}

Balanced Optimization

{
  "mode": "balanced",
  "tokenBudget": 1000,
  "excludeDecorative": true,
  "textLimit": 100
}

Performance Targets

  • Token Reduction – 60-80 % smaller snapshots.
  • Processing Speed – <100 ms on typical pages.
  • Accuracy Retention – 100 % of interactive elements kept.
  • Compression Ratio – tunable per project needs.

This optimization pipeline ensures our snapshots stay lean, cost-effective, and fully actionable for the agent.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions