Skip to content

Latest commit

 

History

History
270 lines (189 loc) · 9.01 KB

File metadata and controls

270 lines (189 loc) · 9.01 KB

Anarchy Agent - Implementation Documentation

Overview

This document provides detailed information about the implementation of the Anarchy Agent project components. All components have been implemented using the Anarchy-Inference language, following its symbolic syntax and design principles.

Implemented Components

1. String Dictionary

File: string_dictionary.json

The string dictionary centralizes all strings used throughout the application, following Anarchy-Inference's minimalist design philosophy. This approach:

  • Reduces token usage for LLMs
  • Makes the codebase more maintainable
  • Allows for easier localization
  • Provides consistent messaging across the application

The dictionary includes strings for:

  • Initialization and status messages
  • Error messages
  • User interface text
  • Operation descriptions
  • Common responses

2. Sandbox Module

File: sandbox.a.i

The Sandbox module provides a secure execution environment for Anarchy-Inference code. Key features:

  • Permission System: Controls access to sensitive operations
  • Resource Limits: Prevents excessive resource usage
  • Symbol Registration: Manages available operations
  • Secure Execution: Safely runs parsed Anarchy-Inference code
  • Error Handling: Captures and reports execution errors

The sandbox is the core security component, ensuring that Anarchy-Inference code cannot perform unauthorized operations.

3. Parser Module

File: parser.a.i

The Parser module transforms Anarchy-Inference code into an Abstract Syntax Tree (AST) for execution. Key features:

  • Tokenization: Breaks code into tokens
  • AST Generation: Builds a structured representation of the code
  • Syntax Validation: Ensures code follows Anarchy-Inference syntax
  • Error Detection: Identifies and reports syntax errors
  • Unicode Support: Handles Anarchy-Inference's symbolic syntax

The parser supports all Anarchy-Inference language features, including its unique symbolic operators.

4. File System Module

File: file.a.i

The File System module provides secure file operations. Key features:

  • Directory Listing: Lists contents of directories
  • File Reading/Writing: Reads from and writes to files
  • File/Directory Removal: Safely removes files and directories
  • File Copying/Moving: Copies and moves files
  • Path Validation: Prevents access to sensitive directories
  • Error Handling: Reports file operation errors

All operations include security checks to prevent unauthorized access to sensitive files.

5. Shell Module

File: shell.a.i

The Shell module enables secure command execution. Key features:

  • Command Execution: Runs shell commands
  • Output Capturing: Captures command output
  • OS Information: Retrieves system information
  • Environment Variables: Accesses environment variables
  • Security Validation: Prevents dangerous commands
  • Error Handling: Reports command execution errors

The module includes extensive security checks to prevent execution of dangerous commands.

6. Network Module

File: network.a.i

The Network module provides HTTP request functionality. Key features:

  • HTTP GET: Performs GET requests
  • HTTP POST: Performs POST requests with data
  • URL Validation: Prevents access to internal networks
  • Response Handling: Processes HTTP responses
  • JSON Parsing: Parses JSON responses
  • Error Handling: Reports network operation errors

All network operations include security validation to prevent access to internal networks.

7. Database Module

File: db.a.i

The Database module provides persistent storage. Key features:

  • Key-Value Storage: Stores and retrieves values by key
  • Execution History: Records task execution history
  • Relevance Queries: Finds relevant past executions
  • Persistence: Saves data to disk
  • Error Handling: Reports database operation errors

The database provides both simple key-value storage and more complex query capabilities.

8. LLM Engine

File: llm.a.i

The LLM Engine enables interaction with language models. Key features:

  • Model Loading: Loads language models from files
  • Prompt Generation: Creates effective prompts
  • Response Generation: Generates responses from prompts
  • Context Management: Maintains conversation context
  • Fallback Generation: Provides basic functionality when no model is loaded
  • Error Handling: Reports LLM operation errors

The LLM Engine is designed to work with local quantized models for offline operation.

9. Browser Module

File: browser.a.i

The Browser module enables web automation. Key features:

  • Page Navigation: Opens web pages
  • Element Interaction: Clicks on elements and inputs text
  • Content Extraction: Gets text from elements
  • JavaScript Execution: Runs JavaScript in the browser
  • Screenshot Capture: Takes screenshots of pages
  • URL Validation: Prevents access to internal networks
  • Error Handling: Reports browser operation errors

The browser implementation replaces the previous placeholder code with functional automation.

10. Integration Module

File: integration.a.i

The Integration module connects all components. Key features:

  • Component Initialization: Initializes all components
  • Symbol Registration: Registers all symbols with the sandbox
  • Code Execution: Executes Anarchy-Inference code
  • Task Execution: Generates and executes code for tasks
  • Component Access: Provides access to individual components
  • Shutdown: Properly shuts down all components

The integration module serves as the main entry point for the Anarchy Agent.

Symbol Mapping

The following symbols are registered for use in Anarchy-Inference code:

Symbol Operation Component
📂 List directory File System
📖 Read file File System
Write file File System
Remove file/directory File System
Copy file File System
Move file File System
? Check if file exists File System
! Execute shell command Shell
🖥 Get OS information Shell
HTTP GET request Network
HTTP POST request Network
🌐 Open web page Browser
🖱 Click element Browser
Input text Browser
👁 Get text Browser
🧠 Execute JavaScript Browser
Close browser Browser
📸 Take screenshot Browser
📝 Set memory value Database
📚 Get memory value Database
🗑 Delete memory value Database

Testing

A comprehensive test suite has been implemented in test.a.i to verify the functionality of all components. The tests include:

  • Individual component tests
  • Integration tests
  • Security validation tests
  • Error handling tests

The test suite provides detailed reporting of test results and can be used to verify the correct operation of the Anarchy Agent.

Usage Examples

Basic Task Execution

// Initialize the agent
ι agent = Integration();
agent.initialize({});

// Run a task
ι result = agent.run_task("List files in the current directory");

// Print the result
⌽(result.result);

Direct Code Execution

// Initialize the agent
ι agent = Integration();
agent.initialize({});

// Execute Anarchy-Inference code
ι code = `
ƒmain() {
    // List files in the current directory
    ι files = 📂(".");
    
    // Print each file
    ∀(files.files, λfile {
        ⌽(file);
    });
    
    ↩ files;
}

main();
`;

ι result = agent.execute(code);

// Print the result
⌽(result.result);

Security Considerations

The implementation includes several security measures:

  1. Sandbox Isolation: All code execution occurs within a sandbox
  2. Permission Controls: Operations can be restricted based on permissions
  3. Resource Limits: Execution time and memory usage are limited
  4. Path Validation: File operations are restricted to safe directories
  5. Command Validation: Shell commands are checked for dangerous operations
  6. URL Validation: Network and browser operations are restricted to external networks

These measures ensure that the Anarchy Agent operates safely and securely.

Future Improvements

Potential areas for future improvement include:

  1. Enhanced LLM Integration: Support for more sophisticated models and prompting
  2. Expanded Browser Automation: More advanced web interaction capabilities
  3. Improved Memory Management: Vector storage for more effective context retrieval
  4. Additional System Operations: More comprehensive system interaction
  5. User Interface Improvements: Better visualization of agent operations
  6. Performance Optimization: Faster code execution and response generation

Conclusion

The Anarchy Agent implementation provides a fully functional, cross-platform AI assistant that operates entirely offline using the Anarchy-Inference language. The modular architecture allows for easy extension and customization, while the minimalist design ensures efficiency and simplicity.