All blogs

Agentic React ·

How we halved the tokens an agent needs to find React source

Agents usually start a UI change from a screenshot, then spend tokens reading pixels and searching the repository. React already knows which component rendered each element and where that component lives. Our idea was to hand that knowledge to the agent directly. Agentic React lets you select an element in the browser and copy its component, stable selector, source file and line, owner trace and nearby code, so the agent starts at the right line.

A selected web UI region takes a short direct path to source code while a longer path passes through many context nodes

Working principle

On three source-location tasks, Agentic React context used 180,302 tokens where screenshots used 388,694. That is 53.6% fewer tokens, 21.8% less runtime and 66.1% lower API-equivalent cost, with the correct source found every time.

The pain: a screenshot shows what, never where

A screenshot shows how the page looks. It does not say which component rendered it or which file holds that component. The agent spends tokens describing the image, then more tokens searching the repository for the text it saw, and it needs a model that reads images.

How Agentic React works

Agentic React has a bundler-agnostic core with adapters for Vite, Webpack and Next.js. In local dev you select one element or many, and Agentic React copies text or JSON for each. The dev server also serves the same context to agents as local MCP tools at /mcp. The context is plain text, so any model can use it.

The tuning modal turns choices such as a new text color or font into written instructions, each placed next to the file and line the agent should edit.

Copied context for one element

<web_context type="react_component_location">
component: ProfileField
tuning prompts:
- Change <ProfileField> in src/components/UserProfile/ProfileField.jsx:19 text color to rgb(15, 118, 110).
selector: #profile-field-email
source: src/components/UserProfile/ProfileField.jsx:19
source trace:
  -> <ProfileField> at src/components/UserProfile/ProfileField.jsx:19
  -> <ProfileContent> at src/components/UserProfile/ProfileContent.jsx:54
</web_context>

Vite setup

pnpm install @agentic-react/vite -D

// vite.config.ts
import { defineConfig } from 'vite'
import AgenticReact from '@agentic-react/vite'

export default defineConfig({ plugins: [AgenticReact()] })

The benchmark

We gave a coding agent the same read-only task six times: find the smallest source region that renders a given UI target and return compact JSON. Three UI areas each ran once with a cropped screenshot and once with pasted Agentic React context. The agent was gpt-5.4 at low reasoning effort in codex-cli 0.143.0, recorded on 2026-07-28.

Cost is API-equivalent at $2.50 per million uncached input tokens, $0.25 per million cached input tokens and $15.00 per million output tokens. The raw manifest and full method are public.

Agentic React source-location benchmark, 2026-07-28
UI areaInputInput tokensCached inputOutputTotalTokens savedCostCost saved
Issue rowScreenshot138,50196,256830139,331baseline$0.1421265baseline
Issue rowAgentic React context56,42938,01656056,98959.0981%$0.063936555.0144%
Issue detailScreenshot128,16696,128970129,136baseline$0.1186770baseline
Issue detailAgentic React context50,85248,76852151,37360.2179%$0.025217078.7516%
Live analyticsScreenshot119,16291,0081,065120,227baseline$0.1091120baseline
Live analyticsAgentic React context71,17468,09676671,94040.1632%$0.036209066.8148%
AggregateScreenshot385,829283,3922,865388,694baseline$0.3699155baseline
AggregateAgentic React context178,455154,8801,847180,30253.6134%$0.125362566.1105%

Where it stands

The packages are on npm under @agentic-react: core, vite, webpack and next. vertile.ai uses @agentic-react/next in its own development.

We built a larger benchmark on eight open-source React apps pinned to fixed commits, covering the major bundlers and React frameworks: Vite with TanStack Router, webpack 5, Rsbuild, Next.js on Turbopack and on webpack, TanStack Start, Astro with React islands, and React Router v7 with Express. The tasks run on Harbor.

Agentic React and agentic-node split the work. agentic-node folds what Node prints: builds, dev servers and test runs. Agentic React owns what the browser shows: the UI itself, hydration errors and console output. Together they cover what an agent reads while it works on a React app.

What's next

Next, Agentic React will digest browser output, such as hydration errors and console floods, into the few lines an agent needs, next to the component and source line that caused them.

Then we run agents on the eight-app benchmark with and without Agentic React and report task success, output tokens and rounds.

Add @agentic-react/vite, @agentic-react/webpack or @agentic-react/next to your dev dependencies, select an element, and paste its context into your agent.