Choose how to run this agent
Download Agent
Choose how you want to use this agent:
Use Security Settings Key (Recommended)
Use the API key you've already saved in Security Settings. Quick and convenient!
- No need to re-enter API key
- Works offline after download
- Centralized key management
No API key found in Security Settings. Add one now
Enter API Key Manually
Enter your API key now for this specific agent download.
- Use different key for this agent
- One-time use (not saved)
- Works offline after download
Configure Agent Encryption
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
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