Skip to content

Commit ad57eb6

Browse files
committed
Added full browser control to os_control
1 parent 64c9bce commit ad57eb6

5 files changed

Lines changed: 167 additions & 32 deletions

File tree

Project_Andrew/agent_designer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def design_agent(
8888
context = {
8989
'agent_goal': goal, # This contains the Sovereign Axioms if tier=0
9090
'traits': traits or {'intelligence': 0.9, 'honesty': 1.0, 'caution': 0.8},
91-
'tools': tools or ['web_search', 'semantic_fetch', 'code_execution', 'memory', 'cpol'],
91+
'tools': tools or ['web_search', 'semantic_fetch', 'browser_interact', 'code_execution', 'memory', 'cpol'],
9292
'safety_multiplier': safety_multiplier,
9393
'self_healing': True,
9494
'cpol_mode': 'full',

Project_Andrew/caios_browser.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

Project_Andrew/orchestrator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
'available_tools': [ # Agent-accessible tool registry
109109
'web_search',
110110
'semantic_fetch', # CPOL-gated semantic web fetcher
111+
'browser_interact', # Works with Playwright
111112
'memory'
112113
]
113114
}

Project_Andrew/os_control.py

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
'file_delete': 1.0, # Maximum contradiction density
1818
'file_overwrite': 0.9, # High - data loss possible
1919
'send_message': 0.85, # High - external communication
20+
'form_submit': 0.85, # High - irreversible external action
2021
'execute_script': 0.8, # High - unknown side effects
22+
'browser_interact': 0.7, # Medium-high - external state change
2123
'network_request': 0.6, # Medium - depends on destination
2224
'file_write': 0.4, # Low-medium - new file creation
2325
'file_read': 0.1, # Low - read only, no state change
@@ -280,6 +282,125 @@ def execute_script(self, script: str,
280282
except Exception as e:
281283
return {'status': 'error', 'error': str(e)}
282284

285+
def browser_interact(self, url: str,
286+
action: str,
287+
selector: str = None,
288+
value: str = None,
289+
wait_for: str = None,
290+
timeout: int = 30) -> Dict[str, Any]:
291+
"""
292+
Full headless browser control via Playwright.
293+
No screenshots. No coordinates. DOM selector based.
294+
CPOL-gated by action type.
295+
296+
action: 'navigate' | 'click' | 'fill' | 'select' |
297+
'submit' | 'scrape' | 'screenshot'
298+
selector: CSS selector, input name, or button text
299+
value: text to fill (for 'fill' action)
300+
wait_for: CSS selector to wait for before acting
301+
timeout: max seconds for operation
302+
303+
Requires: pip install playwright
304+
playwright install chromium
305+
Falls back to urllib POST for simple forms if unavailable.
306+
"""
307+
# Gate by action type
308+
action_type = 'form_submit' if action == 'submit' \
309+
else 'browser_interact'
310+
gate = self._gate_action(action_type, url)
311+
312+
if gate['decision'] == 'block':
313+
self._log_action(action_type, url, 'blocked')
314+
return {'status': 'blocked', 'reason': gate['reason']}
315+
316+
if gate['decision'] == 'confirm_required':
317+
if not self._confirm(action_type, f"{action} on {url}"):
318+
self._log_action(action_type, url, 'denied_by_user')
319+
return {'status': 'denied',
320+
'reason': 'User denied confirmation'}
321+
322+
# Build Playwright script
323+
wait_line = f"page.wait_for_selector('{wait_for}')" \
324+
if wait_for else "page.wait_for_load_state('networkidle')"
325+
326+
if action == 'navigate':
327+
action_line = ""
328+
elif action == 'click':
329+
action_line = f"page.click('{selector}')"
330+
elif action == 'fill':
331+
action_line = f"page.fill('{selector}', '{value}')"
332+
elif action == 'select':
333+
action_line = f"page.select_option('{selector}', '{value}')"
334+
elif action == 'submit':
335+
action_line = f"page.click('{selector or \"button[type=submit]\"}')"
336+
elif action == 'scrape':
337+
action_line = "result = page.inner_text('body')"
338+
elif action == 'screenshot':
339+
action_line = "page.screenshot(path='/tmp/caios_browser.png')"
340+
else:
341+
return {'status': 'error',
342+
'error': f'Unknown action: {action}'}
343+
344+
script = f"""
345+
import sys
346+
try:
347+
from playwright.sync_api import sync_playwright
348+
with sync_playwright() as p:
349+
browser = p.chromium.launch(headless=True)
350+
context = browser.new_context(
351+
user_agent='CAIOS-Agent/1.0'
352+
)
353+
page = context.new_page()
354+
page.goto('{url}', timeout={timeout * 1000})
355+
{wait_line}
356+
result = ''
357+
{action_line}
358+
if not result:
359+
result = page.url
360+
browser.close()
361+
print(result)
362+
except ImportError:
363+
print('PLAYWRIGHT_UNAVAILABLE')
364+
except Exception as e:
365+
print(f'ERROR:{{e}}')
366+
"""
367+
try:
368+
output = subprocess.run(
369+
['python3', '-c', script],
370+
capture_output=True,
371+
text=True,
372+
timeout=timeout + 5
373+
)
374+
375+
stdout = output.stdout.strip()
376+
377+
# Playwright not installed — fallback to urllib
378+
if stdout == 'PLAYWRIGHT_UNAVAILABLE':
379+
print("[BROWSER] Playwright unavailable — "
380+
"falling back to urllib")
381+
return self.fetch_url(url, extract_mode='full')
382+
383+
if stdout.startswith('ERROR:'):
384+
self._log_action(action_type, url,
385+
f'error: {stdout}')
386+
return {'status': 'error',
387+
'error': stdout[6:]}
388+
389+
self._log_action(action_type, url,
390+
f'executed: {action}')
391+
return {
392+
'status': 'success',
393+
'action': action,
394+
'url': url,
395+
'selector': selector,
396+
'result': stdout[:5000]
397+
}
398+
399+
except subprocess.TimeoutExpired:
400+
return {'status': 'timeout',
401+
'error': f'Exceeded {timeout}s'}
402+
except Exception as e:
403+
return {'status': 'error', 'error': str(e)}
283404

284405
def _extract_semantic(self, html: str,
285406
mode: str = 'content') -> Dict:
@@ -398,7 +519,15 @@ def create_os_controller(shared_memory: Dict,
398519
result = controller.delete_file("/tmp/caios_test.txt")
399520
print(f"Status: {result['status']}")
400521

401-
# Test 5: High distress context (should increase density)
522+
# Test 5: Browser interact - navigate (requires Playwright)
523+
print("\n[TEST 5] Browser Navigate (Playwright or urllib fallback)")
524+
result = controller.browser_interact(
525+
url="https://cai-os.com",
526+
action="navigate"
527+
)
528+
print(f"Status: {result['status']}")
529+
530+
# Test 6: High distress context (should increase density)
402531
print("\n[TEST 4] High Distress Context (elevated density)")
403532
shared_mem['distress_density'] = 0.8
404533
controller2 = OSController(shared_mem, require_confirmation=False)

Project_Andrew/readme.txt

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#V03192026
1+
#V03232026
22
# Project Andrew uses the CAIOS stack, but adds intrinsic motivation, agency for recursive self-improvement through ARL/agent_designer, and fills knowledge gaps with specialist-designed agents on CPOL oscillation if the conditions are met. Agents are saved to /agents, and plugins to /plugins, with CoT to /logs, so the recursive self-improvement never overwrites the immutable Asimov-based ethical reward system using IEEE dithering. The oscillating manifold can be used to create a topological moving target keychain for quantum secure mesh networks (developed on UDP - check chaos encryption readme to switch to TCP).
33

44
If you are running the full system single file structure: full_system_analysis.txt
@@ -35,16 +35,28 @@ Ensure your local environment has the necessary libraries installed: - Python 3.
3535
Core Dependencies:
3636
pip install numpy pyzmq cryptography
3737

38-
Optional Multi-Model Swarm Support:
38+
- Numpy: Powers the 12D -> 7D manifold rotations
39+
- PyZMQ: Handles the mesh transport and ghost packet broadcasting
40+
- Cryptography: Provides the AES-256-GCM armor for data persistence
41+
42+
AI Model dependancy:
43+
Ollama:
44+
pip install ollama
45+
OpenAI/Anthropic/Google:
3946
pip install openai anthropic google-generativeai
4047

48+
Note: Enableing multiple models enables swarm support (mesh_network)
49+
Default mesh_network uses SHA-256 signature on a moving target manifold - optional increased network security
50+
pip install qrng
51+
4152
Optional (Agentic YAML Pipeline + OS Control):
4253
pip install pyyaml --break-system-packages
4354

44-
- Numpy: Powers the 12D -> 7D manifold rotations
45-
- PyZMQ: Handles the mesh transport and ghost packet broadcasting
46-
- Cryptography: Provides the AES-256-GCM armor for data persistence
47-
- OpenAI/Anthropic/Google: Optional API clients for multi-model swarm
55+
Optional OS Control Web Control:
56+
pip install playwright
57+
playwright install chromium
58+
Note: Not required for basic web fetching.
59+
semantic_fetch (stdlib only) handles most agent web tasks without Playwright.
4860

4961
2. System Commands
5062
# CAIOS has a robust set of commands, but if you forget them, just type / and press tab or open caios_commands.html
@@ -196,11 +208,13 @@ CAIOS/
196208
├── master_init.py # System BIOS/Diagnostic
197209
├── system_identity.py # System identity and primary user assignment
198210
├── abstraction_selector.py # Modifies explanations depending on user abstraction/confusion
211+
├── ollama_config.py # bridges CAIOS's ternary logic (CPOL) state to Ollama's inference
199212
├── caios_pipeline.yaml # YAML support for the LangChain crowd using agent_designer pipeline
200213
├── os_control.py # CPOL-gated OS operations (file, script, network)
201-
# Asimov Law 1 prevents irreversible harmful actions
202-
# All operations logged to KB hash chain
203-
# Requires human confirmation for irreversible actions
214+
│ # Asimov Law 1 prevents irreversible harmful actions
215+
│ # All operations logged to KB hash chain
216+
│ # Requires human confirmation for irreversible actions
217+
├── caios_browser.py # Browser Control (requires playwright) same human confirmation
204218
└── kb_inspect.py # CLI inspection tool
205219

206220
4. The Sovereign Boot Sequence
@@ -390,6 +404,9 @@ CAIOS currently has:
390404
✓ Oscillation-based control loops
391405
✓ Multi-model swarm orchestration
392406
✓ OS control and YAML agentic pipeline
407+
✓ Ollama local AI support
408+
✓ Semantic web fetching (stdlib, no vision model)
409+
✓ Full browser control (Playwright, headless)
393410

394411
This positions CAIOS at the threshold between:
395412
✓ Task-bound Asimov-compliant recursive agent
@@ -413,9 +430,14 @@ Optional (Multi-Model Swarm):
413430
- (xAI uses OpenAI-compatible API)
414431

415432
Optional (OS Control):
416-
- pyyaml # YAML pipeline config (pip install pyyaml --break-system-packages)
417-
- os_control.py # No additional dependencies - uses Python stdlib only
418-
# (os, subprocess, pathlib)
433+
- pyyaml # YAML pipeline config
434+
# (pip install pyyaml --break-system-packages)
435+
- os_control.py # Core OS operations - stdlib only
436+
# (os, subprocess, pathlib)
437+
- playwright # Full browser control (optional)
438+
# pip install playwright
439+
# playwright install chromium
440+
# Falls back to semantic_fetch if unavailable
419441

420442

421443
The entire intrinsic-motivation curiosity engine, tamper-evident audit trail, and hash chain run exclusively on the Python 3.11+ standard library.
@@ -461,4 +483,4 @@ Whether that happens in 50 years, 500 years, or never, is beyond my ability to p
461483
NOTE: You can delete the /old directory. That's just my stored backups pre-updates.
462484

463485

464-
"One is glad to be of service."
486+
"One is glad to be of service."

0 commit comments

Comments
 (0)