Skip to content

Latest commit

ย 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 

Repository files navigation

๐Ÿค– AI Web Action Framework

Proof of Concept โ€” An AI agent that can perform real actions inside a user's browser.


๐Ÿ’ก The Idea

What if an AI chatbot could do more than just reply with text? What if it could actually click buttons, navigate pages, fill forms, and manipulate the DOM โ€” all from a simple chat conversation?

This project proves that's possible on the web, today, using nothing but a hidden communication protocol between a server-side AI and a lightweight JavaScript SDK.


โœ… What This Proof of Concept Demonstrates

Capability Status How It Works
AI โ†’ Browser Navigation โœ… Working AI tells the browser to window.location.href to a URL
AI โ†’ Browser Alerts โœ… Working AI triggers native alert() dialogs with dynamic messages
AI โ†’ Console Logging โœ… Working AI sends debug info to console.log()
AI โ†’ DOM Manipulation โœ… Working AI updates any element's text/HTML by ID (calculator demo)
Multiple Actions in One Response โœ… Working AI can fire several browser actions from a single response
Custom Action Registration โœ… Working Developers can register any custom JS function as a "tool"
Hidden Protocol (User Never Sees JSON) โœ… Working Action tokens are embedded as HTML comments โ€” invisible to end users

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    USER'S BROWSER                       โ”‚
โ”‚                                                         โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚   Chat UI     โ”‚ โ”€โ”€โ–ถ โ”‚  AIWebAgent (JS SDK)       โ”‚   โ”‚
โ”‚  โ”‚  (clean text) โ”‚     โ”‚  โ€ข Parses action tokens     โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚  โ€ข Executes registered      โ”‚   โ”‚
โ”‚                        โ”‚    JavaScript functions      โ”‚   โ”‚
โ”‚                        โ”‚  โ€ข Returns clean text for UI โ”‚   โ”‚
โ”‚                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                   โ–ฒ                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ”‚  HTTP / SSE
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               LARAVEL BACKEND (The Brain)               โ”‚
โ”‚                                   โ”‚                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ LLM / AI   โ”‚โ”€โ”€โ–ถโ”‚  ClientActionTool (PHP)          โ”‚  โ”‚
โ”‚  โ”‚ (GPT, etc) โ”‚   โ”‚  โ€ข NavigateToPage                โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚  โ€ข ShowAlert                     โ”‚  โ”‚
โ”‚                   โ”‚  โ€ข (extensible via subclasses)    โ”‚  โ”‚
โ”‚                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Key Trick: Hidden Action Tokens

The AI's response looks like this to the user:

"Sure! I'm navigating you to the product page now."

But the raw response actually contains:

Sure! I'm navigating you to the product page now.
<!-- CLIENT_ACTION_START {"action":"navigate","payload":{"url":"/products/iphone-15"}} CLIENT_ACTION_END -->

The hidden HTML comment is parsed by the JS SDK, which executes the action and strips the token before displaying the text. The user never sees the JSON.


๐Ÿ“‚ Project Structure

experiment-001/
โ”œโ”€โ”€ README.md                           โ† You are here
โ”œโ”€โ”€ Guideline.md                        โ† Architecture spec & implementation guidelines
โ”‚
โ”œโ”€โ”€ app/Ai/Tools/                       โ† ๐Ÿ”ง Backend (Laravel)
โ”‚   โ”œโ”€โ”€ ClientActionTool.php            โ† Abstract base class with dispatch() method
โ”‚   โ”œโ”€โ”€ NavigateToPage.php              โ† Concrete tool: browser navigation
โ”‚   โ””โ”€โ”€ ShowAlert.php                   โ† Concrete tool: browser alerts
โ”‚
โ””โ”€โ”€ public/                             โ† ๐ŸŒ Frontend
    โ”œโ”€โ”€ js/ai-browser-tools.js          โ† AIWebAgent SDK (vanilla JS, ~230 lines)
    โ””โ”€โ”€ simulate.html                   โ† Interactive test page with all demos

๐Ÿš€ Running the Demo

No backend required! The simulation page works standalone:

  1. Open public/simulate.html in any browser
  2. Click the preset buttons to test each action type:
    • ๐Ÿงญ Navigate โ€” Simulates browser redirect (suppressed for safety)
    • โš ๏ธ Alert โ€” Triggers a browser alert via the protocol
    • ๐Ÿ“‹ Console โ€” Logs to browser DevTools console
    • ๐Ÿ”— Multiple โ€” Fires two actions from one response
    • ๐Ÿงฎ Calculator โ€” Full DOM manipulation demo (AI "calculates" and updates the page)
  3. Use the Custom Simulation textarea to test your own payloads

