Writing
ai-engineeringcode-modeagentsuraiLLMs

Urai - Unreasonable effectiveness of code-mode agents

Most production agent systems rely on structured tool calling: the model selects a function from a predefined JSON schema, the orchestrator executes it, and the output feeds back into the prompt for the next turn.

This approach works for simple lookups. It breaks down quickly once a task requires inspecting live web pages, extracting assets, querying internal documentation, and writing multi-file software artifacts. Every step requires another round-trip through the inference API. Raw payloads pollute the context window, and any minor schema mismatch halts the entire chain.

Code mode changes this dynamic entirely. Instead of negotiating JSON schemas with an orchestrator, the agent writes and executes code directly inside a sandboxed runtime.

A live run inside Urai illustrated this contrast clearly. Given a high-level request, an agent running on Gemini 3.8 Flash scraped brand assets, consulted an internal knowledge base, built an interactive presentation canvas, and formatted it for print-ready PDF export. The run finished in roughly five minutes and cost fifty cents.


The Task

The user prompt was intentionally broad:

“Visit uraiai.com and docs.uraiai.com, download the logo, and create a professional presentation about Urai AI Corp. Use the slides-skill library to create a slide deck with the logo and the same theme as the website. Use the knowledge about the team to write the team slide. Structure it as overview, problem, solution, product, team, and thanks.”

Here is the result.

Thread | Slides

To satisfy this prompt, an agent must execute several distinct operations:

  1. Fetch live HTML from two separate web domains and parse the DOM to locate official vector logos.
  2. Query an internal knowledge base to extract accurate biographical data for the company founders.
  3. Scaffold an engine-backed presentation inside an isolated canvas directory.
  4. Extract the primary and secondary color tokens from the production site and map them to presentation styles.
  5. Author six semantic HTML slide fragments utilizing Tailwind utility classes and Alpine.js data bindings.
  6. Verify 1920×1080 stage boundaries and print stylesheets so the deck exports to PDF without clipping.

Why Standard Function Calling Stalls

Handling this workflow through traditional JSON tool definitions creates three major points of friction.

1. The Context Window Tax

When an agent calls a web scraper tool, the raw HTML or Markdown usually returns straight into the model’s conversation history. Two full pages of documentation and landing page markup can consume tens of thousands of tokens. The agent’s context quickly fills with navigation bars, cookie banners, and irrelevant scripts, degrading model attention for the creative task that follows.

2. Turn Inflation

In standard tool-calling loops, each discrete action requires a full inference pass. Fetching a page is turn one. Extracting the logo URL is turn two. Downloading the file is turn three. Querying the team database is turn four. Creating six slides requires at least six more turns. A twelve-turn conversation introduces latency at every step, increasing both completion time and error rates.

3. Lack of Control Flow

Standard tools cannot loop, branch, or filter data before returning it to the model. If a selector fails or an image link is relative rather than absolute, the orchestrator throws an error, and the agent must burn another complete round-trip attempting a correction.


What Code Mode Does Differently

In code mode, the agent receives an execution environment (in Urai, a WinterTC-compliant JavaScript runtime) and access to a local filesystem rather than a collection of rigid API wrappers. The action space becomes standard JavaScript.

Code mode loop
  1. 01

    Write

    A JavaScript file that fetches, parses with regex and writes to disk.

  2. 02

    Execute

    Run it inside the isolated sandbox runtime.

  3. 03

    Inspect

    Read stdout and the files the script wrote.

  4. 04

    Iterate or finish

    Fix the error and loop back, or return the final artifact path.

↺ on failure, step 04 returns to step 01

This structural shift produces several operational advantages:

Data Stays at the Runtime Layer

When the agent needs the company logo, it does not pass the raw HTML of the documentation site back into the prompt. Instead, it writes a short script that fetches the page, runs a regular expression or DOM query to find the SVG path, downloads the vector file, and saves it directly to /canvas/urai-presentation/assets/logo.svg. The agent only receives a short confirmation string: Wrote 2,140 bytes to assets/logo.svg. Thousands of tokens of raw web markup never enter the conversational context.

Multi-Step Operations Collapse Into Single Scripts

Instead of asking permission for every file operation, the agent writes a script that copies the layout engine, sets up the presentation directory structure, and initializes config.js in a single execution. Six conversational turns shrink to one.

The Filesystem Serves as External Memory

The generated artifacts live on disk rather than inside chat messages. The model edits slide templates directly using file system operations, runs test scripts against them, and points the user to the resulting canvas URL.


The Economics: Five Minutes, Fifty Cents

Running long agentic workflows on large frontier models can quickly cost several dollars per run. This experiment paired code execution with Gemini 3.8 Flash.

Metric Result
Model Gemini 3.8 Flash
Wall-Clock Time ~5 minutes
Total Inference Cost ~$0.50
Output Artifact 6-slide presentation (HTML, Tailwind, Alpine.js)
Export Capability Native 1920×1080 print-to-PDF
Assets Handled Scraped SVGs, private knowledge base documents, custom themes

Fast, lightweight models are frequently underestimated for autonomous tasks because their raw reasoning scores trail heavier flagship models. When constrained to rigid JSON schemas, they can hallucinate keys or trip over complicated tool definitions.

Place that same model in a code execution loop, however, and the dynamic flips. Fast models generate JavaScript exceptionally well. If a script encounters a typo or a broken path, the runtime surfaces an error stack trace. The model reads the error, modifies line 12, and runs it again. Fast inference speeds and cheap input tokens allow the agent to iterate rapidly without running up a massive bill.


Key Implications for Building Agent Workflows

  1. Stop writing specialized tools for things code can already do. If an agent needs to filter a list, parse a string, or format a timestamp, it does not need a dedicated backend endpoint. It needs a JavaScript or Python interpreter.
  2. Treat files as primary outputs. Forcing an agent to return large Markdown documents, SVGs, or HTML files in the chat response wastes tokens and causes truncation bugs. Have the agent write to a shared disk or canvas, and return only the file path.
  3. Keep intermediate data out of the prompt. Let scripts read large files, extract the relevant lines, and write them to a local cache. The model’s context window should hold instructions, planning state, and error logs, not Megabytes of unprocessed raw data.

When given an expressive action space and an isolated execution environment, smaller and cheaper models can complete end-to-end design and coding tasks that previously required human intervention.


Why We Built Urai Around Code Mode

We engineered Urai because we kept hitting these exact walls while shipping agents inside SaaS products. Every Urai agent writes JavaScript, runs it in the uraiJS sandbox, reads the result, and repeats until it can answer. Step limits, secret allowlists, and network allowlists keep that loop safe to run against production data. Your team publishes typed TypeScript libraries with a git push, so the agent calls your functions instead of improvising raw HTTP requests. Procedures live as Markdown skills that agents load only when a task needs them, and the knowledge base answers with hybrid search and citations, which is how the team slide in this run got accurate biographies. Each conversation can be distilled into a new skill, so the next run starts smarter than the last. The whole thing embeds in your product with a single script tag or a React, Vue, or Svelte component, and it can be self-hosted. If you want to see the run from this post, or point it at your own product, book a 45-minute demo with the founders.