Topic

JavaScript

All digests tagged JavaScript

Transformers.js v4.3: Structured Output in the browser thumbnail

· 11:08

Transformers.js v4.3: Structured Output in the browser

Transformers.js v4.3 introduces structured output capabilities via the new `@huggingface/transformers-structured-output` package. This feature allows developers to force Large Language Models (LLMs) to adhere to strict JSON Schemas or regular expressions directly in the browser. This solves the common problem of unreliable LLM output formats (e.g., markdown fences, inconsistent JSON structure) by implementing constrained decoding, which hooks into the model's logits processor to filter out non-compliant tokens.

Key takeaways

  1. Structured Output Capability 1:59

    The new package allows users to force an LLM to follow an exact JSON Schema or regex, ensuring predictable and reliable data extraction without needing to parse markdown or assume structure.

  2. Technical Implementation 3:48

    Constrained decoding works by hooking into the `logits processor` within Transformers.js. This allows the system to validate potential next tokens against the defined constraints (JSON Schema or regex) and strip out non-compliant tokens.

  3. Performance Improvement

    The initial prototype used a WASM wrapper around Rust's `llguidance`. This was successfully rewritten into a pure JavaScript implementation, eliminating the large 1MB WASM overhead while maintaining minimal performance overhead across models like Gemma 4, Granite, and LFM 2.5.

Watch on YouTube Full article

Expose your site's actions to AI agents using WebMCP thumbnail

· 1:29

Expose your site's actions to AI agents using WebMCP

This talk introduces WebMCP (Web Manifest Capabilities Protocol), a method for web sites to expose their functional capabilities directly to AI agents. Instead of relying on agents to interpret the UI like a human, developers can register tools using plain JavaScript, defining explicit inputs and outputs via a schema. This allows agents to perform direct tool calls (e.g., 'Download report CSV') rather than attempting button interactions, significantly improving reliability for automated agent workflows.

Key takeaways

  1. Problem with Current AI Agent Interaction

    AI agents often fail or go off course because they misinterpret the visual interface (UI) of a website, forcing them to interact like a human user.

  2. WebMCP Solution: Exposing Capabilities

    WebMCP allows sites to explicitly expose what they can do. Developers register tools using plain JavaScript, providing a name, description, and function that performs the action.

  3. Reliable Agent Interaction via Schema

    By defining explicit inputs and outputs (the schema), agents can bypass guesswork. They discover capabilities and execute direct tool calls, such as calling 'Download report CSV' directly.

  4. Alternative Exposure Methods

    If JavaScript is not used, capabilities can be exposed by annotating supported HTML forms instead.

Watch on YouTube Full article