๐Ÿ”ง How It Works โ€” Code Examples

Backend: Creating a New Client Tool (PHP)

class AddToCart extends ClientActionTool
{
    public function actionName(): string
    {
        return 'add_to_cart';
    }

    public function description(): Stringable|string
    {
        return 'Add a product to the shopping cart in the browser.';
    }

    public function schema(JsonSchema $schema): array
    {
        return $schema->object([
            'product_id' => $schema->string('The product ID.'),
            'quantity'    => $schema->integer('Number of items to add.'),
        ])->require(['product_id', 'quantity']);
    }

    public function handle(Request $request): Stringable|string
    {
        return $this->dispatch($this->actionName(), [
            'product_id' => $request->input('product_id'),
            'quantity'    => $request->input('quantity'),
        ]);
    }
}

Frontend: Registering the Matching JS Handler

const agent = new AIWebAgent();

agent.registerTool('add_to_cart', (payload) => {
    fetch('/api/cart', {
        method: 'POST',
        body: JSON.stringify({
            product_id: payload.product_id,
            quantity: payload.quantity,
        }),
    }).then(() => {
        updateCartBadge();
        showToast('Item added to cart!');
    });
});

๐Ÿ”ฎ Future Roadmap

Phase 1: Core Enhancements

  • Streaming support โ€” Parse action tokens from SSE (Server-Sent Events) streams in real-time
  • Action acknowledgment โ€” Browser reports back to the server whether an action succeeded or failed
  • Action queueing โ€” Buffer multiple rapid actions and execute sequentially with optional delays
  • Conditional actions โ€” Server sends actions that only execute if certain DOM conditions are met

Phase 2: Rich Browser Tools

  • Form auto-fill โ€” AI fills forms by targeting input fields by name/ID
  • Click simulation โ€” AI triggers click events on buttons and links
  • Scroll to element โ€” AI scrolls the viewport to a specific section
  • CSS class toggling โ€” AI adds/removes classes (e.g., dark mode, highlights)
  • Toast/notification system โ€” Non-blocking UI notifications instead of alert()
  • Modal dialogs โ€” AI opens rich modal content with HTML

Phase 3: Advanced Capabilities

  • Multi-step workflows โ€” AI chains multiple browser actions into sequences (e.g., "fill form โ†’ submit โ†’ navigate to confirmation")
  • Visual feedback โ€” Highlight elements the AI is about to interact with
  • Undo system โ€” Let users revert AI-triggered browser actions
  • Permission system โ€” User approves certain actions before execution (e.g., "AI wants to navigate away, allow?")
  • Sandbox mode โ€” Preview what actions the AI would take without executing them

Phase 4: Framework & Ecosystem

  • NPM package โ€” Publish the JS SDK as an installable package
  • Composer package โ€” Publish the Laravel tools as a standalone package
  • React/Vue adapters โ€” Framework-specific wrappers for the SDK
  • WordPress plugin โ€” Bring AI browser actions to WordPress sites
  • TypeScript types โ€” Full type definitions for the SDK
  • Action marketplace โ€” Community-contributed tool packs (e-commerce, forms, analytics)

๐Ÿ›ก๏ธ Security Considerations

Measure Implementation
Whitelist-only execution Only registered tools can run โ€” no eval() ever
URL validation Navigation restricted to relative or whitelisted domains
Payload validation Both backend schema validation and frontend type checking
No server-side effects Client tools return tokens only โ€” they don't modify server state
HTML comment hiding Tokens are invisible in rendered HTML, preventing social engineering

๐Ÿงช Tech Stack

Layer Technology Purpose
AI Brain Laravel 12+ with Laravel AI SDK Tool definitions, LLM orchestration
Protocol Hidden HTML comments with JSON Communication bridge
Browser SDK Vanilla JavaScript (AIWebAgent) Token parsing, tool execution
Test Page Pure HTML/CSS/JS No build tools needed

๐Ÿค Why This Matters

Traditional AI chatbots are read-only โ€” they can only respond with text. This framework makes AI read-write on the web, enabling:

  • E-commerce: "Add that jacket to my cart" โ†’ AI actually adds it
  • SaaS dashboards: "Show me last month's revenue" โ†’ AI navigates to the report
  • Customer support: "Reset my password" โ†’ AI triggers the reset flow in the browser
  • Accessibility: Voice-driven AI that physically operates the interface for users

The web browser becomes the AI's hands. ๐Ÿ–๏ธ


Built as a proof of concept โ€” proving that AI-driven browser actions are possible, practical, and ready for production.

About

AI Function Calling for the Browser

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors