Skip to content

Conversation

@ahuang11
Copy link
Contributor

First pass at implementing #1447

layout.mp4

The Three-Step Approach:
Break layout generation into three sequential steps similar to Planner -> Agents:
Planning (1 LLM call): Create a layout plan with natural language instructions for each subplot
Parallel Generation (N LLM calls): Generate each subplot independently in parallel
Assembly (Python): Programmatically combine specs into hconcat/vconcat structure

Note, these are the valid properties outside:

spec:
  $schema: https://vega.github.io/schema/vega-lite/v5.json
  
  # SHARED by all charts
  data:
    name: token_use_and_response_time_from_gpt_4o_mini_csv
  
  # Optional: overall title for entire visualization
  title:
    text: GPT-4o Mini Token Usage Analysis
  
  # Optional: shared transforms applied before splitting
  transform:
    - filter: "datum.response_time > 0"
  
  # The concatenation container
  hconcat: [...]

Within each subplot:

hconcat:
- # FIRST CHART
  width: 300                    # This chart's width
  height: container             # This chart's height
  title: Input Tokens Distribution  # This chart's title
  mark: bar                     # This chart's mark type
  encoding:                     # This chart's encodings
    x: {...}
    y: {...}
  transform:                    # Optional: transforms just for this chart
    - filter: "datum.input_tokens < 10000"

- # SECOND CHART  
  width: 300                    # Different width possible
  height: container
  title: Output Tokens Distribution
  mark: point                   # Different mark type
  encoding:
    x: {...}
    y: {...}

Visual Representation

┌─────────────────────────────────────────────────────┐
│ spec (top-level)                                    │
│                                                     │
│  ┌─────────────────────────────────────────────┐  │
│  │ data: (SHARED by all)                       │  │
│  └─────────────────────────────────────────────┘  │
│                                                     │
│  ┌─────────────────────────────────────────────┐  │
│  │ hconcat: [                                  │  │
│  │   ┌──────────────────────────┐              │  │
│  │   │ Chart 1                  │              │  │
│  │   │ - width                  │              │  │
│  │   │ - height                 │              │  │
│  │   │ - title                  │              │  │
│  │   │ - mark                   │              │  │
│  │   │ - encoding               │              │  │
│  │   └──────────────────────────┘              │  │
│  │   ┌──────────────────────────┐              │  │
│  │   │ Chart 2                  │              │  │
│  │   │ - width                  │              │  │
│  │   │ - height                 │              │  │
│  │   │ - title                  │              │  │
│  │   │ - mark                   │              │  │
│  │   │ - encoding               │              │  │
│  │   └──────────────────────────┘              │  │
│  │ ]                                           │  │
│  └─────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────┘

TODOs:

  • make it more token efficient
  • fix layout height / width (if both are containers, it gets clipped)

Would also like to address #1431

@ahuang11 ahuang11 requested a review from philippjfr October 17, 2025 01:36
@codecov
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

❌ Patch coverage is 37.80864% with 403 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.93%. Comparing base (4855124) to head (d64529d).

Files with missing lines Patch % Lines
lumen/ai/agents.py 5.59% 152 Missing ⚠️
lumen/tests/views/test_base.py 24.32% 112 Missing ⚠️
lumen/tests/ai/test.py 11.25% 71 Missing ⚠️
lumen/tests/ai/conftest.py 24.07% 41 Missing ⚠️
lumen/views/base.py 4.16% 23 Missing ⚠️
lumen/ai/utils.py 89.18% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1453      +/-   ##
==========================================
+ Coverage   47.89%   49.93%   +2.03%     
==========================================
  Files         122      124       +2     
  Lines       20802    21252     +450     
==========================================
+ Hits         9964    10613     +649     
+ Misses      10838    10639     -199     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ahuang11
Copy link
Contributor Author

Area.mp4

if "params" in spec:
continue
# Size limit to avoid token bloat
if len(spec_str) > 1500:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant