Skip to content

About

A TypeScript framework for building AI agents that run entirely in the browser using WebGPU-accelerated LLMs (Gemma). Features include A2U protocol for dynamic UI generation, React integration hooks, smart context providers, and MCP server support.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Web Agent Framework

A next-generation framework for orchestrating browser-based LLMs with agent-controlled UI, zero configuration, and model-agnostic architecture. Inspired by Mastra, powered by Google's A2U protocol.

๐Ÿš€ Features

  • Agent-Controlled UI: Agents can dynamically update and control your web interface using A2U/AG-UI protocols
  • Zero Configuration: Works out of the box with sensible defaults
  • Model Agnostic: Support for MediaPipe, Transformers.js, LiteRT.js through adapters
  • Type Safe: Full TypeScript support with Zod schemas
  • Composable: Agents, Workflows, Tools as first-class primitives
  • Client-First: No server required for LLM execution (runs locally via WebGPU/WASM)
  • Framework Agnostic: Works with React, Vue, Svelte, or vanilla JavaScript
  • Secure by Default: API proxy patterns for external calls, no exposed API keys

๐Ÿ“ฆ Packages

  • @web-agent/core - Core orchestration engine โœ…
  • @web-agent/ui-protocol - A2U & AG-UI protocol implementation (next)
  • @web-agent/react - React components and hooks (next)
  • @web-agent/mediapipe - MediaPipe LLM adapter (next)
  • @web-agent/transformers - Transformers.js adapter (future)
  • @web-agent/litert - LiteRT.js adapter (future)

๐ŸŽฏ What Makes This Different?

Traditional Web Apps

User clicks โ†’ JavaScript โ†’ Update UI

Web Agent Framework

User speaks/types โ†’ AI Agent โ†’ Agent controls UI directly

Example: Ask "Show me flights to Paris" and the agent automatically:

  • Renders flight cards
  • Highlights the best option
  • Pre-fills booking forms
  • Updates the UI based on your preferences

All without you writing UI update logic!

๐Ÿ—๏ธ Project Status

Phase 1: Core Foundation โœ… (Complete - 7/8 tasks)

  • Monorepo structure with pnpm workspaces
  • LLM adapter interface (model-agnostic)
  • Agent primitive with .generate() and .stream()
  • Tool primitive with Zod schemas
  • Function calling orchestration logic
  • Conversation memory (IndexedDB-backed)
  • Request context for conditional logic
  • MediaPipe adapter implementation (90% designed)

Phase 2: UI Protocol Layer ๐Ÿšง (Next - 6-8 weeks to MVP)

  • A2U protocol renderer
  • AG-UI event bus
  • Component registry
  • React integration (@web-agent/react)
  • Example: Flight booking with UI control
  • Documentation

Phase 3: Additional Adapters ๐Ÿ”ฎ (Future)

  • Transformers.js adapter
  • LiteRT.js adapter
  • Model caching utilities

๐Ÿ“– Quick Start

# Install dependencies
pnpm install

# Build all packages
pnpm build

# Run tests
pnpm test

๐ŸŽฏ Usage Examples

Basic Agent (Text-Only)

import { Agent, createTool } from '@web-agent/core';
import { MediaPipeAdapter } from '@web-agent/mediapipe';
import { z } from 'zod';

// Create a tool
const weatherTool = createTool({
  id: 'weather-tool',
  description: 'Fetches weather for a location',
  inputSchema: z.object({
    location: z.string()
  }),
  outputSchema: z.object({
    weather: z.string()
  }),
  execute: async ({ location }) => {
    const response = await fetch(`https://wttr.in/${location}?format=3`);
    const weather = await response.text();
    return { weather };
  }
});

// Create an agent
const agent = new Agent({
  id: 'weather-agent',
  name: 'Weather Agent',
  instructions: 'You help users check the weather',
  model: new MediaPipeAdapter({
    modelPath: '/models/gemma-2b'
  }),
  tools: { weatherTool },
  memory: true // Auto-configure IndexedDB
});

// Generate a response
const response = await agent.generate("What's the weather in London?", {
  memory: {
    resource: 'user-123',
    thread: 'conversation-1'
  }
});

console.log(response.text);

Agent with UI Control (A2U Protocol)

import { Agent } from '@web-agent/core';
import { A2URenderer } from '@web-agent/ui-protocol';

// Agent generates structured UI
const flightAgent = new Agent({
  id: 'flight-agent',
  instructions: `
    When showing flights, use A2U protocol:
    
    \`\`\`json
    {
      "type": "ui",
      "ui": {
        "type": "list",
        "children": [
          {
            "type": "card",
            "props": { "title": "London โ†’ Paris" },
            "children": [
              { "type": "text", "props": { "content": "โ‚ฌ99 โ€ข 2h" } }
            ],
            "actions": [
              { "type": "call_tool", "params": { "tool": "bookFlight" } }
            ]
          }
        ]
      }
    }
    \`\`\`
  `,
  model: new MediaPipeAdapter({...}),
  tools: { searchFlights, bookFlight }
});

// Agent automatically renders UI
const response = await flightAgent.generate("Find flights to Paris");

if (response.ui) {
  const renderer = new A2URenderer();
  renderer.render(response.ui, document.getElementById('results'));
  // Agent just controlled your UI! ๐ŸŽ‰
}

React Integration

import { AgentChat } from '@web-agent/react';
import { flightAgent } from './agents';

function App() {
  return (
    <AgentChat 
      agent={flightAgent}
      onUIUpdate={(component) => {
        // Agent renders interactive UI components
        console.log('Agent rendered:', component);
      }}
    />
  );
}

๐Ÿ›๏ธ Architecture

web-agent-framework/
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ core/                    # Core orchestration engine
โ”‚   โ”‚   โ”œโ”€โ”€ agent/              # Agent primitive
โ”‚   โ”‚   โ”œโ”€โ”€ tool/               # Tool primitive
โ”‚   โ”‚   โ”œโ”€โ”€ memory/             # Memory management
โ”‚   โ”‚   โ”œโ”€โ”€ llm/                # LLM adapter interface
โ”‚   โ”‚   โ””โ”€โ”€ context/            # Request context
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ mediapipe/              # MediaPipe adapter
โ”‚   โ”œโ”€โ”€ transformers/           # Transformers.js adapter
โ”‚   โ””โ”€โ”€ litert/                 # LiteRT.js adapter
โ”‚
โ”œโ”€โ”€ examples/                    # Example applications
โ””โ”€โ”€ docs/                       # Documentation

๐Ÿ“š Documentation

All documentation is in the docs/ folder:

โ†’ Browse All Documentation

๐Ÿค Contributing

Contributions are welcome!

๐Ÿ“„ License

MIT

๐Ÿ™ Acknowledgments

About

A TypeScript framework for building AI agents that run entirely in the browser using WebGPU-accelerated LLMs (Gemma). Features include A2U protocol for dynamic UI generation, React integration hooks, smart context providers, and MCP server support.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages