// agent

My Physics Simulator Code Studio

by Jacoborodskak · Oct 20, 2026 Public

Choose how to run this agent

⚡ Local runs on your GPU. For usable speed it needs a WebGPU-capable browser — Chrome or Edge on a machine with a graphics card, or an Apple Silicon Mac. Without a supported GPU, pick OpenAI or Anthropic above instead. Check your machine
Try it now

Requires an API key and an AgentOp account.

12 downloads
0 forks
0.0 rating

Description

Based on the Physics Simulator Code Studio template.

What this agent can do

My Physics Simulator Code Studio is built from the Physics Simulator Code Studio template. Runs fully on your own device: llama.cpp compiled to WebAssembly, GPU-accelerated through WebGPU, with no API key and no server. After the one-time model download it works offline. Can run on OpenAI models with your own API key, encrypted in your browser. Can run on Anthropic Claude models with your own API key, encrypted in your browser.

Source Code

agent.py
import re as _re

async def process_user_query(query: str) -> str:
    """Generate a standalone browser physics simulator from an experiment brief.

    Args:
        query: Physics scene and the user's experiment requirements.
    """
    brief = query.strip()[:1500]
    if not brief:
        return 'ERROR: Describe a physics experiment first.'
    prompt = (
        'Write ONE complete, standalone HTML document for this physics experiment. '
        'Output ONLY HTML code, starting with <!DOCTYPE html> and ending with </html>. '
        'Use inline CSS and vanilla JavaScript only; no packages, imports, CDNs, images, or network requests. '
        'Include a canvas, requestAnimationFrame animation, a clear physics update using delta time, '
        'and labeled working controls for relevant parameters plus pause and reset. '
        'Keep the simulation responsive and bound time steps for stability. '
        'Keep code compact. Implement the requested physics rather than describing it.\n\n'
        + brief
    )
    answer = str(await agentop_llm.generate(prompt, globals().get('TEMPLATE_SYSTEM_PROMPT', ''))).strip()
    fenced = _re.fullmatch(r'```(?:html)?\s*([\s\S]*?)\s*```', answer, _re.I)
    if fenced:
        answer = fenced.group(1).strip()
    start = _re.search(r'<!doctype\s+html\s*>|<html\b', answer, _re.I)
    end = _re.search(r'</html\s*>', answer, _re.I)
    if start and end and end.end() > start.start():
        answer = answer[start.start():end.end()]
    if not _re.search(r'<html\b', answer, _re.I) or not _re.search(r'<canvas\b', answer, _re.I) or not _re.search(r'<script\b', answer, _re.I) or not _re.search(r'</html\s*>', answer, _re.I):
        return 'ERROR: The model did not return a complete canvas simulator. Try a shorter, more specific experiment brief.'
    return answer