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 ULTRON — Personal AI Command Center template.
What this agent can do
My ULTRON — Personal AI Command Center is built from the ULTRON — Personal AI Command Center 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 json
from urllib.parse import urlsplit
from pyodide.http import pyfetch
def _config():
return json.loads(globals().get('ultron_settings_json', '{}'))
def _base_ollama(cfg):
address = str(cfg.get('ollama') or 'http://127.0.0.1:11434').strip().rstrip('/')
parsed = urlsplit(address)
if parsed.scheme not in ('http', 'https') or parsed.hostname not in ('localhost', '127.0.0.1', '::1') or parsed.username or parsed.password or parsed.path not in ('', '/') or parsed.query or parsed.fragment:
raise ValueError('Ollama address must be a local http(s) address, such as http://127.0.0.1:11434.')
return address
async def _request_json(url, payload=None, key=''):
headers = {'Accept': 'application/json'}
if payload is not None:
headers['Content-Type'] = 'application/json'
if key:
headers['Authorization'] = 'Bearer ' + key
try:
kwargs = {'method': 'POST' if payload is not None else 'GET', 'headers': headers}
if payload is not None:
kwargs['body'] = json.dumps(payload)
response = await pyfetch(url, **kwargs)
if not response.ok:
raise ValueError('HTTP ' + str(response.status) + '. Check the address, model, credentials, service billing, and browser CORS permissions.')
return json.loads(await response.string())
except ValueError:
raise
except Exception as exc:
raise RuntimeError('Network request failed. Check that the server is running and allows requests from this page (CORS). Details: ' + str(exc)[:180]) from exc
async def _list_ollama_models():
data = await _request_json(_base_ollama(_config()) + '/api/tags')
return json.dumps([item['name'] for item in data.get('models', []) if isinstance(item, dict) and isinstance(item.get('name'), str)])
async def process_user_query(query: str) -> str:
"""Answer through the selected real AI model.
Args:
query: The user's latest chat message.
"""
cfg = _config()
mode = cfg.get('mode', 'platform')
question = query.strip()[:6000]
if not question:
raise ValueError('Write a message first.')
try:
history = json.loads(globals().get('ultron_history_json', '[]'))
except (ValueError, TypeError):
history = []
messages = []
for item in history[-8:] if isinstance(history, list) else []:
if isinstance(item, dict) and item.get('role') in ('user', 'assistant') and isinstance(item.get('content'), str):
messages.append({'role': item['role'], 'content': item['content'][:1200]})
messages.append({'role': 'user', 'content': question})
if mode == 'platform':
transcript = '\n'.join(('USER' if m['role'] == 'user' else 'ASSISTANT') + ': ' + m['content'] for m in messages)
prompt = 'Conversation so far:\n' + transcript[-6500:] + '\nASSISTANT:'
return str(await agentop_llm.generate(prompt, globals().get('TEMPLATE_SYSTEM_PROMPT', '')))
model = str(cfg.get('model') or '').strip()
if not model:
raise ValueError('Enter the exact model name in Settings.')
system = 'You are ULTRON, a concise, professional, confident futuristic assistant. Do not claim consciousness or abilities you do not have. Never fabricate system metrics or pretend a failed model call succeeded.'
payload_messages = [{'role': 'system', 'content': system}] + messages
if mode == 'ollama':
result = await _request_json(_base_ollama(cfg) + '/api/chat', {'model': model, 'messages': payload_messages, 'stream': False})
answer = (result.get('message') or {}).get('content', '')
elif mode == 'online':
endpoint = str(cfg.get('endpoint') or '').strip().rstrip('/')
parsed = urlsplit(endpoint)
if parsed.scheme != 'https' and not (parsed.scheme == 'http' and parsed.hostname in ('localhost', '127.0.0.1', '::1')):
raise ValueError('Online API endpoint must use HTTPS, except for localhost.')
if not parsed.netloc or parsed.username or parsed.password or parsed.query or parsed.fragment:
raise ValueError('Enter a valid online API endpoint without embedded credentials or query parameters.')
url = endpoint if endpoint.endswith('/chat/completions') else endpoint + ('/chat/completions' if endpoint.endswith('/v1') else '/v1/chat/completions')
result = await _request_json(url, {'model': model, 'messages': payload_messages, 'stream': False}, str(cfg.get('key') or ''))
choices = result.get('choices') or []
answer = ((choices[0].get('message') or {}).get('content') or '') if choices else ''
else:
raise ValueError('Select a supported AI mode in Settings.')
if not isinstance(answer, str) or not answer.strip():
raise ValueError('The selected model returned no text. Check its model name and service status.')
return answer.strip()